예제 #1
0
    rschLib.drawPNL(dtesWithTag,
                    pnlWithTag,
                    dtes,
                    strategy_name,
                    toDatabase='yes',
                    dateStart=dtesPnlAggr[0],
                    pnlType=tagName)
    rschLib.drawPNL(dtesWithTag,
                    pnlWithTag,
                    dtes,
                    strategy_name + '+' + tagNamesEn[i],
                    toDatabase='yes',
                    dateStart=dtesPnlAggr[0],
                    pnlType='pnl')

#analysis of number of trades vs performance
importlib.reload(rschLib)
rschLib.pnlVsNumtrades(pnlAggr, numTrades, strategy_name, toDatabase='yes')

# In[44]:

db.taskAddTagToStrategy.update_one({'_id': q['_id']}, {
    '$set': {
        'lastUpdate':
        str(datetime.datetime.now().year) +
        str(datetime.datetime.now().month) + str(datetime.datetime.now().day)
    }
})

# In[ ]:
예제 #2
0
def analyzeStrategy(strategy_name, offStart, dtes, name, tkrs):
    timeAsFloat, timeLabels, maxM, dayOff, dayTimeAsFloat = rschLib.getTimeLabels(
        maxD)
    R = open_mtx[:, 1:] / close_mtx[:, :-1] - 1  #使用收盘到开盘的回报率来修正分红和拆股
    R = np.hstack((np.zeros((R.shape[0], 1)), R))
    tradesUsed, r_withnan = rschLib.getTradesFast(strategy_name, name, tkrs,
                                                  dtes, maxD, dayTimeAsFloat,
                                                  R)
    # get trade samples by good/bad trades
    tradeArea = [inTime, otTime]
    idxTradable = np.isfinite(r_withnan[:, tradeArea[0]])
    r = r_withnan.copy()
    r[np.isfinite(r) == False] = 0
    result = rschLib.getTradeAnalysisSampleGroups(r, idxTradable, tradeArea)

    # draw price change
    rschLib.drawPriceChange(r[idxTradable, :],
                            strategy_name,
                            timeLabels=timeLabels,
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rGood10'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='盈利前10%交易',
                            tp=tradeArea)
    #rschLib.drawPriceChange(result['rGood20'], strategy_name, timeLabels=timeLabels, title='盈利前20%交易', tp=tradeArea)
    rschLib.drawPriceChange(result['rGood30'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='盈利前30%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rBad10'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='亏损前10%交易',
                            tp=tradeArea)
    #rschLib.drawPriceChange(result['rBad20'], strategy_name, timeLabels=timeLabels, title='亏损前20%交易',  tp=tradeArea)
    rschLib.drawPriceChange(result['rBad30'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='亏损前30%交易',
                            tp=tradeArea)

    # analyze tags
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood10'], result['idxGood10'], '盈利前10%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood20'], result['idxGood20'], '盈利前20%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood30'], result['idxGood30'], '盈利前30%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad10'], result['idxBad10'], '亏损前10%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad20'], result['idxBad20'], '亏损前20%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad30'], result['idxBad30'], '亏损前30%交易',strategy_name, dtes, tkrs, offStart)

    #get tag names
    tnames, tagNamesEn, t2 = rschLib.getTagNames()
    idxOverLapTagList = rschLib.analyzeTradeTags(tradesUsed, r,
                                                 list(range(len(tradesUsed))),
                                                 '所有交易', strategy_name, dtes,
                                                 tkrs, offStart,
                                                 "d:\\pklWeeklyUpdate\\")

    #draw pnl and tag pnl
    importlib.reload(rschLib)
    [dtesByTrade, pnlByTrade] = rschLib.getPnlFast(r,
                                                   dtes,
                                                   tkrs,
                                                   name,
                                                   tradesUsed,
                                                   inTime,
                                                   otTime,
                                                   dayOff,
                                                   timeAsFloat,
                                                   toDatabase='yes',
                                                   strategy_name=strategy_name)
    [dtesPnlAggr, pnlAggr,
     numTrades] = rschLib.aggregatePnlAndDtes(dtesByTrade, pnlByTrade)
    rschLib.drawPNL(dtesPnlAggr,
                    pnlAggr,
                    dtes,
                    strategy_name,
                    showFigure='no',
                    toDatabase='yes')
    for i in range(len(tnames)):
        tagName = tnames[i]
        [dtesWithTag, pnlWithTag,
         n] = rschLib.aggregatePnlAndDtes(dtesByTrade[idxOverLapTagList[i]],
                                          pnlByTrade[idxOverLapTagList[i]])
        rschLib.drawPNL(dtesWithTag,
                        pnlWithTag,
                        dtes,
                        strategy_name,
                        showFigure='no',
                        toDatabase='yes',
                        dateStart=dtesPnlAggr[0],
                        pnlType=tagName)
        rschLib.drawPNL(dtesWithTag,
                        pnlWithTag,
                        dtes,
                        strategy_name + '+' + tagNamesEn[i],
                        showFigure='no',
                        toDatabase='yes',
                        dateStart=dtesPnlAggr[0],
                        pnlType='pnl')

    #analysis of number of trades vs performance
    importlib.reload(rschLib)
    rschLib.pnlVsNumtrades(pnlAggr, numTrades, strategy_name, toDatabase='yes')
    rschLib.saveOffStart(strategy_name, offStart)
예제 #3
0
def analyzeStrategy(strategy_name, offStart, dtes, name, tkrs):
    timeAsFloat, timeLabels, maxM, dayOff = rschLib.getTimeLabels(maxD)
    trades, tradesUsed, Po, r = rschLib.getTradesWithPklCache(
        strategy_name, name, tkrs, dtes, maxD, maxM)
    # get trade samples by good/bad trades
    tradeArea = [inTime, otTime]
    result = rschLib.getTradeAnalysisSampleGroups(r, tradeArea)

    # draw price change
    rschLib.drawPriceChange(r,
                            strategy_name,
                            timeLabels=timeLabels,
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rGood10'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='盈利前10%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rGood20'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='盈利前20%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rGood30'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='盈利前30%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rBad10'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='亏损前10%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rBad20'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='亏损前20%交易',
                            tp=tradeArea)
    rschLib.drawPriceChange(result['rBad30'],
                            strategy_name,
                            timeLabels=timeLabels,
                            title='亏损前30%交易',
                            tp=tradeArea)
    # analyze tags
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood10'], result['idxGood10'], '盈利前10%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood20'], result['idxGood20'], '盈利前20%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rGood30'], result['idxGood30'], '盈利前30%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad10'], result['idxBad10'], '亏损前10%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad20'], result['idxBad20'], '亏损前20%交易',strategy_name, dtes, tkrs, offStart)
    #rschLib.analyzeTradeTags(tradesUsed, result['rBad30'], result['idxBad30'], '亏损前30%交易',strategy_name, dtes, tkrs, offStart)

    #get tag names
    tnames, tagNamesEn, t2 = rschLib.getTagNames()
    idxOverLapTagList = rschLib.analyzeTradeTags(tradesUsed, r,
                                                 list(range(len(tradesUsed))),
                                                 '所有交易', strategy_name, dtes,
                                                 tkrs, offStart)

    #draw pnl and tag pnl
    importlib.reload(rschLib)
    [dtesByTrade, pnlByTrade] = rschLib.getPnl(dtes,
                                               tkrs,
                                               name,
                                               tradesUsed,
                                               inTime,
                                               otTime,
                                               dayOff,
                                               timeAsFloat,
                                               toDatabase='yes',
                                               strategy_name=strategy_name)
    [dtesPnlAggr, pnlAggr,
     numTrades] = rschLib.aggregatePnlAndDtes(dtesByTrade, pnlByTrade)
    rschLib.drawPNL(dtesPnlAggr,
                    pnlAggr,
                    dtes,
                    strategy_name,
                    toDatabase='yes')
    for i in range(len(tnames)):
        tagName = tnames[i]
        [dtesWithTag, pnlWithTag,
         n] = rschLib.aggregatePnlAndDtes(dtesByTrade[idxOverLapTagList[i]],
                                          pnlByTrade[idxOverLapTagList[i]])
        rschLib.drawPNL(dtesWithTag,
                        pnlWithTag,
                        dtes,
                        strategy_name,
                        toDatabase='yes',
                        dateStart=dtesPnlAggr[0],
                        pnlType=tagName)
        rschLib.drawPNL(dtesWithTag,
                        pnlWithTag,
                        dtes,
                        strategy_name + '+' + tagNamesEn[i],
                        toDatabase='yes',
                        dateStart=dtesPnlAggr[0],
                        pnlType='pnl')

    #analysis of number of trades vs performance
    importlib.reload(rschLib)
    rschLib.pnlVsNumtrades(pnlAggr, numTrades, strategy_name, toDatabase='yes')
    rschLib.saveOffStart(strategy_name, offStart)
예제 #4
0
rschLib.analyzeTradeTags(trades, result['rBad10'], result['idxBad10'],
                         '亏损前10%交易', strategy_name, dtes, name, offStart)
rschLib.analyzeTradeTags(trades, result['rBad20'], result['idxBad20'],
                         '亏损前20%交易', strategy_name, dtes, name, offStart)
rschLib.analyzeTradeTags(trades, result['rBad30'], result['idxBad30'],
                         '亏损前30%交易', strategy_name, dtes, name, offStart)

# In[8]:

importlib.reload(rschLib)
[dtesPnl, pnl, numTrades] = rschLib.getPnl(dtes,
                                           tkrs,
                                           name,
                                           trades,
                                           inTime,
                                           otTime,
                                           dayOff,
                                           timeAsFloat,
                                           toDatabase='yes')

# In[ ]:

importlib.reload(rschLib)
rschLib.pnlVsNumtrades(pnl, numTrades)

# In[ ]:

# In[ ]:

# In[ ]:
예제 #5
0
rschLib.analyzeTradeTags(trades, result['rBad20'], result['idxBad20'], '亏损前20%交易',strategy_name, dtes, name, offStart)
rschLib.analyzeTradeTags(trades, result['rBad30'], result['idxBad30'], '亏损前30%交易',strategy_name, dtes, name, offStart)


# In[ ]:


importlib.reload(rschLib)
[dtesPnl,pnl, numTrades]=rschLib.getPnl(dtes,tkrs, name, trades, inTime, otTime, dayOff, timeAsFloat, toDatabase='yes')


# In[ ]:


importlib.reload(rschLib)
rschLib.pnlVsNumtrades(pnl, numTrades, strategy_name)


# In[ ]:





# In[ ]:





# In[ ]: