Beispiel #1
0
def MACDR1TestWithSET100(verbose=False):
    directory = './resources/stockdata/'
    ignoreList = ['BANPU', 'MAKRO', 'VGI', 'STPI']
    symbolList = [f.replace('.csv','') for f in os.listdir(directory) if f.endswith('.csv') and f.split('.')[0] not in ignoreList]
    
    resultList = pd.DataFrame({'success rate': None, 'profit rate': None}, index=symbolList)
    
    for symbol in symbolList:
        if verbose: print('testing ' + symbol + '...')
        pricesData = getPricesData(symbol=symbol)
        macd, signalLine = getMACDAndSignalLine(pricesData, 12, 26, 9)
        
        pricesData = pricesData[25:]
        macd = macd[25:]
        signalLine = signalLine[25:]
        successRate, profitRate = MACDR1Test(pricesData, macd, signalLine)

        getAllBuyPoints(pricesData, macd, signalLine)
        getAllSellPoints(pricesData, macd, signalLine)
        
        resultList['profit rate'][symbol] = profitRate
        resultList['success rate'][symbol] = successRate
        
    if verbose:
        import webbrowser
        f = open(os.getcwd() + '/temp.html', 'w')
        f.write('MACDR1 test with SET-100')
        f.write(resultList.to_html())
        f.close()
        webbrowser.open(os.getcwd() + '/temp.html', new=2)
        
    resultList = resultList.dropna()
    avgSuccessRate = resultList['success rate'].mean()
    avgProfitRate = resultList['profit rate'].mean()
    return avgSuccessRate, avgProfitRate
Beispiel #2
0
from macdtester.tradingtest_originalmacd import originalMACDTest, getAllBuyPoints as org_getAllBuyPoints, getAllSellPoints as org_getAllSellPoints, originalMACDTestWithSET100
from macdtester.modifiedsignalline import getModifiedSignalLine, getModifiedSignalLineWithK
from macdtester.plot import standardPlot, addMarkers, addModifiedSignalLine, addModifiedSignalLineWithK
from macdtester.tradingtest_macdr1 import MACDR1Test, getAllBuyPoints as macdr1_getAllBuyPoints, getAllSellPoints as macdr1_getAllSellPoints, MACDR1TestWithSET100
from macdtester.tradingtest_macdr2 import MACDR2Test, getAllBuyPoints as macdr2_getAllBuyPoints, getAllSellPoints as macdr2_getAllSellPoints, MACDR2TestWithSET100
from macdtester.tradingtest_modifiedsignalline import modifiedSignalLineTest, getAllBuyPoints as modsig_getAllBuyPoints, getAllSellPoints as modsig_getAllSellPoints, modifiedSignalLineTestWithSET100
from macdtester.tradingtest_modifiedsignalline_withK import modifiedSignalLineWithKtest, getAllBuyPoints as macdk_getAllBuyPoints, getAllSellPoints as macdk_getAllSellPoints, modifiedSignalLineWithKtestInSET100
from macdtester.tradingtest_modifiedsignalline_withK_1 import MACDK1Test, getAllBuyPoints as macdk1_getAllBuyPoints, getAllSellPoints as macdk1_getAllSellPoints, MACDK1TestWithSET100
from macdtester.tradingtest_modifiedsignalline_withK_2 import MACDK2Test, getAllBuyPoints as macdk2_getAllBuyPoints, getAllSellPoints as macdk2_getAllSellPoints, MACDK2TestWithSET100

## prepare data for a single data
print('preparing data...')
symbol = input("please input SET name: ")
if not symbol: raise Exception("Please Define SET")
symbol = symbol.upper()
pricesData = getPricesData(symbol)
macd, signalLine = getMACDAndSignalLine(pricesData, 12, 26,
                                        9)  #can change period later
modifiedSignalLine = getModifiedSignalLine(macd, signalLine, 1)
modifiedSignalLineWithK = getModifiedSignalLineWithK(macd, signalLine)

pricesData = pricesData[25:]
macd = macd[25:]
signalLine = signalLine[25:]
modifiedSignalLine = modifiedSignalLine[25:]
modifiedSignalLineWithK = modifiedSignalLineWithK[25:]

## modified signal line test with a single data
print('modified signal line with K test for ' + symbol)
successRate, profitRate = modifiedSignalLineWithKtest(pricesData, macd,
                                                      modifiedSignalLineWithK)