forked from philipperemy/deep-learning-bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
53 lines (46 loc) · 1.51 KB
/
utils.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
import matplotlib
matplotlib.use('Agg')
def compute_returns(p):
close_prices = p['price_close']
close_prices_returns = 100 * ((close_prices.shift(-1) - close_prices) / close_prices).fillna(0.0)
return close_prices_returns.shift(1).fillna(0)
def plot_p(df):
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
fig, ax = plt.subplots()
candlestick2_ohlc(ax,
df['price_open'].values,
df['price_high'].values,
df['price_low'].values,
df['price_close'].values,
width=0.6,
colorup='g',
colordown='r',
alpha=1)
plt.show()
print('Done.')
def save_to_file(df, filename):
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
fig, ax = plt.subplots()
candlestick2_ohlc(ax,
df['price_open'].values,
df['price_high'].values,
df['price_low'].values,
df['price_close'].values,
width=0.6,
colorup='g',
colordown='r',
alpha=1)
plt.savefig(filename)
plt.close(fig)
def mkdir_p(path):
import os
import errno
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise