-
Notifications
You must be signed in to change notification settings - Fork 6
/
data_preprocessing.py
32 lines (26 loc) · 1.11 KB
/
data_preprocessing.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
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
class FeatureExtractor:
def __init__(self, df):
self.df = df
self.open = df['open'].astype('float')
self.high = df['high'].astype('float')
self.low = df['low'].astype('float')
self.close = df['close'].astype('float')
self.volume = df['volume'].astype('float')
def add_bar_features(self):
self.df['bar_ho'] = self.high - self.open
self.df['bar_hl'] = self.high - self.low
self.df['bar_hc'] = self.high - self.close
self.df['bar_co'] = self.close - self.open
self.df['bar_ol'] = self.open - self.low
self.df['bar_cl'] = self.close - self.low
self.df['bar_mov'] = self.df['close'] - self.df['close'].shift(1)
return self.df
def add_adj_features(self):
self.df['adj_open'] = self.df['open'] / self.close
self.df['adj_high'] = self.df['high'] / self.close
self.df['adj_low'] = self.df['low'] / self.close
self.df['adj_close'] = self.df['close'] / self.close
return self.df