PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/plots/stats/moments_ewmvol.py

http://github.com/wesm/pandas
Python | 23 lines | 16 code | 7 blank | 0 comment | 0 complexity | d6da626f95c399419626cfe5ad455377 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. import matplotlib.pyplot as plt
  2. import pandas.util.testing as t
  3. import pandas.stats.moments as m
  4. t.N = 500
  5. ts = t.makeTimeSeries()
  6. ts[::100] = 20
  7. s = ts.cumsum()
  8. plt.figure(figsize=(10, 5))
  9. plt.plot(s.index, m.ewmvol(s, span=50, min_periods=1).values, color='b')
  10. plt.plot(s.index, m.rolling_std(s, 50, min_periods=1).values, color='r')
  11. plt.title('Exp-weighted std with shocks')
  12. plt.legend(('Exp-weighted', 'Equal-weighted'))
  13. f = plt.gcf()
  14. f.autofmt_xdate()
  15. plt.show()
  16. plt.close('all')