def makeAlgs(): TradeSize = [0.25] # Changing to use tradeCue combinations. # Only 60 at the moment but this allows for up to 1000. fetchCues = meSchema.tradeCue.all().fetch(1000) TradeCues = [] for tradecue in fetchCues: TradeCues.append(tradecue.key().name()) Cash = [100000.0] id = 0 meList = [] count = 0 for buyCue in TradeCues: for sellCue in TradeCues: if sellCue != buyCue: for size in TradeSize: for meCash in Cash: id += 1 key_name = meSchema.buildAlgKey(id) alg = meSchema.meAlg(key_name = key_name, TradeSize = size, BuyCue = buyCue, SellCue = sellCue, Cash = meCash) meList.append(alg) meSchema.batchPut(meList)
def post(self): startDayIndex = int(self.request.get('startDayIndex')) Symbol = str(self.request.get('Symbol')) stckID = meSchema.getStckID(Symbol) csvFile = Symbol + '_01-2005_11-2010.csv' dailyQuotes = list(csv.reader(open(csvFile))) dailyQuotes.reverse() # Index 0 is for step 1000001 to 1000080 # Index 1 is for step 1000081 to 1000160 # Index N is for step N*80 + 1 to (N+1)*80 # plus 1000000 putList = [] for N in range(len(dailyQuotes)): dailyOpenStep = 1000000 + N*80 + 1 dailyCloseStep = 1000000 + N*80 + 80 '''Must draw random steps for High and Low.''' daySteps = [step for step in range(dailyOpenStep+1,dailyCloseStep)] highLow = sample(daySteps, 2) dailyHighStep = highLow[0] dailyLowStep = highLow[1] ''' Set Quote Values ''' OpenQuote = dailyQuotes[N][1] HighQuote = dailyQuotes[N][2] LowQuote = dailyQuotes[N][3] CloseQuote = dailyQuotes[N][4] ''' Create stck Entities for stckID Quotes''' openStck = meSchema.stck(key_name=str(stckID) + '_' + str(dailyOpenStep), ID = stckID, quote = float(OpenQuote), step = dailyOpenStep) highStck = meSchema.stck(key_name=str(stckID) + '_' + str(dailyHighStep), ID = stckID, quote = float(HighQuote), step = dailyHighStep) lowStck = meSchema.stck(key_name=str(stckID) + '_' + str(dailyLowStep), ID = stckID, quote = float(LowQuote), step = dailyLowStep) closeStck = meSchema.stck(key_name=str(stckID) + '_' + str(dailyCloseStep), ID = stckID, quote = float(CloseQuote), step = dailyCloseStep) putList.extend([openStck,highStck,lowStck,closeStck]) meSchema.batchPut(putList)
def post(self): ''' Starting at Step 1000001 and iterating over each group of 80, Get all stck quotes for range and fill in gaps. ''' startStep = int(self.request.get('startStep')) if startStep < 1000001: raise Exception('Must be doing random fills above step 1000000!') endStep = startStep + 79 stckDict,stepSeq = getStckDictStepSeq(startStep,endStep) ''' for stckID in stckDict, must fill in gaps between stepSeq values. ''' entityList = buildEntityList(stckDict, stepSeq) meSchema.batchPut(entityList)
def makeTradeCues(): TimeDelta = [1,80,160,240,320,400] QuoteDelta = [-0.05,-0.03,-0.02,-0.015,-0.01,-0.0075,0.0075,0.01,0.015,0.02,0.03,0.05] cueID = 0 count = 0 meList = [] for tdelta in TimeDelta: for qdelta in QuoteDelta: cueID += 1 key_name = meSchema.buildTradeCueKey(cueID) tradeCue = meSchema.tradeCue(key_name = key_name, QuoteDelta = qdelta, TimeDelta = tdelta) meList.append(tradeCue) meSchema.batchPut(meList)
def updateNs(stopStep,startStep, pReturnFilter, name, i, backTests): N = [1,2] Nkeys = {} for n in N: nStop = stopStep - n*400 nStart = startStep - n*400 thisN = meSchema.backTestResult.all(keys_only = True).filter("stopStep =", nStop).filter("startStep =", nStart).filter(pReturnFilter,0.0).order("-percentReturn") memKey = str(dumps(thisN).__hash__()) algsN = memcache.get(memKey) if algsN is None: fullAlgKeys = thisN.fetch(4000) algsN = [algkey.name().split('_')[0] for algkey in fullAlgKeys] memcache.set(memKey, algsN) Nkeys[n] = algsN for backTest in backTests: algKey = backTest.key().name().split('_')[0] backTest.N = 1 if algKey in set(Nkeys[1]) - set(Nkeys[2]): backTest.N = 2 elif algKey in set(Nkeys[1]) & set(Nkeys[2]): backTest.N = 3 meSchema.batchPut(backTests)