When I am running this line of code from webinar:
pf = alphien.portfolio.Portfolio(tkr)
pf.payout(equalWeightsSP500Select, df)
pf.evaluate()
pf.backtest()
It gives me the below error…Why would this happen? I just copy the codes directly from the equalWeightsSP500Select function, and same error applies to my own strategy as well
TypeError Traceback (most recent call last)
<ipython-input-35-3e5a23fd86ed> in <module>
1 pf = alphien.portfolio.Portfolio(tkr)
2 pf.payout(equalWeightsSP500Select, df)
----> 3 pf.evaluate()/mnt/public/IT/Libs/Python/alphien/portfolio/portfolio.py in evaluate(self, startDate, endDate, zoom, period, lastN, computationDataPoints, rollEval, alignAndFillDates)
394 if rollEval is None:
395 self.singleEval(startDate=startDate, endDate=endDate, zoom=zoom, period=period, lastN=lastN, computationDataPoints=computationDataPoints,
–> 396 rollEval=False, alignAndFillDates=alignAndFillDates)
397 else:
398 self.rollEval(startDate=startDate, endDate=endDate, zoom=zoom, period=period, rollingWindow=rollEval, computationDataPoints=computationDataPoints)/mnt/public/IT/Libs/Python/alphien/portfolio/portfolio.py in singleEval(self, startDate, endDate, zoom, period, lastN, computationDataPoints, rollEval, alignAndFillDates, composeLogic)
446 try:
447 if i==0:
–> 448 weights = payout(*self.payoutParams[0][i],**self.payoutParams[1][i])
449 else:
450 # If i>0, compose weights as defined by composeLogic<ipython-input-31-5dcf50d6f290> in equalWeightsSP500Select(features, industry)
2 def equalWeightsSP500Select(features, industry=None, ):
3 inclusionMatrix = getTickersSP500(ticker=features.tickers, startDate=features.startDate, endDate=features.endDate, industry=industry, asPrice=True)
----> 4 weights = inclusionMatrix / inclusionMatrix.sum(axis=1).values[:,None]
5 return weights/opt/conda/lib/python3.6/site-packages/pandas/core/ops/init.py in f(self, other, axis, level, fill_value)
649 if isinstance(other, ABCDataFrame):
650 # Another DataFrame
–> 651 new_data = self._combine_frame(other, na_op, fill_value)
652
653 elif isinstance(other, ABCSeries):/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py in _combine_frame(self, other, func, fill_value)
5861 return func(left, right)
5862
-> 5863 new_data = ops.dispatch_to_series(self, other, _arith_op)
5864 return new_data
5865/opt/conda/lib/python3.6/site-packages/pandas/core/ops/init.py in dispatch_to_series(left, right, func, axis)
273 # _frame_arith_method_with_reindex
274
–> 275 bm = left._mgr.operate_blockwise(right._mgr, array_op)
276 return type(left)(bm)
277/opt/conda/lib/python3.6/site-packages/pandas/core/internals/managers.py in operate_blockwise(self, other, array_op)
362 Apply array_op blockwise with another (aligned) BlockManager.
363 “”"
–> 364 return operate_blockwise(self, other, array_op)
365
366 def apply(self: T, f, align_keys=None, **kwargs) -> T:/opt/conda/lib/python3.6/site-packages/pandas/core/internals/ops.py in operate_blockwise(left, right, array_op)
36 lvals, rvals = _get_same_shape_values(blk, rblk, left_ea, right_ea)
37
—> 38 res_values = array_op(lvals, rvals)
39 if left_ea and not right_ea and hasattr(res_values, “reshape”):
40 res_values = res_values.reshape(1, -1)/opt/conda/lib/python3.6/site-packages/pandas/core/ops/array_ops.py in arithmetic_op(left, right, op)
183 if should_extension_dispatch(lvalues, rvalues) or isinstance(rvalues, Timedelta):
184 # Timedelta is included because numexpr will fail on it, see GH#31457
–> 185 res_values = op(lvalues, rvalues)
186
187 else:/opt/conda/lib/python3.6/site-packages/pandas/core/ops/invalid.py in invalid_op(self, other)
51 def invalid_op(self, other=None):
52 typ = type(self).name
—> 53 raise TypeError(f"cannot perform {name} with this index type: {typ}")
54
55 invalid_op.name = nameTypeError: cannot perform truediv with this index type: DatetimeArray