Skip to content

Commit

Permalink
Merge pull request #1268 from tgibson11/no-risk-overlay
Browse files Browse the repository at this point in the history
Improve code for handling when risk overlay is not configured
  • Loading branch information
robcarver17 authored Oct 12, 2023
2 parents c82a225 + 079bb16 commit 0d4695a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
9 changes: 5 additions & 4 deletions sysproduction/strategy_code/report_system_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,12 @@ def risk_scaling_string(backtest) -> str:
backtest_system_portfolio_stage.get_leverage_for_original_position().iloc[-1]
)
percentage_vol_target = backtest_system_portfolio_stage.get_percentage_vol_target()
risk_scalar = backtest_system_portfolio_stage.get_risk_scalar()
if type(risk_scalar) is pd.Series:
risk_scalar_final = risk_scalar.iloc[-1]
try:
risk_scalar = backtest_system_portfolio_stage.get_risk_scalar()
except missingData:
risk_scalar_final = 1.0
else:
risk_scalar_final = risk_scalar
risk_scalar_final = risk_scalar.iloc[-1]
risk_overlay_config = (
backtest_system_portfolio_stage.config.get_element_or_arg_not_supplied(
"risk_overlay"
Expand Down
17 changes: 7 additions & 10 deletions systems/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,18 @@ def get_notional_position(self, instrument_code: str) -> pd.Series:
self.get_notional_position_before_risk_scaling(instrument_code)
)

risk_scalar = self.get_risk_scalar()
if type(risk_scalar) is pd.Series:
try:
risk_scalar = self.get_risk_scalar()
except missingData:
self.log.debug("No risk overlay in config: won't apply risk scaling")
notional_position = notional_position_without_risk_scalar
else:
risk_scalar_reindex = risk_scalar.reindex(
notional_position_without_risk_scalar.index
)
notional_position = (
notional_position_without_risk_scalar * risk_scalar_reindex.ffill()
)
else:
notional_position = notional_position_without_risk_scalar

return notional_position

Expand Down Expand Up @@ -960,12 +962,7 @@ def capital_multiplier(self):
@diagnostic()
def get_risk_scalar(self) -> pd.Series:

risk_overlay_config = self.config.get_element_or_arg_not_supplied(
"risk_overlay"
)
if risk_overlay_config is arg_not_supplied:
self.log.debug("No risk overlay in config: won't apply risk scaling")
return 1.0
risk_overlay_config = self.config.get_element("risk_overlay")

normal_risk = self.get_portfolio_risk_for_original_positions()
shocked_vol_risk = (
Expand Down

0 comments on commit 0d4695a

Please sign in to comment.