-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
73 lines (52 loc) · 1.33 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# example.py
import pandas as pd
import numpy as np
from feature_space import (
Column, SMA, RSI, SuperTrend, ATR, Change, Momentum,
MACDSignal, MACD, EMA, MACDHistogram, Dataset
)
df = pd.DataFrame(
{
key: np.random.random(100)
for key in ('Open', 'High', 'Low', 'Close', 'Volume')
}
)
print(df)
high = Column('High')
low = Column('Low')
close = Column('Close')
close_change = Change(close)
close_rsi_14 = RSI(close_change, 14)
close_momentum = Momentum(close_change, 35)
atr = ATR(high, low, close)
super_trend = SuperTrend(close, atr, 14, 3)
close_sma_20 = SMA(close, 20)
close_ema_34 = EMA(close, 34)
macd = MACD(close_ema_34, close_sma_20)
macd_signal_15 = MACDSignal(macd, 15)
macd_histogram = MACDHistogram(macd_signal_15)
print(df)
change_indicators = Dataset(
name='Change_Features',
features=[close_change, close_rsi_14, close_momentum]
)
change_indicators.calculate(df)
df.dropna(inplace=True)
print(df)
atr_indicators = Dataset(
name='ATR_Features',
features=[atr, super_trend]
)
atr_indicators.calculate(df)
df.dropna(inplace=True)
print(df)
macd_indicators = Dataset(
name='MACD_Features',
features=[
close_sma_20, close_momentum,
macd, macd_signal_15, macd_histogram
]
)
macd_indicators.calculate(df)
df.dropna(inplace=True)
print(macd_indicators.copy())