Initial import
git-svn-id: http://moon:8086/svn/projects/Stock@291 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# https://www.fmlabs.com/reference/default.htm?url=SimpleMA.htm
|
||||
|
||||
def sin(f, a, N):
|
||||
result = np.empty(0)
|
||||
for n in range(0, N):
|
||||
v = a*math.sin(2*math.pi*f*n/N)
|
||||
result = np.append(result, v)
|
||||
|
||||
return result
|
||||
|
||||
def ema(data, alpha=0.75):
|
||||
result = np.empty(0)
|
||||
r = data[0]
|
||||
|
||||
for v in data:
|
||||
r = alpha*r + (1-alpha)*v
|
||||
result = np.append(result, r)
|
||||
|
||||
return result
|
||||
|
||||
def macd(data):
|
||||
ema_short = ema(data, alpha=0.85)
|
||||
ema_long = ema(data, alpha=0.925)
|
||||
|
||||
return ema_short - ema_long
|
||||
|
||||
pd_data = pd.read_csv("aapl.csv", names=['Dates', 'Price'])
|
||||
np_data = np.flip(pd_data['Price'].to_numpy())
|
||||
a = sin(2, 1, 100)
|
||||
|
||||
plt.plot(np_data, label='Price')
|
||||
plt.plot(ema(np_data), label='EMA')
|
||||
plt.plot(macd(np_data), label='MACD')
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user