-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_simulation.py
More file actions
26 lines (24 loc) · 839 Bytes
/
plot_simulation.py
File metadata and controls
26 lines (24 loc) · 839 Bytes
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
import matplotlib.pyplot as pyplot
import prices
import simulation
def plot_beliefs(beliefs, color='k'):
belief_by_time = {}
for time, belief in beliefs:
belief_by_time.setdefault(time, []).append(belief)
x = belief_by_time.keys()
y = [sum(a) / float(len(a)) for a in belief_by_time.values()]
pyplot.plot(x, y, color=color)
return x
def run(traders, timesteps=100, lmsr_b=150):
market_fact = prices.LMSRFactory(lmsr_b)
sim_obj = simulation.Simulation(
timesteps, market_fact, traders)
sim_obj.simulate()
pyplot.figure()
x_overall = plot_beliefs(sim_obj.log.beliefs)
pyplot.plot(range(len(sim_obj.p_vec)),
[a * 100.0 for a in sim_obj.p_vec],
ls='--', color='r')
pyplot.ylim((0, 100))
print sim_obj.profits_by_user()
pyplot.show()