There is a possible inconsistency and/or vulnerabilty in code from the Q model algo cloned from here Quantopian Risk Model In Algorithms. I would rather call it a possible implementation bug. This snippet of code pertaining to beta (also recently changed to SimpleBeta) is exposed for users to change:
# Alpha Combination
# -----------------
# Assign every asset a combined rank and center the values at 0.
# For UNIVERSE_SIZE=500, the range of values should be roughly -250 to 250.
combined_alpha = (fcf_zscore + yield_zscore + sentiment_zscore).rank().demean()
**beta = 0.66*RollingLinearRegressionOfReturns(
target=sid(8554),
returns_length=5,
regression_length=260,
mask=combined_alpha.notnull() & Sector().notnull()
).beta + 0.33*1.0**
This beta calculation is used to constrain beta to minimum and maximum levels per user setting in Optimize API:
# Constrain beta-to-SPY to remain under the contest criteria.
beta_neutral = opt.FactorExposure(
pipeline_data[['beta']],
**min_exposures={'beta': -0.05},
max_exposures={'beta': 0.05},**
)
Contest threshold for beta is between +- 0.30. If user has the option to change window length in beta calculation, (1) doesn't this create inconsistencies with the beta threshold of +-0.30 because the beta distribution of different window lengths is also different, and (2) doesn't this create vulnerabilities in the sense that it could be used to "game" the algo if the beta constraint operation in Optimize API actually worked. I think the beta calculation code should be hardwired to standardized one year daily returns and hidden from user to change parameters perhaps in the riskloadings pipeline. Beta calculation should have fixed window length not configurable by user to be standardized, otherwise, the contest threshold for beta of between +- 0.30 becomes relative. So let's test this and see what the impact is against the baseline code. The only change we will make is change the regression_length=260 to regression_length=63. Below is first the baseline and next is the revision: