ret 0.259406 stdev 0.141263 sharpe 1.836329 HD 0.160262 PYPL 0.163804 SBUX 0.151671 UNH 0.169210 WEC 0.355054 Name: 1834, dtype: float64 ret 0.239737 stdev 0.135932 sharpe 1.763657 HD 0.158094 PYPL 0.137120 SBUX 0.092738 UNH 0.051022 WEC 0.561026 Name: 1672, dtype: float64


In [14]:
import pandas as pd
   from pandas import DataFrame as df
   import matplotlib.pyplot as plt

   def load_file(filename) :
      data = pd.read_pickle(filename)
      target = 'Stock'
      if target in data :
         name = data.pop(target)
         name = name[0]
         return name, data
      name = filename.split("/")[-1]
      name = name.split(".")[0]
      return name, data
   def main(file_list, stock_list) :
       for path in file_list :
           name, ret = load_file(path)
           if name not in stock_list :
              del ret
              continue
           yield name, ret 

   from glob import glob
   import os,sys

   pwd = os.getcwd()
   ini_list = glob('{}/*.ini'.format(pwd))
   file_list = glob('{}/historical_prices/*pkl'.format(pwd))
   file_list = sorted(file_list)
   spy_list = filter(lambda x : 'SPY' in x, file_list)
   spy = spy_list[0]
   print spy
    
   stock_list = ["HD", "PYPL", "SBUX", "UNH", "WEC"]
   target_01 = 'Adj Close'
   stocks = {'SPY' : spy }
   for name, data in main(file_list, stock_list) :
       stocks[name] = data
   for key in stocks.keys() :
       data = stocks[key]
       returns = data[target_01]
       returns = returns.pct_change()
       returns.plot(label=name)
       print returns.description()
   target_02 = 'Volume'
   for key in stocks.keys() :
       data = stocks[key]
       volume = data[target_01]
       volume = volume.pct_change()
       volume.plot(label=name)
       print returns.description()


/sandbox/repo/stock-study/lib/historical_prices/SPY.pkl
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-3c9ae3b0d861> in <module>()
     41     returns = data[target_01]
     42     returns = returns.pct_change()
---> 43     returns.plot(label=name)
     44     print returns.description()
     45 target_02 = 'Volume'

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2739                            colormap=colormap, table=table, yerr=yerr,
   2740                            xerr=xerr, label=label, secondary_y=secondary_y,
-> 2741                            **kwds)
   2742     __call__.__doc__ = plot_series.__doc__
   2743 

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_core.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   1988                 **kwds):
   1989 
-> 1990     import matplotlib.pyplot as plt
   1991     if ax is None and len(plt.get_fignums()) > 0:
   1992         ax = _gca()

/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py in <module>()
    122 from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
    123 from matplotlib.compat import subprocess
--> 124 from matplotlib.rcsetup import (defaultParams,
    125                                 validate_backend,
    126                                 cycler)

/usr/local/lib/python2.7/dist-packages/matplotlib/rcsetup.py in <module>()
     31     import collections as abc
     32 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
---> 33 from matplotlib.colors import is_color_like
     34 
     35 

/usr/local/lib/python2.7/dist-packages/matplotlib/colors.py in <module>()
     66 import numpy as np
     67 from numpy import ma
---> 68 import matplotlib.cbook as cbook
     69 from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
     70 

AttributeError: 'module' object has no attribute 'cbook'

In [ ]:


In [ ]: