Ejemplo n.º 1
0
def processLiveAlgStepRange(start, stop, stepRange, algKeyFilter, namespace, JobID, callback, totalBatches, taskname):
    namespace_manager.set_namespace(namespace)
    currentStep = start
    stopStepList = buildStopStepList(start, stop)
    liveAlgInfo = getLiveAlgInfo(stop, stepRange, algKeyFilter)
    for i in range(len(stopStepList)):
        lastBackTestStop = stopStepList[i]
        bestAlgs = getBestAlgs(lastBackTestStop, liveAlgInfo)
        if i < len(stopStepList) - 1:
            lastStep = stopStepList[i + 1]
        else:
            lastStep = stop
        # Must deal with case where stop step is final step in stopStepList.
        if currentStep < lastStep:
            liveAlgInfo = processStepRangeDesires(currentStep, lastStep, bestAlgs, liveAlgInfo)
            liveAlgInfo = getCurrentReturn(liveAlgInfo, lastStep)
            currentStep = lastStep + 1
    putList = []
    for liveAlgKey in liveAlgInfo:
        putList.append(liveAlgInfo[liveAlgKey])
    meTools.retryPut(putList)
    if callback:
        meTools.taskAdd(
            "callback-" + taskname,
            callback,
            "default",
            0.5,
            JobID=JobID,
            taskname=taskname,
            totalBatches=totalBatches,
            jobtype="callback",
            stepType="weeklyLiveAlgs",
            model="",
        )
Ejemplo n.º 2
0
def initializeLiveAlgs(initialStopStep, stepRange, Cash):
    """
    Removed FTLo types.  Adds unnecessary clutter.
    """
    global FTLtype
    global NRtype

    techniques = []
    for FTL in FTLtype:
        for NR in NRtype:
            techniques.append(FTL + "-" + NR)

    liveAlgs = []
    for technique in techniques:
        keyname = str(initialStopStep).rjust(7, "0") + "-" + str(stepRange).rjust(7, "0") + "-" + technique
        liveAlg = meSchema.liveAlg(
            key_name=keyname,
            stopStep=initialStopStep,
            startStep=initialStopStep - stepRange,
            stepRange=stepRange,
            lastBuy=0,
            lastSell=0,
            percentReturn=0.0,
            Positions=repr({}),
            PosVal=0.0,
            PandL=0.0,
            CashDelta=repr(deque([])),
            Cash=Cash,
            numTrades=0,
            history=repr(deque([])),
            technique=technique,
        )
        liveAlgs.append(liveAlg)
    meTools.retryPut(liveAlgs)
def doCallback(handler):
    JobID = handler.request.get('JobID')
    stepType = handler.request.get('stepType')
    taskname = handler.request.get('taskname')
    totalBatches = int(handler.request.get('totalBatches'))
    model = handler.request.get('model')

    entity = meSchema.WorkQueue(key_name = taskname,
                                WorkID = stepType + JobID)
    meTools.retryPut(entity)
    batchCount = meSchema.WorkQueue.all(keys_only=True).filter('WorkID =', stepType + JobID).count()
    if batchCount == totalBatches:
        doNext(JobID, stepType, model)