ValueError: operands could not be broadcast together with shapes (67,) (252,)

Hi,
For this line of code at the end, i am getting below error. Using python 3.9, pandas version 2.2.0, please help.
import matplotlib.pyplot as plt
%matplotlib inline

Multiply the future percentage returns with the signals generated to calculate the strategy’s performance

strategy_perf1=pd.Series(strategy_perf*data_sim.close.pct_change().shift(-1).iloc[-simulation_length:].values)
plt.plot(np.nancumprod(strategy_perf1+1))

ValueError: operands could not be broadcast together with shapes (67,) (252,)

Course Name: Decision Trees in Trading, Section No: 10, Unit No: 12, Unit type: Notebook

Hi,

So this error is because the two arrays being multiplied have different shapes:

  1. strategy_perf has 67 elements.
  2. data_sim.close.pct_change().shift(-1).iloc[-simulation_length:].values has 252 elements.

I ran the notebook on my end, and it executed without any errors (i.e., both arrays had the same shape [252]). Please ensure that you are running the previous code cell completely (without interruption) before executing this one. Please let us know if the issue persists.

Thanks for the reply