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()
In [ ]:
In [ ]: