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
//! Equity Research workflow definitions.
//!
//! Nine static workflow templates covering the full equity research lifecycle:
//! initiating coverage, earnings analysis/preview, model updates, morning notes,
//! thesis tracking, catalyst calendars, idea generation, and sector overviews.

use super::types::*;

// ---------------------------------------------------------------------------
// Public registry
// ---------------------------------------------------------------------------

pub static WORKFLOWS: &[&WorkflowDefinition] = &[
    &INITIATING_COVERAGE,
    &EARNINGS_ANALYSIS,
    &EARNINGS_PREVIEW,
    &MODEL_UPDATE,
    &MORNING_NOTE,
    &THESIS_TRACKER,
    &CATALYST_CALENDAR,
    &IDEA_GENERATION,
    &SECTOR_OVERVIEW,
];

// ---------------------------------------------------------------------------
// 1. Initiating Coverage
// ---------------------------------------------------------------------------

static INITIATING_COVERAGE: WorkflowDefinition = WorkflowDefinition {
    id: "er-initiating-coverage",
    name: "Initiating Coverage Report",
    domain: WorkflowDomain::EquityResearch,
    description: "Full initiating coverage report with business overview, \
                  financial analysis, valuation, and investment thesis",
    required_inputs: &[
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: true,
            description: "Target company ticker symbol",
        },
        WorkflowInput {
            name: "peer_group",
            input_type: InputType::PeerGroup,
            required: false,
            description: "Peer group for comparable analysis",
        },
        WorkflowInput {
            name: "target_return",
            input_type: InputType::TargetReturn,
            required: false,
            description: "Target return threshold for recommendation",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Data Collection",
            description: "Gather financial statements, quotes, and key metrics",
            required_tools: &[
                "fmp_income_statement",
                "fmp_balance_sheet",
                "fmp_cash_flow",
                "fmp_quote",
                "fmp_key_metrics",
            ],
        },
        WorkflowStep {
            order: 2,
            name: "Earnings Quality",
            description: "Screen for manipulation and fundamental strength",
            required_tools: &[
                "beneish_mscore",
                "piotroski_fscore",
                "earnings_quality_composite",
            ],
        },
        WorkflowStep {
            order: 3,
            name: "Valuation",
            description: "DCF, comps, and target price derivation",
            required_tools: &[
                "wacc_calculator",
                "dcf_model",
                "comps_analysis",
                "target_price",
            ],
        },
        WorkflowStep {
            order: 4,
            name: "Scenario Analysis",
            description: "Base/bull/bear cases with sensitivity",
            required_tools: &["sensitivity_matrix", "monte_carlo_dcf"],
        },
        WorkflowStep {
            order: 5,
            name: "Report Assembly",
            description: "Compile investment thesis with risk assessment",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "CompletenessCheck",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "SourceVerification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
        QualityGate {
            name: "ScenarioCheck",
            check_type: QualityCheckType::ScenarioCheck,
            required: true,
        },
        QualityGate {
            name: "RiskFirstCheck",
            check_type: QualityCheckType::RiskFirstCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Investment Thesis",
        "Business Overview",
        "Industry Analysis",
        "Financial Analysis",
        "Valuation",
        "Scenario Analysis",
        "Risk Factors",
        "Target Price",
    ],
};

// ---------------------------------------------------------------------------
// 2. Earnings Analysis
// ---------------------------------------------------------------------------

static EARNINGS_ANALYSIS: WorkflowDefinition = WorkflowDefinition {
    id: "er-earnings-analysis",
    name: "Earnings Analysis",
    domain: WorkflowDomain::EquityResearch,
    description: "Post-earnings analysis with beat/miss assessment, \
                  guidance review, and estimate revisions",
    required_inputs: &[
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: true,
            description: "Company ticker symbol",
        },
        WorkflowInput {
            name: "quarter",
            input_type: InputType::FreeText,
            required: true,
            description: "Reporting quarter (e.g. Q3 2025)",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Earnings Data",
            description: "Pull reported vs consensus",
            required_tools: &["fmp_earnings", "fmp_analyst_estimates", "fmp_quote"],
        },
        WorkflowStep {
            order: 2,
            name: "Quality Screen",
            description: "Check earnings quality signals",
            required_tools: &["beneish_mscore", "piotroski_fscore"],
        },
        WorkflowStep {
            order: 3,
            name: "Estimate Impact",
            description: "Revise model and target",
            required_tools: &["three_statement_model", "target_price"],
        },
        WorkflowStep {
            order: 4,
            name: "Report",
            description: "Summarise beat/miss and outlook",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "CompletenessCheck",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "SourceVerification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
    ],
    output_sections: &[
        "Summary",
        "Beat/Miss Analysis",
        "Guidance Review",
        "Estimate Revisions",
        "Valuation Impact",
        "Recommendation",
    ],
};

// ---------------------------------------------------------------------------
// 3. Earnings Preview
// ---------------------------------------------------------------------------

static EARNINGS_PREVIEW: WorkflowDefinition = WorkflowDefinition {
    id: "er-earnings-preview",
    name: "Earnings Preview",
    domain: WorkflowDomain::EquityResearch,
    description: "Pre-earnings preview with consensus expectations, \
                  key metrics to watch, and scenario outcomes",
    required_inputs: &[WorkflowInput {
        name: "ticker",
        input_type: InputType::Ticker,
        required: true,
        description: "Company ticker symbol",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Consensus",
            description: "Gather analyst estimates and historical surprises",
            required_tools: &["fmp_analyst_estimates", "fmp_earnings"],
        },
        WorkflowStep {
            order: 2,
            name: "Key Metrics",
            description: "Identify critical KPIs and thresholds",
            required_tools: &["fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 3,
            name: "Scenarios",
            description: "Outline beat/miss/inline scenarios",
            required_tools: &["sensitivity_matrix"],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "CompletenessCheck",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "ScenarioCheck",
            check_type: QualityCheckType::ScenarioCheck,
            required: true,
        },
    ],
    output_sections: &[
        "Consensus Expectations",
        "Key Metrics to Watch",
        "Scenario Outcomes",
        "Trading Strategy",
    ],
};

// ---------------------------------------------------------------------------
// 4. Model Update
// ---------------------------------------------------------------------------

static MODEL_UPDATE: WorkflowDefinition = WorkflowDefinition {
    id: "er-model-update",
    name: "Model Update",
    domain: WorkflowDomain::EquityResearch,
    description: "Refresh three-statement model with latest data \
                  and recalculate fair value",
    required_inputs: &[WorkflowInput {
        name: "ticker",
        input_type: InputType::Ticker,
        required: true,
        description: "Company ticker symbol",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Data Refresh",
            description: "Pull latest financial data",
            required_tools: &["fmp_income_statement", "fmp_balance_sheet", "fmp_cash_flow"],
        },
        WorkflowStep {
            order: 2,
            name: "Model Rebuild",
            description: "Update three-statement model",
            required_tools: &["three_statement_model"],
        },
        WorkflowStep {
            order: 3,
            name: "Revalue",
            description: "Recalculate DCF and target price",
            required_tools: &["wacc_calculator", "dcf_model", "target_price"],
        },
    ],
    quality_gates: &[QualityGate {
        name: "SourceVerification",
        check_type: QualityCheckType::SourceVerification,
        required: true,
    }],
    output_sections: &[
        "Model Changes",
        "Updated Financials",
        "Revised Valuation",
        "Target Price Change",
    ],
};

// ---------------------------------------------------------------------------
// 5. Morning Note
// ---------------------------------------------------------------------------

static MORNING_NOTE: WorkflowDefinition = WorkflowDefinition {
    id: "er-morning-note",
    name: "Morning Note",
    domain: WorkflowDomain::EquityResearch,
    description: "Daily morning briefing with market moves, \
                  earnings calendar, and key events",
    required_inputs: &[WorkflowInput {
        name: "tickers",
        input_type: InputType::FreeText,
        required: true,
        description: "Comma-separated tickers",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Market Data",
            description: "Pull quotes and recent prices",
            required_tools: &["fmp_quote", "fmp_historical_prices"],
        },
        WorkflowStep {
            order: 2,
            name: "Compile",
            description: "Assemble briefing note",
            required_tools: &[],
        },
    ],
    quality_gates: &[QualityGate {
        name: "CompletenessCheck",
        check_type: QualityCheckType::CompletenessCheck,
        required: true,
    }],
    output_sections: &[
        "Market Overview",
        "Coverage Universe Update",
        "Earnings Calendar",
        "Key Events",
    ],
};

// ---------------------------------------------------------------------------
// 6. Thesis Tracker
// ---------------------------------------------------------------------------

static THESIS_TRACKER: WorkflowDefinition = WorkflowDefinition {
    id: "er-thesis-tracker",
    name: "Thesis Tracker",
    domain: WorkflowDomain::EquityResearch,
    description: "Track investment thesis milestones, catalysts, \
                  and conviction level changes",
    required_inputs: &[
        WorkflowInput {
            name: "ticker",
            input_type: InputType::Ticker,
            required: true,
            description: "Company ticker symbol",
        },
        WorkflowInput {
            name: "thesis",
            input_type: InputType::FreeText,
            required: true,
            description: "Original investment thesis statement",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Current State",
            description: "Pull current data and compare to thesis",
            required_tools: &["fmp_quote", "fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Milestone Check",
            description: "Assess progress against thesis milestones",
            required_tools: &["fmp_earnings"],
        },
        WorkflowStep {
            order: 3,
            name: "Conviction Update",
            description: "Revise conviction and catalysts",
            required_tools: &[],
        },
    ],
    quality_gates: &[QualityGate {
        name: "SourceVerification",
        check_type: QualityCheckType::SourceVerification,
        required: true,
    }],
    output_sections: &[
        "Thesis Recap",
        "Milestone Progress",
        "Catalyst Update",
        "Conviction Assessment",
        "Action Items",
    ],
};

// ---------------------------------------------------------------------------
// 7. Catalyst Calendar
// ---------------------------------------------------------------------------

static CATALYST_CALENDAR: WorkflowDefinition = WorkflowDefinition {
    id: "er-catalyst-calendar",
    name: "Catalyst Calendar",
    domain: WorkflowDomain::EquityResearch,
    description: "Calendar of upcoming catalysts with expected impact \
                  and probability",
    required_inputs: &[WorkflowInput {
        name: "tickers",
        input_type: InputType::FreeText,
        required: true,
        description: "Comma-separated tickers",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Data Gather",
            description: "Pull earnings dates and estimates",
            required_tools: &["fmp_earnings", "fmp_analyst_estimates"],
        },
        WorkflowStep {
            order: 2,
            name: "Calendar Build",
            description: "Compile catalyst timeline",
            required_tools: &[],
        },
    ],
    quality_gates: &[QualityGate {
        name: "CompletenessCheck",
        check_type: QualityCheckType::CompletenessCheck,
        required: true,
    }],
    output_sections: &[
        "Catalyst Calendar",
        "Impact Assessment",
        "Probability Weighting",
    ],
};

// ---------------------------------------------------------------------------
// 8. Idea Generation
// ---------------------------------------------------------------------------

static IDEA_GENERATION: WorkflowDefinition = WorkflowDefinition {
    id: "er-idea-generation",
    name: "Idea Generation",
    domain: WorkflowDomain::EquityResearch,
    description: "Systematic screen for investment ideas using \
                  fundamental and quality filters",
    required_inputs: &[WorkflowInput {
        name: "criteria",
        input_type: InputType::FreeText,
        required: true,
        description: "Screening criteria description",
    }],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Screen",
            description: "Apply fundamental screens",
            required_tools: &["fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Quality Filter",
            description: "Apply earnings quality and forensic filters",
            required_tools: &["piotroski_fscore", "beneish_mscore"],
        },
        WorkflowStep {
            order: 3,
            name: "Rank",
            description: "Rank and prioritise candidates",
            required_tools: &["comps_analysis"],
        },
    ],
    quality_gates: &[QualityGate {
        name: "SourceVerification",
        check_type: QualityCheckType::SourceVerification,
        required: true,
    }],
    output_sections: &[
        "Screening Criteria",
        "Candidates",
        "Quality Assessment",
        "Top Ideas",
        "Next Steps",
    ],
};

// ---------------------------------------------------------------------------
// 9. Sector Overview
// ---------------------------------------------------------------------------

static SECTOR_OVERVIEW: WorkflowDefinition = WorkflowDefinition {
    id: "er-sector-overview",
    name: "Sector Overview",
    domain: WorkflowDomain::EquityResearch,
    description: "Sector-level analysis with competitive landscape, \
                  valuation comparison, and sector thesis",
    required_inputs: &[
        WorkflowInput {
            name: "sector",
            input_type: InputType::FreeText,
            required: true,
            description: "Sector name or classification",
        },
        WorkflowInput {
            name: "tickers",
            input_type: InputType::FreeText,
            required: true,
            description: "Comma-separated tickers in sector",
        },
    ],
    steps: &[
        WorkflowStep {
            order: 1,
            name: "Sector Data",
            description: "Pull comparable data across sector",
            required_tools: &["fmp_quote", "fmp_key_metrics", "fmp_ratios"],
        },
        WorkflowStep {
            order: 2,
            name: "Comps Table",
            description: "Build sector valuation comparison",
            required_tools: &["comps_analysis"],
        },
        WorkflowStep {
            order: 3,
            name: "Sector View",
            description: "Formulate sector thesis",
            required_tools: &[],
        },
    ],
    quality_gates: &[
        QualityGate {
            name: "CompletenessCheck",
            check_type: QualityCheckType::CompletenessCheck,
            required: true,
        },
        QualityGate {
            name: "SourceVerification",
            check_type: QualityCheckType::SourceVerification,
            required: true,
        },
    ],
    output_sections: &[
        "Sector Overview",
        "Competitive Landscape",
        "Valuation Comparison",
        "Sector Thesis",
        "Top Picks",
    ],
};

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

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

    #[test]
    fn test_workflow_count() {
        assert_eq!(WORKFLOWS.len(), 9);
    }

    #[test]
    fn test_all_have_steps() {
        for w in WORKFLOWS {
            assert!(!w.steps.is_empty(), "{} has no steps", w.id);
        }
    }

    #[test]
    fn test_all_have_quality_gates() {
        for w in WORKFLOWS {
            assert!(!w.quality_gates.is_empty(), "{} has no quality gates", w.id);
        }
    }

    #[test]
    fn test_ids_unique() {
        let ids: Vec<&str> = WORKFLOWS.iter().map(|w| w.id).collect();
        let unique: std::collections::HashSet<&str> = ids.iter().cloned().collect();
        assert_eq!(ids.len(), unique.len(), "Duplicate workflow IDs found");
    }

    #[test]
    fn test_domain_consistent() {
        for w in WORKFLOWS {
            assert_eq!(
                w.domain,
                WorkflowDomain::EquityResearch,
                "{} has wrong domain",
                w.id
            );
        }
    }

    #[test]
    fn test_step_ordering() {
        for w in WORKFLOWS {
            for (i, step) in w.steps.iter().enumerate() {
                assert_eq!(
                    step.order,
                    (i + 1) as u32,
                    "{} step {} has wrong order",
                    w.id,
                    step.name
                );
            }
        }
    }
}