def setUp(self):
     dt_start = dt.datetime(2008, 1, 1)
     dt_end = dt.datetime(2009, 12, 31)
     ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt.timedelta(hours=16))
     
     dataobj = da.DataAccess('Yahoo', cachestalltime=0)
     year = '2012'
     stock_list = 'sp500' + year
     ls_symbols = dataobj.get_symbols_from_list(stock_list)
     ls_symbols.append('SPY')
     ls_keys = ['open', 'high', 'low', 'close', 'volume', 'actual_close']
     all_stocks = get_tickdata(ls_symbols=ls_symbols, ldt_timestamps=ldt_timestamps)
     df_events = self.find_events(ls_symbols, all_stocks)
     self.event_no = ep.eventprofiler(df_events, all_stocks, i_lookback=20, i_lookforward=20,
                 b_market_neutral=True, b_errorbars=True,
                 s_market_sym='SPY')
Exemple #2
0
 def setUp(self):
     order_list = []
     with open("orders.csv", 'rU') as csvfile:
         order_reader = csv.reader(csvfile, delimiter=',', skipinitialspace=True)
         for row in order_reader:
             date = dt.datetime(int(row[0]),int(row[1]), int(row[2]), 16)
             o = Order(action=row[4], date=date, tick=row[3], shares=row[5])
             order_list.append(o)
     # order_list needs to be sorted. Otherwise the algorithm won't work.
     date_list = [x.date for x in order_list]
     date_list.sort()
     dt_timeofday = dt.timedelta(hours=16)
     dt_start = date_list[0]     
     dt_end = date_list[-1] 
     tick_set = sets.Set([x.tick for x in order_list])
     ls_symbols = ['$SPX']
     while(tick_set):
         ls_symbols.append(tick_set.pop())
     ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt_timeofday)
     cash = 1000000
     all_stocks = get_tickdata(ls_symbols=ls_symbols, ldt_timestamps=ldt_timestamps)
     self.pf = Portfolio(equities=all_stocks, cash=cash, dates=ldt_timestamps, order_list=order_list)
     self.benchmark = self.pf.equities['$SPX']
     self.pf.sim()
Exemple #3
0
         if len(row) == 4:
             o = Order(action=row[2], date=date, tick=row[1], shares=row[3])
         else:
             o = Order(action=row[2], date=date, tick=row[1], shares=row[3], price=row[4])
         order_list.append(o)
 # order_list needs to be sorted. Otherwise the algorithm won't work.
 date_list = [x.date for x in order_list]
 date_list.sort()
 dt_start = date_list[0]     
 dt_end = date_list[-1] 
 tick_set = sets.Set([x.tick for x in order_list])
 ls_symbols = ['$GSPC']
 while(tick_set):
     ls_symbols.append(tick_set.pop())
 ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt_timeofday)
 all_stocks = get_tickdata(ls_symbols=ls_symbols, ldt_timestamps=ldt_timestamps)
 pf = Portfolio(equities=all_stocks, cash=cash, dates=ldt_timestamps, order_list=order_list)
 pf.sim()
 equity_col = ['buy', 'sell', 'close']
 pf.csvwriter(csv_file=value_file, d=',', cash=False)
 print "The final value of the portfolio using the sample file is -- ", pf.total[-1]
 print "Details of the Performance of the portfolio :"
 print "Data Range :",    ldt_timestamps[0],    "to",    ldt_timestamps[-1]
 print "Sharpe Ratio of Fund :", pf.sharpe_ratio() 
 print "Sortino Ratio of Fund :", pf.sortino() 
 print "Sharpe Ratio of $GSPC :", pf.equities['$GSPC'].sharpe_ratio()
 print "Total Return of Fund :", pf.return_ratio()
 print " Total Return of $GSPC :", pf.equities['$GSPC'].return_ratio()
 print "Standard Deviation of Fund :", pf.std()
 print " Standard Deviation of $GSPC :", pf.equities['$GSPC'].std()
 print "Average Daily Return of Fund :", pf.avg_daily_return()
Exemple #4
0
                       date=date,
                       tick=row[1],
                       shares=row[3],
                       price=row[4])
         order_list.append(o)
 # order_list needs to be sorted. Otherwise the algorithm won't work.
 date_list = [x.date for x in order_list]
 date_list.sort()
 dt_start = date_list[0]
 dt_end = date_list[-1]
 tick_set = sets.Set([x.tick for x in order_list])
 ls_symbols = ['$GSPC']
 while (tick_set):
     ls_symbols.append(tick_set.pop())
 ldt_timestamps = du.getNYSEdays(dt_start, dt_end, dt_timeofday)
 all_stocks = get_tickdata(ls_symbols=ls_symbols,
                           ldt_timestamps=ldt_timestamps)
 pf = Portfolio(equities=all_stocks,
                cash=cash,
                dates=ldt_timestamps,
                order_list=order_list)
 pf.sim()
 equity_col = ['buy', 'sell', 'close']
 pf.csvwriter(csv_file=value_file, d=',', cash=False)
 print("The final value of the portfolio using the sample file is -- ",
       pf.total[-1])
 print("Details of the Performance of the portfolio :")
 print("Data Range :", ldt_timestamps[0], "to", ldt_timestamps[-1])
 print("Sharpe Ratio of Fund :", pf.sharpe_ratio())
 print("Sortino Ratio of Fund :", pf.sortino())
 print("Sharpe Ratio of $GSPC :", pf.equities['$GSPC'].sharpe_ratio())
 print("Total Return of Fund :", pf.return_ratio())