TypeError: ufunc true_divide cannot use operands with types dtype('<m8[ns]') and dtype('O')

Hi Team,



I have registered for  Quantitative Portfolio Management  . in that while i am executing the below code



"# Calculate annualised returns

annual_returns = ((((stock_prices.iloc[-1]-stock_prices.iloc[0]) /

                    stock_prices.iloc[0])+1)**(252/len(stock_prices)) - 1)"



Getting the below error



TypeError: ufunc true_divide cannot use operands with types dtype('<m8[ns]') and dtype('O')

Hi Nandagopal,

The code you gave here, in the first glance, is missing a closing parenthesis.

Also, can you please share which notebook (Section/Unit) this code is from? 

Thanks.