Every time I try to use StaticAssets it returns the following error:
TypeError: MaximizeAlpha() expected a value with dtype 'float64' or 'int64' for argument 'alphas', but got 'object' instead.
There was a runtime error on line 100.
I've tried using universe=Filters.StaticAssets(context.stock) but that returns a key error 'stock'. How would I go about fixing this.
def make_pipeline(context):
"""
A function to create our dynamic stock selector (pipeline). Documentation
on pipeline can be found here:
https://www.quantopian.com/help#pipeline-title
"""
my_etfs = (StaticAssets(symbols('IVV','EFA','AGG','IJH','IWM','IWD','IWF','LQD','EEM','EZU',
)))
#first factor + winsorizing to prevent outliers
fac = Fundamentals.equity_per_share_growth.latest
fac_wins = fac.winsorize(min_percentile=0.05, max_percentile=0.95)
#putting it into z-score form
finalfactor = fac_wins.zscore()
#deciding shorts and longs
longs = finalfactor.top(TOTAL_POSITIONS//2, mask=my_etfs)
shorts = finalfactor.bottom(TOTAL_POSITIONS//2, mask=my_etfs)
#adding another screen
finalscreen = (longs | shorts)
pipe = Pipeline(
columns={
'longs': longs,
'shorts': shorts,
'finalfactor': finalfactor
},
screen=(finalscreen & my_etfs)
)
return pipe
def before_trading_start(context, data):
"""
Called every day before market open.
"""
context.output = algo.pipeline_output('pipeline')
context.risk_loadings = algo.pipeline_output('risk_factors')
# These are the securities that we are interested in trading each day.
context.security_list = context.output.index
def rebalance(context, data):
"""
Execute orders according to our schedule_function() timing.
"""
pipeline_data = context.output
risk_loadings = context.risk_loadings
objective = opt.MaximizeAlpha(pipeline_data.finalfactor)
constraints = []
constraints.append(opt.MaxGrossExposure(MAX_GROSS_LEVERAGE))
constraints.append(opt.DollarNeutral())
neutralize_risk_factors = opt.experimental.RiskModelExposure(
risk_model_loadings=risk_loadings,
version=0)
constraints.append(neutralize_risk_factors)
constraints.append(
opt.PositionConcentration.with_equal_bounds(min=-MAX_SHORT_POSITION_SIZE,
max=MAX_LONG_POSITION_SIZE))
algo.order_optimal_portfolio(objective=objective, constraints=constraints)