-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
37 lines (30 loc) · 1.17 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
# -*- coding: utf-8 -*-
"""utils.py
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/14FAWiDrEqpanseiUWvd9PTG0Ve8WfJgk
"""
#creating states, environments and required preprocessing
import tqdm
from tqdm import tqdm
def sigmoid(x):
return 1 / (1 + math.exp(-x))
# returns an an n-day state representation ending at time t
def getState(data, t, n):
d = t - n + 1
block = data[d:t + 1] if d >= 0 else -d * [data[0]] + data[0:t + 1] # pad with t0
#block is which is the for [1283.27002, 1283.27002]
res = []
for i in range(n - 1):
res.append(sigmoid(block[i + 1] - block[i]))
return np.array([res])
# Plots the behavior of the output
def plot_behavior(data_input, states_buy, states_sell, profit):
fig = plt.figure(figsize = (15,5))
plt.plot(data_input, color='r', lw=2.)
plt.plot(data_input, '^', markersize=10, color='m', label = 'Buying signal', markevery = states_buy)
plt.plot(data_input, 'v', markersize=10, color='k', label = 'Selling signal', markevery = states_sell)
plt.title('Total gains: %f'%(profit))
plt.legend()
#plt.savefig('output/'+name+'.png')
plt.show()