def testStockGroupWeightGenerationWithRiskAndReward(self): listSize = 5 stockList = [] for i in range(0,listSize): stockList.append(Stock(str(i),'test'+str(i), (0.2+ 0.01*i), (0.1 + 0.01*i))) assert(len(stockList)==listSize) StockCoRelation.resetMatrix() for i in range(0,listSize): for j in range(i,listSize): StockCoRelation.addCorelation(stockList[i].uid, stockList[j].uid, 0) stockGroup = StockGroup(stockList) w = WeightVectorGenerator(100, listSize, 0, 65-listSize*3) weightCount = 0 for i in range(0, 100): (weightClass, weightVector) = w.getWeightVectorAndClassTuple() while weightClass is not len(stockList): (weightClass, weightVector) = w.getWeightVectorAndClassTuple() weightCount += 1 stockGroup.setPlotBestRewardByRisk( (weightClass, weightVector) ) #print "%s" % (" \n".join([",".join([str(stock.uid), str(stock.reward), str(stock.risk)]) for stock in stockList])) #print "Weights created %s" % weightCount graphPlot = stockGroup.getPlotBestRewardByRisk() graphIndex = graphPlot.keys() graphIndex = sorted(graphIndex) for i in range(0, len(graphIndex)): print "%s %s" % (graphIndex[i], graphPlot[graphIndex[i]]) assert('01234'== stockGroup.getGroupId())
def testWeightVectorGeneration(self): w = WeightVectorGenerator(100, 5, 0, 60) for i in range(0,100): (weightClass, weightVector) = w.getWeightVectorAndClassTuple() #print "%d %s" % (weightClass, weightVector) assert(weightClass > 0 and weightClass <= 5) assert(len(weightVector) == weightClass and sum(weightVector) == 100)