-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.py
34 lines (26 loc) · 858 Bytes
/
simulator.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
from mortgage import Mortgage
from agent import Agent
import numpy as np
import random
import timeit
class Simulator():
def __init__(self):
self.m = Mortgage()
def simulate():
s = Simulator()
a = Agent()
for i in range(10):
print('\n\n------')
print('\ngetting action from agent')
state = s.m.state()
action = a.get_action(s.m.refinance_opportunities(), state)
print("\nenacting action in environment")
reward = s.m.enact(action)
print("\nupdating agent policies based on reward = ", reward)
a.update(action, reward, state, s.m.time, s.m.coupon_payment)
def main():
np.random.seed(0)
random.seed(0)
Simulator.simulate()
if __name__ == '__main__':
main()