Created
June 24, 2026 01:29
-
-
Save quantra-go-algo/223deb54d15cb5e0b24a12d7c81d39b3 to your computer and use it in GitHub Desktop.
guardrailed-llm-agent — Step 6: From Policy to Position: Sizing with Volatility Targeting (snippet 4)
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
| def build_agent_positions(df_seg, policy, state_lag=None, vol_lag=None, mom_lag=None): | |
| if state_lag is None: state_lag = df_seg['state'].shift(1) | |
| if vol_lag is None: vol_lag = df_seg['vol'].shift(1) | |
| pos = pd.Series(0.0, index=df_seg.index) | |
| for t in df_seg.index: | |
| s = state_lag.loc[t] | |
| if pd.isna(s): continue | |
| rec = policy.get(s, {'action': 'LONG', 'size': 0.5}) | |
| base = action_to_base_exposure(rec['action'], rec['size']) | |
| pos.loc[t] = vol_scale(base, vol_lag.loc[t]) | |
| return pos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment