Machine Learning in Reports
How Grade My Investments leverages ML.NET to enhance financial reports with predictive analytics, forecasting, and intelligent insights.
flowchart TB
A[(Historical<br/>Financial Data)]:::data --> B[Data Preparation<br/>Normalize - Validate]:::svc
B --> C[Feature Engineering<br/>Time Series]:::svc
C --> D{Model<br/>Selection}:::app
D --> E[SSA Forecasting<br/>Revenue - Debt - Cash Flow]:::app
D --> F[IID Spike Detection<br/>Anomaly Alerts]:::app
D --> G[Multi-class Classification<br/>Bullish - Neutral - Bearish]:::app
D --> H[Health Score<br/>4-factor 0-100]:::app
E --> I[4-Quarter<br/>Forecast]:::svc
F --> J[Anomaly<br/>Alerts]:::svc
G --> K[Sentiment<br/>Forecast]:::svc
H --> L[Health<br/>Score]:::svc
I --> M[(Excel Report<br/>JSON Output)]:::data
J --> M
K --> M
L --> M
classDef app fill:#1f2630,stroke:#C0894E,color:#F3EFE8;
classDef svc fill:#241c14,stroke:#E2B583,color:#F3EFE8;
classDef data fill:#22201a,stroke:#C0894E,color:#EBD3AE;
classDef ext fill:#1b1f27,stroke:#5A616B,color:#C4C0B8;
classDef sec fill:#1d2733,stroke:#5cc8e0,color:#eafaff;
ML.NET-Powered Report Enhancement
Enhanced Report Features
- Future Revenue Predictions: 4-quarter ahead revenue forecasts with confidence intervals
- Cash Flow Projections: Free cash flow trend analysis and predictions
- Financial Health Scoring: Automated 0-100 health scores based on multiple metrics
- Anomaly Alerts: Automatic detection of unusual trading patterns or financial metrics
ML Integration Workflow
Excel Report ML Features
Enhanced Excel Worksheets
ML.NET predictions are integrated directly into Excel reports, providing users with actionable forecasts alongside traditional financial data:
New Worksheet Sections
- Revenue Forecast Tab: Quarterly predictions with charts
- Health Score Summary: Financial health ratings and explanations
- Sentiment Forecast Tab: Market sentiment predictions and trend analysis
- Anomaly Alerts: Highlighted unusual patterns
- Confidence Intervals: Statistical reliability indicators
Visual Enhancements
- Forecast Charts: Line graphs showing predicted trends
- Confidence Bands: Visual uncertainty ranges
- Health Score Gauges: Dashboard-style score visualizations
- Color-Coded Alerts: Risk level indicators
Sample Excel Output with ML Features
| Quarter | Historical Revenue | ML Forecast | Confidence | Health Score |
|---|---|---|---|---|
| Q3 2025 | $89.5B | - | - | 85/100 |
| Q4 2025 | $92.1B | - | - | 87/100 |
| Q1 2026 | - | $95.2B | 85% | 88/100 |
| Q2 2026 | - | $98.1B | 82% | 89/100 |
| Q3 2026 | - | $101.5B | 78% | 90/100 |
Sample Sentiment Forecasting Tab
| Period | Predicted Sentiment | Intensity Score | Confidence | Risk Level | Key Factors |
|---|---|---|---|---|---|
| Week 1 | Bullish 📈 | 78/100 | 85% | Low | Strong momentum, RSI: 65 |
| Week 2 | Bullish 📈 | 74/100 | 82% | Low | Volume spike, positive MA |
| Week 3 | Neutral ➡️ | 45/100 | 78% | Medium | Mixed signals, volatility |
| Week 4 | Bearish 📉 | 25/100 | 75% | High | Resistance level, overbought |
JSON Output with ML Data
Machine Learning Data Structure
JSON reports include structured ML predictions, making the data easily consumable by other applications:
{
"symbol": "AAPL",
"reportDate": "2026-04-01",
"machineLearning": {
"forecasts": {
"revenue": {
"algorithm": "SSA",
"horizon": 4,
"predictions": [
{
"quarter": "Q1 2026",
"value": 95200000000,
"confidence": 0.85,
"upperBound": 98100000000,
"lowerBound": 92300000000
},
{
"quarter": "Q2 2026",
"value": 98100000000,
"confidence": 0.82,
"upperBound": 102500000000,
"lowerBound": 93700000000
}
]
},
"cashFlow": {
"algorithm": "SSA",
"predictions": [...],
"trend": "increasing"
}
},
"anomalies": [
{
"type": "VolumeSpike",
"date": "2026-03-28",
"severity": "Medium",
"description": "Trading volume 3.2x above 30-day average"
}
],
"healthScore": {
"overall": 87,
"components": {
"revenueGrowth": 22,
"debtToEquity": 21,
"cashFlow": 23,
"profitability": 21
},
"risk": "Low"
}
}
}ML Model Types
Forecasting Models
Anomaly Detection
Detection Categories
- Volume Spikes Critical
- Price Volatility High
- Ratio Outliers Medium
- Seasonal Deviations Low
Health Scoring
Scoring Components
Score Interpretation
Performance Metrics
Technical Implementation
ML.NET Integration
The ML.NET framework is integrated into both the Report Generator Alpha and PyEasy console applications through the MLForecastingService class, which implements the IMLForecastingService interface:
Key Implementation Features
- Real-time Training: Models are trained on-demand for each symbol
- SSA Forecasting: Singular Spectrum Analysis with simple trend fallback
- Minimum Data: 4 quarters of historical data required per symbol
- Memory Efficiency: Models are disposed after prediction to optimize memory
- Parallel Processing: Multiple stocks can be analyzed simultaneously
- Error Handling: Graceful fallback when SSA fails or insufficient data
- Configurable Horizons: Forecast periods can be adjusted per use case (default: 4 quarters)
Data Pipeline
Three Pipelines, One Forecaster
The same ML.NET SSA implementation now drives three separate products, on deliberately different horizons. Sharing the algorithm was the easy part; the interesting engineering was deciding what each pipeline is allowed to claim.
| Pipeline | Subject | Horizon | Entry fee |
|---|---|---|---|
MLForecastingServiceReport Generator Alpha |
Revenue, debt, cash flow, equity — per company | 4 quarters | 4 quarters of history |
MacroForecastServiceReport Generator Beta |
21 of 38 catalogued economic series | 1, 2, 6 months | 120 monthly observations (10 years) |
CommoditiesServiceBeta, via the same forecaster |
Gold, silver, oil, copper, bitcoin | 1, 2, 6 months | 120 monthly observations (10 years) |
Why the macro ladder shrank from 3/6/12 to 1/2/6
The engine had always computed twelve monthly points and published three of them. SSA extrapolates trend and decays with distance, so the twelve-month point was the least defensible number on the page — and, being a year out, the slowest to ever be proven wrong. Trading it for one- and two-month projections cost nothing computationally (those points were already being discarded) and bought something real: horizons that resolve fast enough to be scored against actuals. A forecast you can grade within weeks is worth more than one you can admire for a year.
The honest default: let the confidence band decide
Both macro pipelines refuse to call a direction from the midpoint. A series is only described as trending when its projection band no longer contains today's value; otherwise it reads “holding steady”, because that is precisely what the model knows. The consequence is a page that frequently declines to make a call — the correct behaviour for a trend extrapolator, and the opposite of what a demo would do.
Interpretation is a separate layer, and it is shared
A number is not an insight. MacroTrendReading and CommodityTrendReading
(both in Gmi.RestClient, so the customer portal, the admin portal and the mobile app
render identical wording) turn a projection into a stance plus one sentence of plain English. Two
rules keep that from being decoration:
- Polarity is per series, never per arrow. Rising payrolls and rising unemployment both point up and mean opposite things. Colour follows the meaning, so a rising unemployment projection renders red while the arrow still points up. Getting this backwards would be the most misleading defect the platform could ship, which is why 35 tests assert it in both directions.
- Some series are not allowed a verdict. Average hourly earnings, M2, home prices and the saving rate are genuinely two-sided; among commodities, so are oil and silver. They return “cuts both ways” rather than a confident lie. For commodities the framing is sharper still: bullish and bearish describe the signal, not the price — gold rising is a fear bid and reads bearish, copper rising is industrial demand and reads bullish.