<s> '''<STR_LIT>''' <EOL> import matplotlib . pyplot as plt <EOL> from pylab import * <EOL> from qstkutil import DataAccess as da <EOL> from qstkutil import qsdateutil as du <EOL> from qstkutil import tsutil as tsu <EOL> import datetime as dt <EOL> portfolio = np . loadtxt ( '<STR_LIT>' , <EOL> dtype = '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:U+002C>' , <EOL> comments = '<STR_LIT:#>' , <EOL> skiprows = <NUM_LIT:1> , <EOL> ) <EOL> print portfolio <EOL> portfolio = sorted ( portfolio , key = lambda x : x [ <NUM_LIT:0> ] ) <EOL> print portfolio <EOL> portsyms = [ ] <EOL> portalloc = [ ] <EOL> for i in portfolio : <EOL> portsyms . append ( i [ <NUM_LIT:0> ] ) <EOL> portalloc . append ( i [ <NUM_LIT:1> ] ) <EOL> dataobj = da . DataAccess ( '<STR_LIT>' ) <EOL> all_symbols = dataobj . get_all_symbols ( ) <EOL> intersectsyms = list ( set ( all_symbols ) & set ( portsyms ) ) <EOL> badsyms = [ ] <EOL> if size ( intersectsyms ) < size ( portsyms ) : <EOL> badsyms = list ( set ( portsyms ) - set ( intersectsyms ) ) <EOL> print "<STR_LIT>" <EOL> print badsyms <EOL> for i in badsyms : <EOL> index = portsyms . index ( i ) <EOL> portsyms . pop ( index ) <EOL> portalloc . pop ( index ) <EOL> endday = dt . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> startday = endday - dt . timedelta ( days = <NUM_LIT> ) <EOL> timeofday = dt . timedelta ( hours = <NUM_LIT:16> ) <EOL> print "<STR_LIT>" <EOL> timestamps = du . getNYSEdays ( startday , endday , timeofday ) <EOL> print "<STR_LIT>" <EOL> close = dataobj . get_data ( timestamps , portsyms , "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> rets = close . values . copy ( ) <EOL> tsu . fillforward ( rets ) <EOL> tsu . returnize0 ( rets ) <EOL> portrets = sum ( rets * portalloc , axis = <NUM_LIT:1> ) <EOL> porttot = cumprod ( portrets + <NUM_LIT:1> ) <EOL> componenttot = cumprod ( rets + <NUM_LIT:1> , axis = <NUM_LIT:0> ) <EOL> plt . clf ( ) <EOL> fig = plt . figure ( ) <EOL> fig . add_subplot ( <NUM_LIT> ) <EOL> plt . plot ( timestamps , componenttot , alpha = <NUM_LIT> ) <EOL> plt . plot ( timestamps , porttot ) <EOL> names = portsyms <EOL> names . append ( '<STR_LIT>' ) <EOL> plt . legend ( names ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> plt . xlabel ( '<STR_LIT>' ) <EOL> fig . autofmt_xdate ( rotation = <NUM_LIT> ) <EOL> savefig ( '<STR_LIT>' , format = '<STR_LIT>' ) </s>
