-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAgent.py
More file actions
36 lines (29 loc) · 1.23 KB
/
Copy pathRandomAgent.py
File metadata and controls
36 lines (29 loc) · 1.23 KB
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
import random as rand
from numpy import random
class RandomAgent:
def __init__(self, agent_id, lam):
self.agent_id = agent_id
self.timer = 0
self.holdingLimit = 100
self.lam = lam
# buyPrices are prices at which buyers are willing to buy, which is used when selling
# sellPrices are prices at which sellers are willing to sell, which is used when buying
def take_action(self, buyPrices, sellPrices):
# designate 0 to be sell, and 1 to be buy, 2 is do nothing
decision = rand.randint(0,2)
if self.timer ==0:
if decision == 0 and len(buyPrices) != 0:
price = rand.choice(buyPrices)
shares = rand.randint(0, self.holdingLimit)
self.timer = random.poisson(self.lam, 1)[0]
return decision, price, shares
elif decision == 1 and len(sellPrices) != 0:
price = rand.choice(sellPrices)
shares = rand.randint(0, self.holdingLimit)
self.timer = random.poisson(self.lam, 1)[0]
return decision, price, shares
else:
return None, None, None
else:
self.timer -= 1
return None, None, None