Created
June 24, 2026 01:29
-
-
Save quantra-go-algo/2f928adb14a38265f98a19b7798c3a91 to your computer and use it in GitHub Desktop.
guardrailed-llm-agent — Step 8: The Walk-Forward Loop: Keeping It Honest (snippet 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # One continuous agent position series across the whole OOS window | |
| agent_parts = [] | |
| params_by_day = {} | |
| for idx, policy, guard in month_blocks: | |
| seg = feat_all.loc[idx] | |
| agent_parts.append(build_agent_positions( | |
| seg, policy, | |
| state_lag = state_lag_full.loc[idx], # cross-month continuity | |
| vol_lag = vol_lag_full.loc[idx], | |
| )) | |
| for t in idx: params_by_day[t] = guard | |
| agent_pos = pd.concat(agent_parts) | |
| # Agent-only equity | |
| eq_agent = equity_from_positions(feat_oos, agent_pos) | |
| # Guardrailed equity (continuous guardrail state: no monthly reset) | |
| guard_pos = apply_guardrails_oos( | |
| feat_oos, agent_pos, params_by_day, vol_lag_oos | |
| ) | |
| eq_guard = equity_from_positions(feat_oos, guard_pos) | |
| # Buy-and-hold benchmark over identical window | |
| eq_bh = np.exp(feat_oos['ret'].fillna(0.0).cumsum()) | |
| return eq_agent/eq_agent.iloc[0], eq_guard/eq_guard.iloc[0], eq_bh/eq_bh.iloc[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment