I'm connected to refinitiv to get data of stock prices because I'm trying to optimize my portfolio, the following code is how I got the data:
stocks_list = ['STLAM.MI','AAPL.O','AMZN.OQ','BULTEN.ST','PRIO3.SA','SEPL.L', 'HAL.N', 'TOU.TO', 'TYMN.L', 'kimbera.mx', '005930.KS' ]
def get_prices(stocks, start_date):
stock_prices, err = ek.get_data(stocks,
['TR.PriceClose.date','TR.PriceClose'],
{'SDate':start_date, 'EDate':'0D'})
stock_prices['Date'] = pd.to_datetime(stock_prices['Date'])
stock_prices = stock_prices.set_index(['Date','Instrument'])
stock_prices = stock_prices.unstack()
stock_prices.columns = stock_prices.columns.get_level_values(1)
return stock_prices
prices = get_prices(stocks_list, start_date='-2Y').dropna()
ax = prices.rebase().plot()
After that chunk of code I'm trying to display the stock prices stats with the following code:
np.seterr(all='ignore')
stats = prices.calc_stats()
stats.display()
But I'm getting the following error:
TypeError Traceback (most recent call last)
Cell In[9], line 2
1 np.seterr(all='ignore')
----> 2 stats = prices.calc_stats()
3 stats.display()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffn/core.py:1231, in calc_stats(prices)
1229 return PerformanceStats(prices)
1230 elif isinstance(prices, pd.DataFrame):
-> 1231 return GroupStats(*[prices[x] for x in prices.columns])
1232 else:
1233 raise NotImplementedError("Unsupported type")
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffn/core.py:838, in GroupStats.__init__(self, *prices)
836 self._end = self._prices.index[-1]
837 # calculate stats for entire series
--> 838 self._update(self._prices)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffn/core.py:848, in GroupStats._update(self, data)
847 def _update(self, data):
--> 848 self._calculate(data)
849 self._update_stats()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ffn/core.py:855, in GroupStats._calculate(self, data)
...
323 # add first month
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/_libs/missing.pyx:382, in pandas._libs.missing.NAType.__bool__()
TypeError: boolean value of NA is ambiguous
I already dropped all of the NAs in the prices dataframe. I tried prices.isna().sum() to double check and I got 0 for all of my columns. I also tried prices.fillna(0) but that didn't work either. I got the same error message. What can I do to display the stock prices stats?