Luchkata / Algorithmic_Trading_Machine_Learning

202 stars 125 forks source link

Macd bug #3

Open AiAzez opened 1 month ago

AiAzez commented 1 month ago

I keep getting error from macd: def compute_macd(close): macd = pandas_ta.macd(close=close, length=20).iloc[:,0] return macd.sub(macd.mean()).div(macd.std())

df['macd'] = df.groupby(level=1, group_keys=False)['adj close'].apply(compute_macd)


TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'


result = self._python_apply_general(f, self._selected_obj) values, mutated = self._grouper.apply_groupwise(f, data, self.axis) res = f(group) return op(a, b)

what is the solution

AiAzez commented 1 month ago

I find the problem, because of 2 stocks joined SP500 since 1 week 'GEV' & 'SOLV', how i can extract them from the data?

seriousammy commented 1 month ago

@AiAzez Hey if thats a problem, for learning purposes i would try to just omit the stocks that joined the S&P500

symbols_list = sp500['Symbol'].unique().tolist()

# ['GEV', 'SOLV', 'VLTO']: YFChartError(....)

stocks_to_remove = ['GEV', 'SOLV', 'VLTO']

symbols_list = [stock for stock in symbols_list if stock not in stocks_to_remove]