Guest User

Untitled

a guest
Jan 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. T = 252 # 252 days ~ 52 weeks of 5 days ~ 12 months of 21 days
  5. for period in [1, 5, 21]: # sample every 1 day, 1 week, or 1 month
  6. x = np.arange(0, T, period)
  7. y = 100 + x + 3 * np.sin(x)
  8. returns = (y[1:] / y[:-1] - 1) # will be daily, weekly, monthly returns
  9. plt.plot(x, y)
  10. plt.show()
  11. plt.plot(returns)
  12. plt.show()
  13. print 'Sharpe Ratio: %.5f' % (np.sqrt(T/period) * returns.mean() / returns.std())
  14. # sqrt(T/period) is sqrt(252), ~ sqrt(52), sqrt(12)
Add Comment
Please, Sign In to add comment