feat(research): add canonical session reporting and analytics
This commit is contained in:
parent
1e164450c3
commit
3838295eec
28 changed files with 2402 additions and 47 deletions
85
libs/core/types/src/canonical-analytics.ts
Normal file
85
libs/core/types/src/canonical-analytics.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/** Explicit reporting inputs, independent from financial/execution policy. */
|
||||
export interface CanonicalMetricsInput {
|
||||
version: 1;
|
||||
periodsPerYear: number;
|
||||
annualRiskFreeRate: number | null;
|
||||
/** Benchmark-dependent reporting is unsupported in version 1. */
|
||||
benchmark: null;
|
||||
}
|
||||
|
||||
export interface CanonicalMetricsPolicy extends CanonicalMetricsInput {
|
||||
calendarId: string;
|
||||
calendarRevision: string;
|
||||
sampling: 'account-boundary-after-observations-v1';
|
||||
marks: 'last-available-no-per-session-freshness-certification';
|
||||
returnUnit: 'fraction';
|
||||
variance: 'sample-n-minus-one';
|
||||
riskFreeConversion: 'annual-rate-divided-by-periods-per-year';
|
||||
downside: 'full-series-rms-relative-to-risk-free';
|
||||
partialPeriods: 'visible-excluded-from-periodic-statistics';
|
||||
drawdown: 'session-end-and-terminal-sampled';
|
||||
exposureBasis: 'elapsed-calendar-time';
|
||||
cagrBasis: 'elapsed-calendar-days-365';
|
||||
zeroTerminalCagr: 'negative-one-for-positive-elapsed-time';
|
||||
}
|
||||
|
||||
export type CanonicalMetricUnavailableReason =
|
||||
| 'nonpositive-baseline'
|
||||
| 'negative-terminal-equity'
|
||||
| 'zero-duration'
|
||||
| 'nonfinite-result'
|
||||
| 'undefined-period-return'
|
||||
| 'insufficient-periods'
|
||||
| 'missing-risk-free'
|
||||
| 'missing-benchmark'
|
||||
| 'zero-variance'
|
||||
| 'zero-downside-deviation'
|
||||
| 'unsupported-round-trips';
|
||||
|
||||
export interface CanonicalSessionReturn {
|
||||
sessionId: string;
|
||||
periodStart: number;
|
||||
periodEnd: number;
|
||||
partialStart: boolean;
|
||||
partialEnd: boolean;
|
||||
value: number | null;
|
||||
/** Complete period with a defined return; an undefined complete period invalidates
|
||||
* the entire periodic-statistics sequence, not just this individual sample. */
|
||||
eligible: boolean;
|
||||
reason?: 'nonpositive-baseline' | 'nonfinite-result';
|
||||
}
|
||||
|
||||
/** Statistical numbers are approximate reporting values, never ledger postings. */
|
||||
export interface CanonicalMetrics {
|
||||
totalReturn: number | null;
|
||||
cagr: number | null;
|
||||
maxDrawdown: number | null;
|
||||
exposureTime: number | null;
|
||||
volatility: number | null;
|
||||
downsideDeviation: number | null;
|
||||
sharpeRatio: number | null;
|
||||
sortinoRatio: number | null;
|
||||
var95: number | null;
|
||||
cvar95: number | null;
|
||||
var99: number | null;
|
||||
alpha: null;
|
||||
beta: null;
|
||||
informationRatio: null;
|
||||
roundTripCount: null;
|
||||
winRate: null;
|
||||
profitFactor: null;
|
||||
avgWin: null;
|
||||
avgLoss: null;
|
||||
}
|
||||
|
||||
export interface CanonicalBacktestAnalytics {
|
||||
version: 1;
|
||||
policy: CanonicalMetricsPolicy;
|
||||
sessionReturns: CanonicalSessionReturn[];
|
||||
completePeriodCount: number;
|
||||
/** Zero if any complete-period return is undefined; do not shorten the sequence. */
|
||||
periodicSampleCount: number;
|
||||
fillCount: number;
|
||||
metrics: CanonicalMetrics;
|
||||
unavailable: Partial<Record<keyof CanonicalMetrics, CanonicalMetricUnavailableReason>>;
|
||||
}
|
||||
|
|
@ -51,6 +51,14 @@ export type {
|
|||
BacktestRunTrade,
|
||||
BacktestRunResult,
|
||||
} from './backtest-run';
|
||||
export type {
|
||||
CanonicalMetricsInput,
|
||||
CanonicalMetricsPolicy,
|
||||
CanonicalMetricUnavailableReason,
|
||||
CanonicalSessionReturn,
|
||||
CanonicalMetrics,
|
||||
CanonicalBacktestAnalytics,
|
||||
} from './canonical-analytics';
|
||||
|
||||
// Export helper types
|
||||
export type { HasClose, HasOHLC, HasTimestamp, HasVolume } from './helpers';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue