Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/robcarver17/pysystemtrade
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
rob committed Oct 18, 2023
2 parents c7311d8 + 0d4695a commit 972940f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
7 changes: 6 additions & 1 deletion sysproduction/strategy_code/report_system_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +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_final = backtest_system_portfolio_stage.get_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.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 972940f

Please sign in to comment.