fix: unify backtest execution and add forward validation candidates
Share point-in-time signals and a cash-funded order ledger across backtests and trading. Correct eligibility, missing-price fills, quality factors, regime inputs, warmup windows, and cash-injection accounting. Add reproducible registered-strategy comparisons and paired forward candidates with a 20% resize band. Validation: 125 Python tests, 23 web tests, TypeScript/Vite build, 87 strategy causality checks, and real-data target/order/equity parity for 10 strategies.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from strategies.base import Strategy
|
||||
from strategies.base import StockStrategy, mask_scores
|
||||
|
||||
|
||||
class InverseVolatilityStrategy(Strategy):
|
||||
class InverseVolatilityStrategy(StockStrategy):
|
||||
"""
|
||||
Risk parity via inverse-volatility weighting.
|
||||
|
||||
@@ -17,13 +17,13 @@ class InverseVolatilityStrategy(Strategy):
|
||||
def __init__(self, vol_window: int = 20):
|
||||
self.vol_window = vol_window
|
||||
|
||||
def generate_signals(self, data: pd.DataFrame) -> pd.DataFrame:
|
||||
returns = data.pct_change()
|
||||
def generate_signals(self, data: pd.DataFrame, eligible: pd.DataFrame | None = None) -> pd.DataFrame:
|
||||
returns = data.pct_change(fill_method=None)
|
||||
vol = returns.rolling(self.vol_window).std()
|
||||
|
||||
# Replace zero vol with NaN to avoid division by zero
|
||||
vol = vol.replace(0, np.nan)
|
||||
inv_vol = 1.0 / vol
|
||||
inv_vol = mask_scores((1.0 / vol).where(data.notna()), eligible)
|
||||
|
||||
row_sums = inv_vol.sum(axis=1).replace(0, np.nan)
|
||||
signals = inv_vol.div(row_sums, axis=0).fillna(0.0)
|
||||
|
||||
Reference in New Issue
Block a user