- Zwischenstand
git-svn-id: http://moon:8086/svn/projects/Stock@296 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
+42
-4
@@ -45,18 +45,56 @@ def macd(data):
|
||||
|
||||
return ema_short - ema_long
|
||||
|
||||
data = {}
|
||||
if 0:
|
||||
# Get stock price via data reader
|
||||
start = datetime.datetime(2016,1,1)
|
||||
end = datetime.date.today()
|
||||
apple = web.DataReader("AAPL", "av-monthly", start, end, api_key=key)
|
||||
type(apple)
|
||||
data = web.DataReader("AAPL", "av-monthly", start, end, api_key=key)
|
||||
# data = web.DataReader("AAPL", "stooq", start, end)
|
||||
|
||||
pd_data = pd.read_csv("aapl.csv", names=['Dates', 'Price'])
|
||||
np_data = np.flip(pd_data['Price'].to_numpy())
|
||||
type(data)
|
||||
hdf = pd.HDFStore('aapl.h5')
|
||||
hdf['open'] = data['open']
|
||||
hdf['close'] = data['close']
|
||||
hdf['high'] = data['high']
|
||||
hdf['low'] = data['low']
|
||||
hdf.close()
|
||||
|
||||
else:
|
||||
hdf = pd.HDFStore('aapl.h5', 'r')
|
||||
data['open'] = hdf['open']
|
||||
data['close'] = hdf['close']
|
||||
data['high'] = hdf['high']
|
||||
data['low'] = hdf['low']
|
||||
hdf.close()
|
||||
|
||||
df = pd.DataFrame({"A": ["a", "b", "c", "a"]})
|
||||
print(df)
|
||||
|
||||
v = data.values()
|
||||
i = data.items()
|
||||
print(data)
|
||||
|
||||
data['ema'] = ema(data['close'], alpha=0.75)
|
||||
|
||||
data['open'].plot()
|
||||
data['close'].plot()
|
||||
data['high'].plot()
|
||||
data['low'].plot()
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
np_data = np.flip(data['close'].to_numpy())
|
||||
|
||||
plt.subplot(211)
|
||||
plt.plot(np_data, label='Price')
|
||||
plt.plot(ema(np_data), label='EMA')
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
|
||||
plt.subplot(212)
|
||||
plt.plot(macd(np_data), label='MACD')
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
|
||||
Reference in New Issue
Block a user