Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Exercise 14
- import scipy
- import numpy as np
- import matplotlib.pyplot as plt
- lmbda = np.linspace(0,10,10)
- y = scipy.random.exponential(lmbda**(-1))
- plt.plot(lmbda,y)
- plt.show()
- y2 = scipy.random.uniform(1, 2*lmbda)
- plt.plot(lmbda,y2)
- plt.show()
- ##Exercise 24
- import numpy.random as rd
- import random
- data = {
- 50: 0.00832, 51: 0.00911, 52: 0.00996, 53: 0.01089, 54: 0.01190,
- 55: 0.01300, 56: 0.01421, 57: 0.01554, 58: 0.01700, 59: 0.01859,
- 60: 0.02034, 61: 0.02224, 62: 0.02431, 63: 0.02657, 64: 0.02904,
- 65: 0.03175, 66: 0.03474, 67: 0.03804, 68: 0.04168, 69: 0.04561,
- 70: 0.04979, 71: 0.05415, 72: 0.05865, 73: 0.06326, 74: 0.06812,
- 75: 0.07337, 76: 0.07918, 77: 0.08570, 78: 0.09306, 79: 0.10119,
- 80: 0.10998, 81: 0.11935, 82: 0.12917, 83: 0.13938, 84: 0.15001,
- 85: 0.16114, 86: 0.17282, 87: 0.18513, 88: 0.19825, 89: 0.21246,
- 90: 0.22814, 91: 0.24577, 92: 0.26593, 93: 0.28930, 94: 0.31666,
- 95: 0.35124, 96: 0.40056, 97: 0.48842, 98: 0.66815, 99: 0.72000,
- 100: 0.76000, 101: 0.80000, 102: 0.85000, 103: 0.90000,
- 104: 0.96000, 105: 1.00000}
- def investment():
- money = 150000
- live = True
- age = 50
- while live == True:
- if age <= 70:
- interest = rd.uniform(0.08, 0.09)
- money += (money * interest) #gain interest
- money += 10000
- else:
- money += (money * interest) #gain interest
- money -= 65000
- age += 1
- death = random.uniform(0,1)
- if death <= data[age]:
- live = False
- else:
- continue
- return (money)
- hist_money = []
- for _ in range(1000):
- hist_money.append(investment())
- plt.hist(hist_money)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement