Untitled
unknown
plain_text
8 months ago
3.1 kB
4
Indexable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-73-e4852422b760> in <module>()
----> 1 export_to_excel(prices, start_date, end_date, rebalance_frequency, output_file="momentum_strategy.xlsx")
<ipython-input-72-248457d6c1e4> in export_to_excel(prices, start_date, end_date, rebalance_frequency, output_file)
141 Runs the backtest and exports the results to an Excel file.
142 """
--> 143 portfolio_df = rebalance_portfolio(prices, start_date, end_date, rebalance_frequency)
144 portfolio_df.to_excel(output_file, index=False)
145 print(f"Momentum strategy results saved to {output_file}")
<ipython-input-72-248457d6c1e4> in rebalance_portfolio(prices, start_date, end_date, rebalance_frequency, initial_aum)
109 for rebalance_date in rebalance_dates:
110 # Find the nearest trading day on or after the rebalance date
--> 111 rebalance_date = prices.index[prices.index >= rebalance_date].min()
112
113 if pd.isnull(rebalance_date):
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexes\base.py in cmp_method(self, other)
142 else:
143 with np.errstate(all="ignore"):
--> 144 result = ops.comparison_op(self._values, np.asarray(other), op)
145
146 if is_bool_dtype(result):
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\ops\array_ops.py in comparison_op(left, right, op)
249 warnings.simplefilter("ignore", DeprecationWarning)
250 with np.errstate(all="ignore"):
--> 251 res_values = na_arithmetic_op(lvalues, rvalues, op, is_cmp=True)
252
253 return res_values
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\ops\array_ops.py in na_arithmetic_op(left, right, op, is_cmp)
141
142 try:
--> 143 result = expressions.evaluate(op, left, right)
144 except TypeError:
145 if is_cmp:
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\computation\expressions.py in evaluate(op, a, b, use_numexpr)
231 use_numexpr = use_numexpr and _bool_arith_check(op_str, a, b)
232 if use_numexpr:
--> 233 return _evaluate(op, op_str, a, b) # type: ignore
234 return _evaluate_standard(op, op_str, a, b)
235
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\computation\expressions.py in _evaluate_numexpr(op, op_str, a, b)
117
118 if result is None:
--> 119 result = _evaluate_standard(op, op_str, a, b)
120
121 return result
~\AppData\Roaming\Python\Python36\site-packages\pandas\core\computation\expressions.py in _evaluate_standard(op, op_str, a, b)
66 _store_test_result(False)
67 with np.errstate(all="ignore"):
---> 68 return op(a, b)
69
70
TypeError: '>=' not supported between instances of 'numpy.ndarray' and 'Timestamp'Editor is loading...
Leave a Comment