def getModifiedSignalLine(macd, signalLine, K):
    periods = getTradingPeriods(macd, signalLine)
    modifiedSignalLine = pd.Series(float('nan'), index=signalLine.index)

    for period in periods:
        avmin = getAvailablyMinimumPointsInAPeriod(macd, signalLine, period)
        avmax = getAvailablyMaximumPointsInAPeriod(macd, signalLine, period)
        dmin = getMinimumCertainties(macd, signalLine, period)
        dmax = getMaximumCertainties(macd, signalLine, period)
        upCrossingPoint = None
        for t in period:
            if upCrossingPoint is None and isAnUpCrossingPoint(
                    macd, signalLine, t):
                upCrossingPoint = t

            if upCrossingPoint is None:
                hMinimum = macd[avmin[t]] - signalLine[avmin[t]]
                modifiedSignalLine[t] = signalLine[t] + hMinimum * (dmin[t]**K)
            elif t == period[-1]:
                modifiedSignalLine[t] = signalLine[t]
            else:
                hMaximum = macd[avmax[t]] - signalLine[avmax[t]]
                modifiedSignalLine[t] = signalLine[t] + hMaximum * (dmax[t]**K)

    return modifiedSignalLine
def getAllSellPoints(pricesData, macd, modifiedSignalLineWithK):
    periods = getTradingPeriods(macd, modifiedSignalLineWithK)
    allSellPoints = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(pricesData, macd, modifiedSignalLineWithK, period)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allSellPoints.append(trade.sellPoint)
    print('total sell' ,len(allSellPoints))
    return allSellPoints
Beispiel #3
0
def getAllSellPoints(pricesData, macd, modifiedSignalLineWithK):
    periods = getTradingPeriods(macd, modifiedSignalLineWithK)
    allSellPoints = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(pricesData, macd, modifiedSignalLineWithK, period)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allSellPoints.append(trade.sellPoint)
    print('total sell' ,len(allSellPoints))
    return allSellPoints
def getAllBuyPoints(pricesData, macd, signalLine):
    periods = getTradingPeriods(macd, signalLine)
    allBuyPoints = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(macd, signalLine, period)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allBuyPoints.append(trade.buyPoint)
    print('total buy', len(allBuyPoints))
    #print allBuyPoints
    return allBuyPoints
def getAllBuyPoints(pricesData, macd, signalLine):
    periods = getTradingPeriods(macd, signalLine)
    allBuyPoints = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(macd, signalLine, period)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allBuyPoints.append(trade.buyPoint)
    print('total buy' ,len(allBuyPoints))
    #print allBuyPoints
    return allBuyPoints
def getAllSellPoints(pricesData, macd, signalLine, modifiedSignalLine):
    periods = getTradingPeriods(macd, signalLine)
    allSellPoints = []
    for period in periods:
        upPoint = getUpCrossingPointInAPeriod(macd, signalLine, period)
        totalTrade = getTotalTradesInAPeriod(macd, modifiedSignalLine, period, upPoint)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allSellPoints.append(trade.sellPoint)
    print('total sell' ,len(allSellPoints))
    return allSellPoints
def getAllSellPoints(pricesData, macd, signalLine, modifiedSignalLine):
    periods = getTradingPeriods(macd, signalLine)
    allSellPoints = []
    for period in periods:
        upPoint = getUpCrossingPointInAPeriod(macd, signalLine, period)
        totalTrade = getTotalTradesInAPeriod(macd, modifiedSignalLine, period,
                                             upPoint)
        if totalTrade is not None:
            for trade in totalTrade.tradeList:
                allSellPoints.append(trade.sellPoint)
    print('total sell', len(allSellPoints))
    return allSellPoints
def MACDK1Test(pricesData, macd, modifiedSignalLineWithK):
    periods = getTradingPeriods(macd, modifiedSignalLineWithK)
    profitRateList = []
    successList = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(pricesData, macd, modifiedSignalLineWithK, period)
        if totalTrade is not None:
            profitRate = totalTrade.getProfitRate(pricesData)
            profitRateList.append(profitRate)
            if profitRate > 0:
                successList.append(1)
            else:
                successList.append(0)
    
    if len(profitRateList) > 0:
        return np.mean(successList), np.mean(profitRateList)
    else:
        return None, None
def originalMACDTest(pricesData, macd, signalLine):
    periods = getTradingPeriods(macd, signalLine)
    profitRateList = []
    successList = []
    for period in periods:
        totalTrade = getTotalTradesInAPeriod(macd, signalLine, period)
        if totalTrade is not None:
            profitRate = totalTrade.getProfitRate(pricesData)
            profitRateList.append(profitRate)
            if profitRate > 0:
                successList.append(1)
            else:
                successList.append(0)

    if len(profitRateList) > 0:
        return np.mean(successList), np.mean(profitRateList)
    else:
        return None, None
def modifiedSignalLineTest(pricesData, macd, signalLine, modifiedSignalLine):
    periods = getTradingPeriods(macd, signalLine)
    profitRateList = []
    successList = []
    for period in periods:
        upPoint = getUpCrossingPointInAPeriod(macd, signalLine, period)
        totalTrade = getTotalTradesInAPeriod(macd, modifiedSignalLine, period, upPoint)
        if totalTrade is not None:
            profitRate = totalTrade.getProfitRate(pricesData)
            profitRateList.append(profitRate)
            if profitRate > 0:
                successList.append(1)
            else:
                successList.append(0)
    
    if len(profitRateList) > 0:
        return np.mean(successList), np.mean(profitRateList)
    else:
        return None, None
def modifiedSignalLineTest(pricesData, macd, signalLine, modifiedSignalLine):
    periods = getTradingPeriods(macd, signalLine)
    profitRateList = []
    successList = []
    for period in periods:
        upPoint = getUpCrossingPointInAPeriod(macd, signalLine, period)
        totalTrade = getTotalTradesInAPeriod(macd, modifiedSignalLine, period,
                                             upPoint)
        if totalTrade is not None:
            profitRate = totalTrade.getProfitRate(pricesData)
            profitRateList.append(profitRate)
            if profitRate > 0:
                successList.append(1)
            else:
                successList.append(0)

    if len(profitRateList) > 0:
        return np.mean(successList), np.mean(profitRateList)
    else:
        return None, None
def getModifiedSignalLine(macd, signalLine, K):
    periods = getTradingPeriods(macd, signalLine)
    modifiedSignalLine = pd.Series(float('nan'), index=signalLine.index)

    for period in periods:
        avmin = getAvailablyMinimumPointsInAPeriod(macd, signalLine, period)
        avmax = getAvailablyMaximumPointsInAPeriod(macd, signalLine, period)    
        dmin = getMinimumCertainties(macd, signalLine, period)
        dmax = getMaximumCertainties(macd, signalLine, period)
        upCrossingPoint = None
        for t in period:
            if upCrossingPoint is None and isAnUpCrossingPoint(macd, signalLine, t):
                upCrossingPoint = t
                
            if upCrossingPoint is None:
                hMinimum = macd[avmin[t]] - signalLine[avmin[t]]
                modifiedSignalLine[t] = signalLine[t] + hMinimum*(dmin[t]**K)
            elif t == period[-1]:
                modifiedSignalLine[t] = signalLine[t]
            else:
                hMaximum = macd[avmax[t]] - signalLine[avmax[t]]
                modifiedSignalLine[t] = signalLine[t] + hMaximum*(dmax[t]**K)
      
    return modifiedSignalLine