Example #1
0
    # Set start and end dates
    t = map(int, sys.argv[1].split('-'))
    startday = dt.datetime(t[2], t[0], t[1])
    t = map(int, sys.argv[2].split('-'))
    endday = dt.datetime(t[2], t[0], t[1])

    # Get desired timestamps
    timeofday = dt.timedelta(hours=16)
    timestamps = du.getNYSEdays(startday, endday, timeofday)

    # Get the data from the data store
    dataobj = da.DataAccess('Norgate')
    historic = dataobj.get_data(timestamps, symbols, "close")

    # Setup the allocation table
    alloc_val = random.random()
    alloc = DataMatrix(index=[historic.index[0]],
                       data=[alloc_val],
                       columns=symbols)
    for date in range(1, len(historic.index)):
        alloc_val = 1  #random.random()
        alloc = alloc.append(
            DataMatrix(index=[historic.index[date]],
                       data=[alloc_val],
                       columns=[symbols[0]]))
    alloc['_CASH'] = 1 - alloc[symbols[0]]

    # Dump to pkl file
    output = open(sys.argv[3], "wb")
    cPickle.dump(alloc, output)
    print "Running One Stock strategy from "+sys.argv[1] +" to "+sys.argv[2]

    # Use google symbol
    symbols = list(['SPY'])

    # Set start and end dates
    t = map(int,sys.argv[1].split('-'))
    startday = dt.datetime(t[2],t[0],t[1])
    t = map(int,sys.argv[2].split('-'))
    endday = dt.datetime(t[2],t[0],t[1])

    # Get desired timestamps
    timeofday=dt.timedelta(hours=16)
    timestamps = du.getNYSEdays(startday,endday,timeofday)

    # Get the data from the data store
    dataobj = da.DataAccess('Norgate')
    historic = dataobj.get_data(timestamps, symbols, "close")

    # Setup the allocation table
    alloc_val= random.random()
    alloc=DataMatrix(index=[historic.index[0]], data=[alloc_val], columns=symbols)
    for date in range(1, len(historic.index)):
        alloc_val=1 #random.random()
        alloc=alloc.append(DataMatrix(index=[historic.index[date]], data=[alloc_val], columns=[symbols[0]]))
    alloc['_CASH']=1-alloc[symbols[0]]

    # Dump to pkl file
    output=open(sys.argv[3],"wb")
    cPickle.dump(alloc, output)