corp-finance-core 1.1.0

Institutional-grade corporate finance calculations with 128-bit decimal precision — DCF, WACC, comps, LBO, credit metrics, derivatives, fixed income, options, and 60+ specialty modules. No f64 in financials. WASM-compatible.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
//! Private equity workflow definitions.
//! Static compile-time definitions for PE deal and portfolio pipelines.

use super::types::*;

// ---------------------------------------------------------------------------
// Deal Screening
// ---------------------------------------------------------------------------

static DEAL_SCREENING: WorkflowDefinition = WorkflowDefinition {
    id: "pe-deal-screening",
    name: "Deal Screening",
    domain: WorkflowDomain::PrivateEquity,
    description:
        "Initial deal screening with investment criteria checklist and go/no-go recommendation",
    required_inputs: &[
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: false,
            description: "Ticker symbol if publicly traded",
        },
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "deal_size",
            input_type: InputType::Numeric,
            required: false,
            description: "Indicative deal size",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Financial Screen",
            description: "Pull financial data for initial screening",
            required_tools: &[
                "fmp_income_statement",
                "fmp_balance_sheet",
                "fmp_key_metrics",
                "fmp_ratios",
            ],
        },
        WorkflowStep {
            order: 2,
            name: "Credit Check",
            description: "Run credit assessment and Altman Z-Score",
            required_tools: &["altman_zscore", "credit_metrics"],
        },
        WorkflowStep {
            order: 3,
            name: "Screening Verdict",
            description: "Compile go/no-go recommendation",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Company Overview",
        "Investment Criteria Check",
        "Financial Summary",
        "Credit Assessment",
        "Go/No-Go Recommendation",
    ],
};

// ---------------------------------------------------------------------------
// Investment Committee Memo
// ---------------------------------------------------------------------------

static IC_MEMO: WorkflowDefinition = WorkflowDefinition {
    id: "pe-ic-memo",
    name: "Investment Committee Memo",
    domain: WorkflowDomain::PrivateEquity,
    description: "Full IC memo with deal rationale, returns analysis, risks, and recommendation",
    required_inputs: &[
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: false,
            description: "Ticker symbol if publicly traded",
        },
        WorkflowInput {
            name: "entry_ev",
            input_type: InputType::Numeric,
            required: true,
            description: "Entry enterprise value",
        },
        WorkflowInput {
            name: "entry_ebitda",
            input_type: InputType::Numeric,
            required: true,
            description: "Entry EBITDA",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Financials",
            description: "Pull comprehensive financial statements",
            required_tools: &["fmp_income_statement", "fmp_balance_sheet", "fmp_cash_flow"],
        },
        WorkflowStep {
            order: 2,
            name: "Returns",
            description: "Run LBO model and returns analysis",
            required_tools: &["lbo_model", "returns_calculator"],
        },
        WorkflowStep {
            order: 3,
            name: "Credit",
            description: "Assess credit metrics and distress risk",
            required_tools: &["credit_metrics", "altman_zscore"],
        },
        WorkflowStep {
            order: 4,
            name: "Valuation",
            description: "Run comparable company and DCF analysis",
            required_tools: &["comps_analysis", "dcf_model"],
        },
        WorkflowStep {
            order: 5,
            name: "Risk Assessment",
            description: "Identify and assess key risk factors",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "Scenario Check",
            check_type: QualityCheckType::ScenarioCheck,
            required: true,
        },
        QualityGate {
            name: "Risk First",
            check_type: QualityCheckType::RiskFirstCheck,
            required: true,
        },
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Executive Summary",
        "Investment Thesis",
        "Business Overview",
        "Financial Analysis",
        "Returns Analysis",
        "Risk Factors",
        "Exit Strategy",
        "Recommendation",
    ],
};

// ---------------------------------------------------------------------------
// Due Diligence Checklist
// ---------------------------------------------------------------------------

static DD_CHECKLIST: WorkflowDefinition = WorkflowDefinition {
    id: "pe-dd-checklist",
    name: "Due Diligence Checklist",
    domain: WorkflowDomain::PrivateEquity,
    description:
        "Comprehensive DD checklist across financial, legal, commercial, and operational streams",
    required_inputs: &[
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "deal_type",
            input_type: InputType::FreeText,
            required: true,
            description: "Type of deal (e.g., buyout, growth equity, recap)",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Financial DD Items",
            description: "Pull financials for DD question generation",
            required_tools: &["fmp_income_statement", "fmp_balance_sheet"],
        },
        WorkflowStep {
            order: 2,
            name: "Checklist Build",
            description: "Build comprehensive DD checklist across all streams",
            required_tools: &[],
        },
    ],
    quality_gates: &[QualityGate {
        name: "Completeness",
        check_type: QualityCheckType::CompletenessCheck,
        required: true,
    }],
    output_sections: &[
        "Financial DD",
        "Legal DD",
        "Commercial DD",
        "Operational DD",
        "Tax DD",
        "IT/Cyber DD",
        "ESG DD",
    ],
};

// ---------------------------------------------------------------------------
// DD Meeting Prep
// ---------------------------------------------------------------------------

static DD_MEETING_PREP: WorkflowDefinition = WorkflowDefinition {
    id: "pe-dd-meeting-prep",
    name: "DD Meeting Prep",
    domain: WorkflowDomain::PrivateEquity,
    description: "Preparation pack for management meetings with key questions and data requests",
    required_inputs: &[
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "meeting_focus",
            input_type: InputType::FreeText,
            required: true,
            description: "Focus area for the management meeting",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Background",
            description: "Pull background metrics and ratios",
            required_tools: &["fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Question Prep",
            description: "Prepare key questions and data requests",
            required_tools: &[],
        },
    ],
    quality_gates: &[QualityGate {
        name: "Completeness",
        check_type: QualityCheckType::CompletenessCheck,
        required: true,
    }],
    output_sections: &[
        "Company Background",
        "Key Questions",
        "Data Requests",
        "Red Flags to Probe",
    ],
};

// ---------------------------------------------------------------------------
// Returns Analysis
// ---------------------------------------------------------------------------

static RETURNS_ANALYSIS: WorkflowDefinition = WorkflowDefinition {
    id: "pe-returns-analysis",
    name: "Returns Analysis",
    domain: WorkflowDomain::PrivateEquity,
    description: "LBO returns with IRR/MOIC attribution across EBITDA growth, multiple expansion, and debt paydown",
    required_inputs: &[
        WorkflowInput {
            name: "entry_ev",
            input_type: InputType::Numeric,
            required: true,
            description: "Entry enterprise value",
        },
        WorkflowInput {
            name: "entry_ebitda",
            input_type: InputType::Numeric,
            required: true,
            description: "Entry EBITDA",
        },
        WorkflowInput {
            name: "exit_multiple",
            input_type: InputType::Numeric,
            required: false,
            description: "Exit EV/EBITDA multiple",
        },
        WorkflowInput {
            name: "hold_period",
            input_type: InputType::Numeric,
            required: false,
            description: "Holding period in years",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "LBO Model",
            description: "Build LBO model with debt schedule and sources/uses",
            required_tools: &["lbo_model", "debt_schedule", "sources_uses"],
        },
        WorkflowStep {
            order: 2,
            name: "Returns Calc",
            description: "Calculate IRR, MOIC, and returns attribution",
            required_tools: &["returns_calculator"],
        },
        WorkflowStep {
            order: 3,
            name: "Sensitivity",
            description: "Sensitivity analysis on key return drivers",
            required_tools: &["sensitivity_matrix"],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "Scenario Check",
            check_type: QualityCheckType::ScenarioCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Sources & Uses",
        "Operating Model",
        "Debt Schedule",
        "Returns Summary",
        "Attribution",
        "Sensitivity",
    ],
};

// ---------------------------------------------------------------------------
// Unit Economics
// ---------------------------------------------------------------------------

static UNIT_ECONOMICS: WorkflowDefinition = WorkflowDefinition {
    id: "pe-unit-economics",
    name: "Unit Economics",
    domain: WorkflowDomain::PrivateEquity,
    description: "Unit-level economics analysis with LTV/CAC, cohort analysis, and margin build",
    required_inputs: &[
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: false,
            description: "Ticker symbol if publicly traded",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Financial Data",
            description: "Pull income statement, metrics, and ratios",
            required_tools: &["fmp_income_statement", "fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Analysis",
            description: "Build unit economics and margin analysis",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Unit Economics Summary",
        "Revenue Build",
        "Cost Structure",
        "Margin Analysis",
        "LTV/CAC",
        "Scalability Assessment",
    ],
};

// ---------------------------------------------------------------------------
// Value Creation Plan
// ---------------------------------------------------------------------------

static VALUE_CREATION_PLAN: WorkflowDefinition = WorkflowDefinition {
    id: "pe-value-creation-plan",
    name: "Value Creation Plan",
    domain: WorkflowDomain::PrivateEquity,
    description:
        "100-day and long-term value creation plan with revenue, cost, and capital structure levers",
    required_inputs: &[
        WorkflowInput {
            name: "company_name",
            input_type: InputType::CompanyName,
            required: true,
            description: "Target company name",
        },
        WorkflowInput {
            name: "entry_ebitda",
            input_type: InputType::Numeric,
            required: true,
            description: "Entry EBITDA",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Baseline",
            description: "Pull current financials and ratios for baseline",
            required_tools: &["fmp_income_statement", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Lever Analysis",
            description: "Model revenue, cost, and capital structure levers",
            required_tools: &["three_statement_model"],
        },
        WorkflowStep {
            order: 3,
            name: "Plan Build",
            description: "Build 100-day and long-term value creation plan",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
    ],
    output_sections: &[
        "Current State",
        "Revenue Levers",
        "Cost Levers",
        "Capital Structure",
        "100-Day Plan",
        "Long-Term Roadmap",
        "KPI Targets",
    ],
};

// ---------------------------------------------------------------------------
// Portfolio Monitoring
// ---------------------------------------------------------------------------

static PORTFOLIO_MONITORING: WorkflowDefinition = WorkflowDefinition {
    id: "pe-portfolio-monitoring",
    name: "Portfolio Monitoring",
    domain: WorkflowDomain::PrivateEquity,
    description:
        "Quarterly portfolio company monitoring with financial KPIs and covenant compliance",
    required_inputs: &[WorkflowInput {
        name: "tickers",
        input_type: InputType::FreeText,
        required: true,
        description: "Comma-separated portfolio tickers",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Current Data",
            description: "Pull current market data and key metrics for portfolio",
            required_tools: &["fmp_quote", "fmp_key_metrics"],
        },
        WorkflowStep {
            order: 2,
            name: "Credit Monitor",
            description: "Monitor credit metrics across portfolio",
            required_tools: &["credit_metrics"],
        },
        WorkflowStep {
            order: 3,
            name: "Dashboard",
            description: "Build portfolio monitoring dashboard",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Portfolio Overview",
        "Company Dashboards",
        "Covenant Compliance",
        "Watch List",
        "Action Items",
    ],
};

// ---------------------------------------------------------------------------
// Deal Sourcing
// ---------------------------------------------------------------------------

static DEAL_SOURCING: WorkflowDefinition = WorkflowDefinition {
    id: "pe-deal-sourcing",
    name: "Deal Sourcing",
    domain: WorkflowDomain::PrivateEquity,
    description: "Systematic deal sourcing with sector screening and target identification",
    required_inputs: &[
        WorkflowInput {
            name: "sector",
            input_type: InputType::FreeText,
            required: true,
            description: "Target sector for sourcing",
        },
        WorkflowInput {
            name: "criteria",
            input_type: InputType::FreeText,
            required: true,
            description: "Investment criteria and parameters",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Screen",
            description: "Screen sector for companies matching criteria",
            required_tools: &["fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Target List",
            description: "Build prioritised target list with comparables",
            required_tools: &["comps_analysis"],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "Completeness",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "Source Verification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
    ],
    output_sections: &[
        "Sector Overview",
        "Screening Criteria",
        "Target List",
        "Prioritisation",
        "Outreach Plan",
    ],
};

// ---------------------------------------------------------------------------
// Registry
// ---------------------------------------------------------------------------

pub static WORKFLOWS: &[&WorkflowDefinition] = &[
    &DEAL_SCREENING,
    &IC_MEMO,
    &DD_CHECKLIST,
    &DD_MEETING_PREP,
    &RETURNS_ANALYSIS,
    &UNIT_ECONOMICS,
    &VALUE_CREATION_PLAN,
    &PORTFOLIO_MONITORING,
    &DEAL_SOURCING,
];

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashSet;

    #[test]
    fn workflow_count() {
        assert_eq!(WORKFLOWS.len(), 9, "Expected 9 PE workflows");
    }

    #[test]
    fn all_have_steps() {
        for wf in WORKFLOWS {
            assert!(!wf.steps.is_empty(), "Workflow '{}' has no steps", wf.id);
        }
    }

    #[test]
    fn ids_unique() {
        let mut ids = HashSet::new();
        for wf in WORKFLOWS {
            assert!(ids.insert(wf.id), "Duplicate workflow id: {}", wf.id);
        }
    }

    #[test]
    fn domain_is_private_equity() {
        for wf in WORKFLOWS {
            assert_eq!(
                wf.domain,
                WorkflowDomain::PrivateEquity,
                "Workflow '{}' has wrong domain: {:?}",
                wf.id,
                wf.domain
            );
        }
    }

    #[test]
    fn step_ordering() {
        for wf in WORKFLOWS {
            for (i, step) in wf.steps.iter().enumerate() {
                assert_eq!(
                    step.order,
                    (i as u32) + 1,
                    "Workflow '{}' step '{}' has order {} but expected {}",
                    wf.id,
                    step.name,
                    step.order,
                    i + 1
                );
            }
        }
    }
}