Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import numpy as np
  2.  
  3. beta = 1.41 #Yahoo finance
  4. import matplotlib.pyplot as plt
  5. from mpl_toolkits.mplot3d import Axes3D
  6. import matplotlib.mlab as mlab
  7. from scipy.stats import multivariate_normal
  8.  
  9. def convert(a, b):
  10. current_stock_price = 27.96*beta*(1+a)
  11. #convert that market into a enterprise value
  12. eps = current_stock_price / b
  13. return eps
  14.  
  15. total = []
  16. for i in range(10000):
  17. # draw a random chance market
  18. a = np.random.normal(loc=.05, scale=.21)
  19. b = np.random.normal(loc=17.51, scale = 2.44)
  20. total.append(convert(a,b))
  21.  
  22.  
  23. # fig = plt.figure()
  24.  
  25. # n, bins, patches = plt.hist(total, bins=20, normed=1, facecolor='green', alpha=0.5)
  26.  
  27. # mu, sigma = np.mean(total), np.std(total)
  28. # y = mlab.normpdf(bins, mu, sigma)
  29.  
  30. # plt.plot(bins, y, 'r--')
  31. # plt.ylabel('Probability')
  32. # plt.xlabel('Earnings Per Share')
  33. # plt.title('Monte Carlo Prediction of Earnings Per Share')
  34. # info = "Mean: " + "%.2f"%mu +" | Standard Deviaiton: " + "%.2f"% sigma
  35. # plt.text(4, .65, info)
  36.  
  37. # # Tweak spacing to prevent clipping of ylabel
  38. # plt.subplots_adjust(left=0.15)
  39. # plt.show()
  40.  
  41. x = np.linspace(-1,1,500)
  42. y = np.linspace(0,32,500)
  43. X, Y = np.meshgrid(x,y)
  44. pos = np.empty(X.shape + (2,))
  45. pos[:, :, 0] = X; pos[:, :, 1] = Y
  46.  
  47. mu = np.array([.05, 17.51])
  48. sigma = np.array([.21, 2.44])
  49. covariance = np.diag(sigma**2)
  50. z = multivariate_normal(mean=mu, cov=covariance).pdf(pos) * 17.51
  51.  
  52. #Make a 3D plot
  53. fig = plt.figure()
  54. ax = fig.gca(projection='3d')
  55. ax.plot_surface(X, Y, z,cmap='viridis',linewidth=0)
  56. ax.set_xlabel('Projected Market Increase')
  57. ax.set_ylabel('Projected Price/Earning Ratio')
  58. ax.set_zlabel('Projected Earnings Per Share')
  59. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement