-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
64 lines (42 loc) · 1.46 KB
/
test.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
import torch
from torch.utils.data import DataLoader
import numpy as np
from data import StockData
from models import Conv
import matplotlib.pyplot as plt
import random
from sim import Sim
test = StockData(train=False)
net = Conv()
net.load_model()
net.eval()
simulation = Sim(tickers=['GOOG'],time_frame=('2020-01-01','2021-06-30'), initial_deposit=100000,log=False)
simulation.print_account()
same = []
while True:
for ticker in simulation.tickers:
x,y = simulation.get_x(ticker)
pred = net(x).squeeze()
action = pred.argmax()
same.append((action ==y).item())
if action == 1 : # Increase in the next 10 days; BUY
simulation.buy(ticker)
else: #SELL
simulation.sell(ticker)
if simulation.next_day():
for ticker in simulation.tickers:
if simulation.num_shares_owned[ticker]>0:
print(f'REMAINING SHARES HELD IN {ticker} -> {simulation.num_shares_owned[ticker]}')
print(f'SELLING ALL REMAINING SHARES in {ticker}')
for ticker in simulation.tickers:
if simulation.num_shares_owned[ticker]>0:
for s in range(simulation.num_shares_owned[ticker]):
simulation.sell(ticker)
simulation.print_account()
print(sum(same)/len(same))
break
# simulation.add_more_money(500)
# for i in range(10):
# x,y = test[i]
# p = net(x.unsqueeze(0))
# print(p.argmax(),y)