コード例 #1
0
def updateAlgStats(step,alphaAlg=1,omegaAlg=3540):
    algstats = getAlgStats(alphaAlg,omegaAlg)
    desires = getDesires(step,alphaAlg,omegaAlg)
    alglist = {}
    for alg in algstats:
        desireKey = meTools.buildDesireKey(step,alg)
        if desires[desireKey] is not None:
            tradeCash, PandL, position = mergePosition(eval(desires[desireKey].desire),eval(algstats[alg].Positions))
            cash = tradeCash + algstats[alg].Cash
            if cash > 0:
                cashdelta = eval(decompress(algstats[alg].CashDelta))  # Get CashDelta collection
                cashdelta.appendleft({'value': tradeCash,
                                      'PandL': PandL,
                                      'step':  step})
                # Must check len() before pop() since not padding cashdelta.
                if len(cashdelta) > 800:
                    cashdelta.pop()
                
                algstats[alg].Cash = cash
                algstats[alg].Positions = repr(position)
                algstats[alg].PandL = PandL
                algstats[alg].CashDelta = compress(repr(cashdelta),9)
                alglist[alg] = algstats[alg]
        else:
            pass
    meTools.memPut_multi(meSchema.algStats,alglist)
コード例 #2
0
def putEm(step):
    positions = getPositions("*****@*****.**")
    meDatetime = datetime.now()
    entityDict = {}
    symbols = ["GOOG", "HBC", "INTC", "CME"]
    stckIDs = meTools.getStckIDs(symbols)
    for pos in positions:
        symbol = pos.ticker_id.split(":")[1]
        quote = float(str(pos.position_data.market_value).replace(" USD", ""))
        if symbol in symbols:
            stckID = stckIDs[symbol]
            meStck = meSchema.stck(key_name=str(stckID) + "_" + str(step), ID=stckID, step=step, quote=quote)
            entityDict[meStck.key().name()] = meStck

    meStepDate = meSchema.stepDate(key_name=str(step), step=step, date=meDatetime)
    entityDict[meStepDate.key().name()] = meStepDate

    wait = 0.1
    while True:
        try:
            meTools.memPut_multi(entityDict)
            break
        except db.Timeout:
            from time import sleep

            sleep(timeout)
            wait *= 2
コード例 #3
0
def startSim(namespace, unique, globalStop, initialStop, stepRange, goNext):
    from google.appengine.api.datastore import Key
    
    JobID = meTools.buildJobID(namespace, unique, globalStop, initialStop, stepRange)

    persistStops = meSchema.WorkQueue(key_name = JobID, globalStop = globalStop, initialStop = initialStop)
    meTools.memPut_multi({persistStops.key().name() : persistStops}, priority = 1)
    
    if not globalStop >= initialStop:
        raise(BaseException('globalStop: %s is not >= lastStopStep: %s' % (globalStop, initialStop)))

    lastDesire = meSchema.desire.all(keys_only = True).filter('__key__ <', Key.from_path('desire','1000000_0000_00')).order('-__key__').get()
    if lastDesire:
        lastDesireStop = int(lastDesire.name().split('_')[0])
    else:
        lastDesireStop = 1
    desireFunc.primeDesireCache(lastDesireStop)
    for step in range(lastDesireStop, globalStop + 1):
        desireFunc.doDesires(step)

    if goNext == 'true':
        doNext(JobID, 'weeklyDesires','')
コード例 #4
0
def initializeAlgStats():
    meList = []
    meDict = {}

    cashdelta = deque()
    count = 1000
    cursor = None
    while count == 1000:
        query = meSchema.meAlg.all()
        if cursor is not None:
            query.with_cursor(cursor)
        algs = query.fetch(1000)
        for alg in algs:
            key = alg.key().name()
            algstat = meSchema.algStats(key_name  = key,
                                        Cash      = alg.Cash,
                                        CashDelta = compress(repr(cashdelta),9),
                                        PandL     = 0.0,
                                        Positions = repr({}))
            meDict[key] = algstat
        cursor = query.cursor()
        count = len(algs)
    meTools.memPut_multi(meSchema.algStats,meDict)