-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_analysis.py
34 lines (27 loc) · 1.02 KB
/
data_analysis.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
import pandas as pd
import numpy as np
from itertools import islice
import matplotlib.pyplot as plt
data = pd.read_csv('GBPUSD_30M.csv', parse_dates=[0])
data.columns = map(str.lower, data.columns)
data.columns = data.columns.str.replace(' ', '_')
data['range'] = (data['close'] - data['open']) * 10000
data['body'] = np.where(data['range'] > 0, 'green', 'red')
def trend_bars():
repeats = 1
body = data['body'][0]
trend = [{'body':body , 'repeats':repeats}]
trend_index = 0
for index, row in islice(data.iterrows(), 1, None):
if row['body'] == trend[trend_index]['body']:
repeats = repeats + 1
trend[trend_index]['repeats'] = repeats
else:
repeats = 1
trend.append({'body':row['body'], 'repeats':repeats})
trend_index = trend_index + 1
return trend
trend_bars = pd.DataFrame(trend_bars())
print(trend_bars['repeats'].value_counts(normalize=True))
# plt.plot(data['local_time'], data['range'])
# plt.show()