Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save quantra-go-algo/bd7601404d364ec76a0b3483f95db756 to your computer and use it in GitHub Desktop.

Select an option

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)
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