Hi everybody,
In the past i did something like the next part of code to do an calculation to all stocks in my universe at once:
prices = history(context.returns_lookback, '1d', 'price')
# Calculate the past X days' returns for each security.
returns = (prices.iloc[-1] - prices.iloc[0]) / prices.iloc[0]
Now i want to do the same with a stochastic oscillator, but with my code it gives a logical but iritating error that it can not do this calculation to all the stocks at once. Does anyone has some hints to how i can solve this? I would prefer not doing it with a loop to loop over all the stocks. This is my current not working code snap
def getStoch(H, L, C):
return talib.STOCH(H, L, C,
fastk_period=14,
slowk_period=3,
slowd_period=3)
H = history(25, '1d', 'high')
L = history(25, '1d', 'low')
C = history(25, '1d', 'close_price')
slowk, slowd = getStoch(H, L, C)
k_val = slowk[-1]
d_val = slowd[-1]