Guest User

Untitled

a guest
Mar 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import math
  4. import numpy as np
  5.  
  6. num_stocks = 100000
  7. mean_initial_fair_price = 100.0
  8. stddev_initial_fair_price = 10.0
  9. stddev_noise = 0.01
  10. mean_num_shares = 1000
  11. stddev_num_shares = 100
  12. # 1.0004^250 is approximately 1.1. In other words, if 1.0004 is the
  13. # mean return for a day, then 1.1 (a ten percent gain) is the mean
  14. # return for a year (there are roughly 250 trading days in a year).
  15. mean_return = 1.0004
  16. stddev_return = 0.01
  17. num_days = 250
  18. sum_cum_market_cap_returns = 0
  19. sum_day_market_cap_returns = 0
  20. sum_cum_ew_returns = 0
  21. sum_day_ew_returns = 0
  22.  
  23. def day():
  24. global fair_prices, market_prices
  25. market_caps = np.multiply(market_prices, num_shares)
  26. total_market_cap = np.sum(market_caps)
  27. cap_weights = np.divide(market_caps, total_market_cap)
  28. returns = np.random.normal(mean_return, stddev_return, num_stocks)
  29. fair_prices = np.multiply(fair_prices, returns)
  30. noise = np.random.normal(1.0, stddev_noise, num_stocks)
  31. market_prices = np.multiply(fair_prices, noise)
  32. cap_weighted_return = np.dot(cap_weights, returns)
  33. equally_weighted_return = np.sum(returns) / num_stocks
  34. return (cap_weighted_return, equally_weighted_return)
  35.  
  36. fair_prices = np.random.normal(mean_initial_fair_price,
  37. stddev_initial_fair_price, num_stocks)
  38. noise = np.random.normal(1.0, stddev_noise, num_stocks)
  39. market_prices = np.multiply(fair_prices, noise)
  40. num_shares = np.random.normal(mean_num_shares, stddev_num_shares,
  41. num_stocks)
  42. cum_cap_weighted_return = 1.0
  43. cum_equally_weighted_return = 1.0
  44. for d in range(num_days):
  45. (cap_weighted_return, equally_weighted_return) = day()
  46. cum_cap_weighted_return *= cap_weighted_return
  47. cum_equally_weighted_return *= equally_weighted_return
  48.  
  49. print('Cum cap weighted return %f' % cum_cap_weighted_return)
  50. print('Cum equally weighted return %f' % cum_equally_weighted_return)
  51. daily_cap_weighted_return = \
  52. math.pow(cum_cap_weighted_return, 1.0 / num_days)
  53. daily_equally_weighted_return = \
  54. math.pow(cum_equally_weighted_return, 1.0 / num_days)
  55. print('Daily cap weighted return %f' % daily_cap_weighted_return)
  56. print('Daily equally weighted return %f' % daily_equally_weighted_return)
Add Comment
Please, Sign In to add comment