Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. ##Exercise 14
  2.  
  3. import scipy
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6.  
  7. lmbda = np.linspace(0,10,10)
  8. y = scipy.random.exponential(lmbda**(-1))
  9.  
  10. plt.plot(lmbda,y)
  11. plt.show()
  12.  
  13. y2 = scipy.random.uniform(1, 2*lmbda)
  14.  
  15. plt.plot(lmbda,y2)
  16. plt.show()
  17.  
  18. ##Exercise 24
  19.  
  20. import numpy.random as rd
  21. import random
  22.  
  23. data = {
  24. 50: 0.00832, 51: 0.00911, 52: 0.00996, 53: 0.01089, 54: 0.01190,
  25. 55: 0.01300, 56: 0.01421, 57: 0.01554, 58: 0.01700, 59: 0.01859,
  26. 60: 0.02034, 61: 0.02224, 62: 0.02431, 63: 0.02657, 64: 0.02904,
  27. 65: 0.03175, 66: 0.03474, 67: 0.03804, 68: 0.04168, 69: 0.04561,
  28. 70: 0.04979, 71: 0.05415, 72: 0.05865, 73: 0.06326, 74: 0.06812,
  29. 75: 0.07337, 76: 0.07918, 77: 0.08570, 78: 0.09306, 79: 0.10119,
  30. 80: 0.10998, 81: 0.11935, 82: 0.12917, 83: 0.13938, 84: 0.15001,
  31. 85: 0.16114, 86: 0.17282, 87: 0.18513, 88: 0.19825, 89: 0.21246,
  32. 90: 0.22814, 91: 0.24577, 92: 0.26593, 93: 0.28930, 94: 0.31666,
  33. 95: 0.35124, 96: 0.40056, 97: 0.48842, 98: 0.66815, 99: 0.72000,
  34. 100: 0.76000, 101: 0.80000, 102: 0.85000, 103: 0.90000,
  35. 104: 0.96000, 105: 1.00000}
  36.  
  37. def investment():
  38. money = 150000
  39. live = True
  40. age = 50
  41. while live == True:
  42. if age <= 70:
  43. interest = rd.uniform(0.08, 0.09)
  44. money += (money * interest) #gain interest
  45. money += 10000
  46. else:
  47. money += (money * interest) #gain interest
  48. money -= 65000
  49. age += 1
  50. death = random.uniform(0,1)
  51. if death <= data[age]:
  52. live = False
  53. else:
  54. continue
  55. return (money)
  56.  
  57. hist_money = []
  58. for _ in range(1000):
  59. hist_money.append(investment())
  60.  
  61. plt.hist(hist_money)
  62. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement