feat(strategies): add canonical regime-aware mean reversion
This commit is contained in:
parent
75abae2cfc
commit
6a67ae8683
24 changed files with 1910 additions and 88 deletions
|
|
@ -17,7 +17,7 @@ const identity = z
|
|||
);
|
||||
const period = z.number().int().min(1).max(maxStrategyPeriod);
|
||||
|
||||
export const builtinStrategySelectionSchema = z
|
||||
export const smaStrategySelectionSchema = z
|
||||
.object({
|
||||
ownerId: identity,
|
||||
strategyId: z
|
||||
|
|
@ -48,4 +48,61 @@ export const builtinStrategySelectionSchema = z
|
|||
})
|
||||
.strict();
|
||||
|
||||
export const meanReversionStrategySelectionSchema = z
|
||||
.object({
|
||||
ownerId: identity,
|
||||
strategyId: z
|
||||
.string()
|
||||
.refine(
|
||||
value => builtinStrategy(value) === 'mean_reversion',
|
||||
'Unsupported canonical strategy'
|
||||
)
|
||||
.transform(() => 'mean_reversion' as const),
|
||||
strategyVersion: z.literal('mean-reversion-regime-long-only/v1'),
|
||||
seed: z.number().int().min(0).max(0xffffffff),
|
||||
instrumentId: identity,
|
||||
seriesId: identity,
|
||||
ownerBudget: z
|
||||
.string()
|
||||
.transform(value => parseFinancialDecimal(value))
|
||||
.refine(
|
||||
value => !value.startsWith('-') && value !== '0.00000000',
|
||||
'Owner budget must be positive'
|
||||
),
|
||||
parameters: z
|
||||
.object({
|
||||
lookbackPeriod: period.min(2),
|
||||
trendPeriod: period.min(3),
|
||||
momentumPeriod: period,
|
||||
volatilityPeriod: period.min(2),
|
||||
entryZScore: z.number().finite().positive(),
|
||||
exitZScore: z.number().finite().nonnegative(),
|
||||
minTrendReturn: z.number().finite().gt(-1),
|
||||
minMomentumReturn: z.number().finite().gt(-1),
|
||||
maxVolatility: z.number().finite().nonnegative(),
|
||||
minNotionalVolume: z
|
||||
.string()
|
||||
.transform(value => parseFinancialDecimal(value))
|
||||
.refine(value => !value.startsWith('-'), 'Notional volume must be nonnegative'),
|
||||
regimeFilter: z.enum(['volatility', 'none']),
|
||||
})
|
||||
.strict()
|
||||
.refine(
|
||||
value => value.trendPeriod > value.lookbackPeriod,
|
||||
'Trend period must exceed the mean-reversion lookback'
|
||||
)
|
||||
.refine(
|
||||
value => value.exitZScore < value.entryZScore,
|
||||
'Exit threshold must be below the entry threshold'
|
||||
),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const builtinStrategySelectionSchema = z.union([
|
||||
smaStrategySelectionSchema,
|
||||
meanReversionStrategySelectionSchema,
|
||||
]);
|
||||
export type SmaStrategySelection = z.infer<typeof smaStrategySelectionSchema>;
|
||||
export type MeanReversionStrategySelection = z.infer<typeof meanReversionStrategySelectionSchema>;
|
||||
export type MeanReversionSignalParameters = MeanReversionStrategySelection['parameters'];
|
||||
export type BuiltinStrategySelection = z.infer<typeof builtinStrategySelectionSchema>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue