-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimeframe_converter.py
110 lines (88 loc) · 2.37 KB
/
timeframe_converter.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
def minute_1_to_five5(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to 5 minutes intervals
return df.resample('5T ').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_ten10(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to 10 minutes intervals
return df.resample('10T').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_fifteen15(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to 15 minutes intervals
return df.resample('15T').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_hourly(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to hourly intervals
return df.resample('H').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_day(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to monthly intervals
return df.resample('D').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_weekly(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to weekly intervals
return df.resample('W').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_monthly(df):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to monthly intervals
return df.resample('M').agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})
def minute_1_to_other(df, timeframe='5T'):
# set timestamp as index
df.set_index('timestamp', inplace=True)
# resample to other intervals
return df.resample(timeframe).agg({
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'volume': 'sum'
})