Aug-03-2019, 07:58 PM
Hi Yoriz, thank you for the reply and help. I tried some reworking the script in the hope of making changes based on your suggestion (i hope i did). I am getting the following error message
This is the new version:
Error:Traceback (most recent call last):
File "C:\Users\bgeor\Desktop\multiEMAs.py", line 24, in <module>
ema_val = ExpMovingAverage(val, 3)
File "C:\Users\bgeor\Desktop\multiEMAs.py", line 16, in ExpMovingAverage
a = np.convolve(values, weights, mode='full')[:len(values)]
File "C:\Users\bgeor\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\core\numeric.py", line 1114, in convolve
return multiarray.correlate(a, v[::-1], mode)
TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
in the reworked version i removed the linesget_curprices = lambda:stockdata()[0] #getting dataset of current prices into a dictionary dict_curprices = {} dict_curprices.update(get_curprices()) get_openprices = lambda:stockdata()[1] #getting dataset of open prices into a dictionary dict_openprices = {} dict_openprices.update(get_openprices())as it seems they won't affect the result i'm after
This is the new version:
import numpy as np import pandas as pd from yahoofinancials import YahooFinancials stocks = ['AAPL', 'MSFT', 'TSLA'] def stockdata(): yahoo_financials = YahooFinancials(stocks) price = yahoo_financials.get_current_price() Open = yahoo_financials.get_open_price() return price, Open def ExpMovingAverage(values, window): weights = np.exp(np.linspace(-1., 0., window)) weights /= weights.sum() a = np.convolve(values, weights, mode='full')[:len(values)] a[:window] = a[window] return a if __name__ == "__main__": dF = pd.DataFrame(stockdata()) data = dict(dF) for val in data.keys(): ema_val = ExpMovingAverage(val, 3) print(ema_val, key)