markowitz.backtest.walk_forward¶
markowitz.backtest.walk_forward
¶
Rolling walk-forward backtest engine.
WalkForward(returns: pd.DataFrame, strategies: Mapping[str, Strategy], *, rebalance: str = 'M', lookback: int = 120, rf: pd.Series | float | None = None, cost_bps: float = 10.0, debug_no_lookahead: bool = False)
¶
Rolling-window walk-forward backtester.
The engine slides a fixed-length lookback window across returns,
fits every supplied strategy on the strictly in-sample slice, and
holds the resulting weights until the next rebalance date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
DataFrame
|
Wide DataFrame of per-period simple returns indexed by date. |
required |
strategies
|
Mapping[str, Strategy]
|
Mapping |
required |
rebalance
|
str
|
Pandas offset alias. |
'M'
|
lookback
|
int
|
Length of the rolling estimation window, in periods. |
120
|
rf
|
Series | float | None
|
Risk-free rate; scalar or Series aligned to |
None
|
cost_bps
|
float
|
Proportional transaction cost in basis points per unit turnover. |
10.0
|
debug_no_lookahead
|
bool
|
If |
False
|
Source code in src/markowitz/backtest/walk_forward.py
run() -> BacktestResult
¶
Execute the walk-forward loop and return a :class:BacktestResult.
Source code in src/markowitz/backtest/walk_forward.py
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 | |