Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- T = 252 # 252 days ~ 52 weeks of 5 days ~ 12 months of 21 days
- for period in [1, 5, 21]: # sample every 1 day, 1 week, or 1 month
- x = np.arange(0, T, period)
- y = 100 + x + 3 * np.sin(x)
- returns = (y[1:] / y[:-1] - 1) # will be daily, weekly, monthly returns
- plt.plot(x, y)
- plt.show()
- plt.plot(returns)
- plt.show()
- print 'Sharpe Ratio: %.5f' % (np.sqrt(T/period) * returns.mean() / returns.std())
- # sqrt(T/period) is sqrt(252), ~ sqrt(52), sqrt(12)
Add Comment
Please, Sign In to add comment