-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtrader_example.py
67 lines (52 loc) · 1.94 KB
/
trader_example.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
"""
Cinyoung Hur, [email protected]
James Park, [email protected]
seoulai.com
2018
"""
import seoulai_gym as gym
from seoulai_gym.envs.traders.agents import RandomAgentBuffett
def main():
# make Market enviroment
# TODO: add trading condition of real exchanges.
# then users will be able to choose exchange.
# gym.make("Market", exchange_name)
env = gym.make("Market")
# select exchange
env.select("upbit")
init_cash = 100000000 # KRW
a1 = RandomAgentBuffett("Buffett", init_cash)
current_agent = a1
obs = env.reset()
rew = 0 # reward
done = False
print("tick\t\t decision\t\t trad_price(ccld_price)\t\t"
+ "trad_qty(ccld_qty)\t\t fee\t\t cash\t\t asset_qty\t\t"
+ "asset_val\t\t portfolio_val\t\t 1tick_return\t\t 1tick_ret_ratio\t\t ")
i = 0
while True:
decision, trad_price, trad_qty = current_agent.act(obs, rew, done)
try:
obs, rew, done, info = env.step(
current_agent, decision, trad_price, trad_qty)
# data sheet
print("%5d %4s %10lf %10lf %10lf %10lf %10lf %10lf %10lf %10lf"
% (i, decision, trad_price, trad_qty, info["fee"],
current_agent.cash, current_agent.asset_qty,
current_agent.asset_val, info["1tick_return"],
info["1tick_ret_ratio"]))
except ValueError:
break
env.render(current_agent.cash+current_agent.asset_val, decision)
if done:
wallet = current_agent.cash+current_agent.asset_val
diff = wallet-init_cash
print("game over!!! " + info["msg"])
print("total result. Agent wallet: % f, Agent total_return: % f, Agent total_ret_ratio : %f" %
(wallet, diff, ((wallet/init_cash)-1)*100))
obs = env.reset()
break
i = i+1
env.close()
if __name__ == "__main__":
main()