File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
src/quant_research_starter/tuning Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -212,12 +212,21 @@ def objective(trial: Trial) -> float:
212212 )
213213 results = backtest .run (weight_scheme = "rank" )
214214
215- metrics_calc = RiskMetrics (results ["returns" ])
215+ returns = results ["returns" ]
216+ n_steps = 5 # Number of intermediate steps for reporting
217+ step_size = max (1 , len (returns ) // n_steps )
218+ for step in range (step_size , len (returns ) + 1 , step_size ):
219+ partial_returns = returns .iloc [:step ]
220+ metrics_calc = RiskMetrics (partial_returns )
221+ metrics = metrics_calc .calculate_all ()
222+ metric_value = metrics .get (metric , 0.0 )
223+ trial .report (metric_value , step )
224+ if trial .should_prune ():
225+ raise optuna .TrialPruned ()
226+
227+ # Final metric on all returns
228+ metrics_calc = RiskMetrics (returns )
216229 metrics = metrics_calc .calculate_all ()
217-
218- if trial .should_prune ():
219- raise optuna .TrialPruned ()
220-
221230 metric_value = metrics .get (metric , 0.0 )
222231 return float (metric_value )
223232
You can’t perform that action at this time.
0 commit comments