-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_environment.py
69 lines (53 loc) · 1.76 KB
/
test_environment.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
68
69
from Environment import Environment
import unittest
class TestCases(unittest.TestCase):
def test_empty_sell_rejection(self):
env = Environment()
env.reset()
init_balance = env.portfolio["balance"]
try:
state, reward, done = env.step({
"buy":0,
"sell":3
})
self.assertTrue(False, "Disabled Selling With Empty Porflio")
except AssertionError:
self.assertTrue(True)
def test_buying(self):
env = Environment()
env.reset()
init_balance = env.portfolio["balance"]
state, reward, done = env.step({
"buy": 3,
"sell": 0
})
self.assertLess(env.portfolio["balance"], init_balance, "Buying Does Decrease Account Balance")
def test_selling(self):
env = Environment()
env.reset()
state, reward, done = env.step({
"buy": 3,
"sell": 0
})
init_balance = env.portfolio["balance"]
state, reward, done = env.step({
"buy": 0,
"sell": 2
})
after_balance = env.portfolio["balance"]
self.assertGreater(after_balance, init_balance, "Selling Does Increase Account Balance")
def test_rewards(self):
env = Environment()
env.reset()
state, reward, done = env.step({
"buy": 3,
"sell": 0
})
sell_price = env._get_state(False)[0].iloc[-1]["close"]
state, reward, done = env.step({
"buy": 0,
"sell": 3
})
self.assertEqual(reward, sell_price *3, "Rewards are Estimated Correctly")
if __name__ == "__main__":
unittest.main()