0

I am trying to calculate the macd of a stock using the panada_ta library.

The function I created to do so (will post below) works perfectly fine when I run it on it's own, but I am trying to call it within a calc_technicals() functions that calls several methods to conduct technical analysis on stocks, but it says my df is of type NoneType

def calc_macd(self, stock: Stock):
    macd = ta.macd(stock._df["Close"])
    stock._macd = macd["MACD_12_26_9"].tail()[-1]
    stock._macd_slow = macd["MACDs_12_26_9"].tail()[-1]

def calc_technicals(self):
    for stock in self._watchlist:
        self.calc_macd(stock)
        self.calc_rsi(stock)
        self.calc_vwap(stock)
        self.calc_ema(stock)

This is the error I get when I call the calc_technicals() method

enter image description here

Mamadou Coulibaly
  • 481
  • 1
  • 4
  • 5
  • Is there `None` or similar value in `self._watchlist`? – Capybara Jun 01 '22 at 04:47
  • No there isn't it is populated with custom Stock objects – Mamadou Coulibaly Jun 01 '22 at 14:24
  • 1
    So it appears that `macd` is None or something similar on the second line of the `calc_macd` function. Is it possible that `ta.macd(stock._df["Close"])` is returning None? Maybe that function does something but then has an empty `return` statement? – Capybara Jun 01 '22 at 16:12

0 Answers0