-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw1_1.py
50 lines (38 loc) · 1.51 KB
/
hw1_1.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
import numpy as np
import pandas as pd
import utils_io
###########
# problem 1
###########
def print_prescient_mean(p0, p1):
utils_io.plot_histogram(pd.Series(np.maximum(p0, p1)), '1.1b prescient revenues', 'num paths with revenue', 'revenue')
print 'prescient expected revenue', str(np.mean(np.maximum(p0, p1)))
def print_no_knowledge_mean(p0, p1, mu0, mu1, sigma0, sigma1):
exp_mean0 = np.exp(mu0 + sigma0**2 / 2)
exp_mean1 = np.exp(mu1 + sigma1**2 / 2)
if exp_mean0 > exp_mean1:
p_to_use = p0
else:
p_to_use = p1
utils_io.plot_histogram(pd.Series(p_to_use), '1.1b no knowledge expected revenue', 'num paths with revenue', 'revenue')
print 'no knowledge mean', str(np.mean(p_to_use))
def print_partial_knowledge_mean(p0, p1, mu1, sigma1):
exp_mean1 = np.exp(mu1 + sigma1**2 / 2)
p_to_use = np.where(p0 > exp_mean1, p0, p1)
utils_io.plot_histogram(pd.Series(p_to_use), '1.1b partial knowledge expected revenue', 'num paths with revenue',
'revenue')
print 'partial knowledge revenues', str(np.mean(p_to_use))
def prob_1():
mu0 = 0.0
mu1 = 0.1
sigma0 = 0.4
sigma1 = 0.4
num_samples = 1000000
p0 = np.exp(np.random.normal(mu0, sigma0, num_samples))
p1 = np.exp(np.random.normal(mu1, sigma1, num_samples))
utils_io.label('1.1b')
print_prescient_mean(p0, p1)
print_no_knowledge_mean(p0, p1, mu0, mu1, sigma0, sigma1)
print_partial_knowledge_mean(p0, p1, mu1, sigma1)
if __name__ == '__main__':
prob_1()