Пример #1
0
def computeWithPointsUsingStrategy(futureData, strategy):
    futureData = similarity.byFirst(futureData)
    money = 1
    stock = 0
    holdingStocks = False
    for i in range(0,len(futureData)):
        action = strategy(i, futureData[:i+1])
        if action == 0:
            continue
        elif action == -1:
            if not holdingStocks: continue
            #sell
            print('Sell ' + str(i))
            money += stock*futureData[i]
            stock = 0
            holdingStocks = False
        else: # action == 1
            if holdingStocks: continue
            #buy
            print('Buy ' + str(i))
            stock = money / futureData[i]
            money = 0
            holdingStocks = True

    # Sell remaining stock at end of period.
    if holdingStocks:
        money += stock*futureData[len(futureData)-1]

    return money
Пример #2
0
def largestReturn(data):
    data = similarity.byFirst(data)
    runningMin = data[0]
    minIndex = 0
    maxReturn = -1
    buyPoint = -1
    sellPoint = -1
    for i in range(0,len(data)):
        v = data[i]
        if (v < runningMin):
            runningMin = v
            minIndex = i
        if (v - runningMin  > maxReturn):
            maxReturn = v - runningMin
            buyPoint = minIndex
            sellPoint = i

    return(buyPoint, sellPoint)
Пример #3
0
def computeWithPoints(futureData, buySellPoints):
    futureData = similarity.byFirst(futureData)
    money = 1
    stock = 0
    holdingStocks = False
    for i in range(0,len(buySellPoints)):
        if holdingStocks:
            #sell
            money += stock*futureData[buySellPoints[i]]
            stock = 0
            holdingStocks = False
        else:
            #buy
            stock = money / futureData[buySellPoints[i]]
            money = 0
            holdingStocks = True

    # Sell remaining stock at end of period.
    if holdingStocks:
        money += stock*futureData[len(futureData)-1]

    return money