예제 #1
0
def strat_backtest1(strat, start, end, num, diff, startval):
    """
    @summary: Back tests a strategy defined in a python script that takes
              in a start
    and end date along with a starting value a set number of times.
    @param strat: filename of python script strategy
    @param start: starting date in a datetime object
    @param end: ending date in a datetime object
    @param num: number of tests to perform
    @param diff: offset in days of the tests
    @param startval: starting value of fund during back tests
    @return fundsmatrix: Datamatrix of fund values returned from each test
    @rtype datamatrix
    """
    fundsmatrix = []
    startdates = du.getNextNNYSEdays(start, num * diff, dt.timedelta(hours=16))
    enddates = du.getNextNNYSEdays(end, num * diff, dt.timedelta(hours=16))
    for start, end in zip(startdates, enddates):
        cmd = "python %s %s %s temp_alloc.pkl" % (
            strat,
            start.strftime("%m-%d-%Y"),
            end.strftime("%m-%d-%Y")
        )
        os.system(cmd)

        return alloc_backtest('temp_alloc.pkl', startval)
    return fundsmatrix
예제 #2
0
def strat_backtest1(strat, start, end, num, diff, startval):
    """
    @summary: Back tests a strategy defined in a python script that takes
              in a start
    and end date along with a starting value a set number of times. 
    @param strat: filename of python script strategy
    @param start: starting date in a datetime object
    @param end: ending date in a datetime object
    @param num: number of tests to perform
    @param diff: offset in days of the tests
    @param startval: starting value of fund during back tests
    @return fundsmatrix: Datamatrix of fund values returned from each test
    @rtype datamatrix
    """
    fundsmatrix = []
    startdates = du.getNextNNYSEdays(start, num * diff, dt.timedelta(hours=16))
    enddates = du.getNextNNYSEdays(end, num * diff, dt.timedelta(hours=16))
    for i in range(0, num):
        os.system( 'python ' + strat + ' ' + startdates[i].strftime("%m-%d-%Y")\
                    + ' ' + enddates[i].strftime("%m-%d-%Y") + \
                    ' temp_alloc.pkl')

        return alloc_backtest('temp_alloc.pkl', startval)
    return fundsmatrix
예제 #3
0
tot_invest = float(sys.argv[1])
dataobj = da.DataAccess('Yahoo')
'''
symbols = dataobj.get_symbols_from_list("sp5002012")
starter = dt.datetime(2011,1,1)
ender = dt.datetime(2011,12,31)
timeday=dt.timedelta(hours=16)
timestamps = du.getNYSEdays(starter,ender,timeday)
close = dataobj.get_data(timestamps, symbols, "close")
'''
simulation = dict()



for count in csvdata:
	timestamp = du.getNextNNYSEdays( dt.datetime(count['year'],count['month'],count['day']),1,dt.timedelta(hours=16) )[0]
	if(firstts == None):
		firstts = timestamp
	if (secondts != None) and (secondts != timestamp) :
		temp = timestamp - dt.timedelta(days = 1)
		if(firstts <= temp):

			totaltime = du.getNYSEdays(firstts,temp, dt.timedelta(hours=16))
			sym = [k for k,v in simulation.iteritems()]
			data = dataobj.get_data(totaltime, sym, "close")
			totaltime = data.index
			data = data.values
			# Values Extracted from QSTK and then Modified as per the orders on the matching days from timestamp
			for ix in range(len(totaltime)):
				val = tot_invest
			for ix in range(len(sym)):