PageRenderTime 76ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/python/pandas_ex.py

https://bitbucket.org/jaredlander/lab
Python | 37 lines | 22 code | 15 blank | 0 comment | 1 complexity | 8146b5aa42181dca4081f5ffcf46184e MD5 | raw file
  1. import numpy as np
  2. import pandas.io.data as web
  3. def pct_change(x):
  4. return x / x.shift(1) - 1
  5. stocks = ['AAPL', 'FB', 'GOOG']
  6. st = '2012-1-1'
  7. ed = '2012-9-29'
  8. dd = {}
  9. for s in stocks:
  10. dd[s] = web.get_data_yahoo(s, st, ed)['Adj Close']
  11. from pandas import DataFrame
  12. df = DataFrame(dd)
  13. df
  14. returns = df.pct_change()
  15. returns = returns.dropna(how='all').sort_indx(ascending=False)
  16. type(returns)
  17. fb = return_arr[:, 1]
  18. fb.std()
  19. fb[::-1]
  20. fb[::2]
  21. fb_asc = fb[::-1]
  22. fb_asc = aapl