Created
June 24, 2026 01:29
-
-
Save quantra-go-algo/bd7601404d364ec76a0b3483f95db756 to your computer and use it in GitHub Desktop.
guardrailed-llm-agent — Step 6: From Policy to Position: Sizing with Volatility Targeting (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
| def vol_scale(base_exposure, realized_vol): | |
| # Scale toward TARGET_VOL=0.25 using yesterday's realized vol. | |
| # Yesterday's vol avoids lookahead: we only know today's vol at close. | |
| if not USE_VOL_TARGET or base_exposure == 0.0: | |
| return base_exposure | |
| if pd.isna(realized_vol) or realized_vol <= 0: | |
| return base_exposure | |
| return base_exposure * min(TARGET_VOL / realized_vol, MAX_LEVERAGE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment