Fix out-of-sample states alignment in backtesting

Updated the out-of-sample (OOS) backtesting process to ensure that the states used are aligned with the OOS data frame index. This change addresses potential mismatches by applying a mask to the states based on the aligned index, improving the accuracy of the backtest results.
This commit is contained in:
Luke Mosoti
2026-05-11 15:43:42 +03:00
parent b2724a4115
commit 335fcc7b3f
2 changed files with 136 additions and 385 deletions
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -702,9 +702,13 @@ def _run_wfo(
start += step_bars
continue
# Align states to df_oos_aligned index (prepare_features drops first/last row)
oos_mask = df_oos_slice.index.isin(df_oos_aligned.index)
states_oos_al = states_oos[oos_mask]
try:
oos_result = vectorized_backtest(
df_oos_aligned, probs_oos, states_oos,
df_oos_aligned, probs_oos, states_oos_al,
split_idx=None, account_size=balance, broker=broker, tf=tf,
hmm_transmat=model_is.transmat_,
)