''' Created on Jul 25, 2014 @author: Brett Paufler Copyright Brett Paufler ''' import pickle from lotto_class import prizeLevel from lotto_class import lotteryGame import matplotlib.pyplot as plt import numpy #import lotto_benchmarks as lotto def loadData(): '''loads the 01-lottoPickleData.txt file made by the htmlDataExtracton module ''' with open(r'.\lottery\01-lottoPickleData.txt', 'rb') as f: data = pickle.load(f) return data def pbOptions(): '''returns list of lotteryGame options various powerBall prize equalization options ''' gD = [] for n in range(5): gD.append(loadData()[0]) gD[0].name = "powerBall\nBase Data" gD[1].name = "powerBall\nHigh Jackpot" del gD[1].prizes[1] #gD[1].printLotteryGameData() #print "\n\n\n3" gD[2].name = "powerBall\nHigh Jackpot\nLow Reinvested" gD[2].price = float(gD[2].price) - float(gD[2].prizes[1].prize) / (gD[2].prizes[1].odds * gD[2].price) del gD[2].prizes[1] #gD[3].printLotteryGameData() gD[3].name = "powerBall\nLow Jackpot" del gD[3].prizes[0] #gD[2].printLotteryGameData() #print "\n\n\n4" gD[4].name = "powerBall\nLow Jackpot\nHigh Reinvested" gD[4].price -= float(gD[4].prizes[0].prize) / (gD[4].prizes[0].odds * gD[4].price) del gD[4].prizes[0] #gD[4].printLotteryGameData() return gD def powerBallPrizeChart(gD): '''Analysis of Various superBall options Prize Chart ''' legend = [] prize = [] for g in gD: legendName = "%s" % g.name legend.append(legendName) prize.append(g.prizes[0].prize) #For the Unaltered Data, combining Both PRizes prize[0] = gD[0].prizes[0].prize + gD[0].prizes[1].prize graphTitle = "Power Ball\nPrize Levels for Various Break-Out Options\n(7-11-14 Data)" yLabel = "Top Prizes in Tens of Millions of Dollars\n(It's a lot of money no matter how you count it!!!)" n = len(legend) ind = numpy.arange(0.5,n,1.0) width = 0.90 plt.rcParams['figure.figsize'] = 50,25 fig, ax = plt.subplots() plt.bar(range(n), prize, width, color="b") ax.set_title(graphTitle, fontsize=50) ax.set_xticklabels((legend), fontsize=36) plt.xlabel("PowerBall Prize Break-Out Options", fontsize=50) ax.set_ylabel(yLabel, fontsize=40) ax.set_xticks(ind) plt.ylim(0, 50000000) sN = "./lottery/powerBallOptionsPrizeChart.png" print "Working On %s" % sN plt.savefig(sN) #plt.show() print "FINISHED %s" % sN def rpdReinvestData(gameData, cutOff): '''returns a stacked list of the 'Return per Dollar' values for every prize level in a lotteryGame over cutOff value prizes at or below cutOff are summed together (sumV) and returned as one value ''' rpdList = [] lowRPD = 0.0 for pL in gameData.prizes: print "first Loop" if pL.prize < cutOff: lowRPD += float(pL.prize) / (pL.odds * gameData.price) print "lowRPD += %.10f at Prize: %d for cutOff %d" % (lowRPD, pL.prize, cutOff) for pL in gameData.prizes: print "second Loop" if pL.prize >= cutOff: iRPD = float(pL.prize) / (pL.odds * gameData.price) multi = lowRPD t = iRPD while multi * iRPD > 0.0000000001: multi = multi * lowRPD t += multi * iRPD print "iRPD %.8f multi %.8f t %.8f" %(iRPD, multi, t) rpdList.append(t) return rpdList def powerBallRPDOptions(gD): ''' Analysis of the various PowerBall options using the predefined RPD chart methodology ''' legend = [] rpd = [] for g in gD: rpd.append(sum(rpdReinvestData(g, 1000000))) legend.append(g.name) graphTitle = "Power Ball\nReturn per Dollar for Various Break-Out Options\n(7-11-14 Data)" L1 = "\n(For the Raw Data, both prizes are stacked)" yLabel = "Return per Dollar for the Multi-Million Prize%s" % (L1) n = len(rpd) ind = numpy.arange(0.5,n,1.0) width = 0.90 plt.rcParams['figure.figsize'] = 50,25 fig, ax = plt.subplots() plt.bar(range(n), rpd, width, color="g") ax.set_title(graphTitle, fontsize=50) ax.set_xticklabels((legend), fontsize=35) plt.xlabel("PowerBall Prize Break-Out Options", fontsize=50) ax.set_ylabel(yLabel, fontsize=30) ax.set_xticks(ind) plt.ylim(0, 1.0) sN = "./lottery/powerBall-RPD-Options.png" print "Working On %s" % sN plt.savefig(sN) #plt.show() print "FINISHED %s" % sN def oddsAboveTarget(g, target=100000): '''returns the cumulative odds for target price and above per DOLLAR (so a $2 ticket's true odds is 2x return value) g = a lotteryGame dataObject target = prize level desired (or better) returns cumulative odds above target ''' print "\noddsAboveTarget started" delta = 0.000000000000001 underOdds = [] prizes = [] for p in g.prizes: pO = p.returnPrizeOdds() prizes.append(pO) print pO prizes.sort() print prizes print pO for prize, odds in prizes: a = 0.00 print "prize: %d \t odds: %d" % (prize, odds) if prize < target: chance = 1.00 / odds #print "prizeOdds: %.15f" % chance a = chance * prize / g.price dT = chance c = 1 print "dT loop dT %.15f Count %d AccumulatedrOdds: %.15f" % (dT, c, a) while dT > delta: c += 1 dT = chance ** c a += dT * prize / g.price print "dT loop dT %.15f Count %d AccumulatedrOdds: %.15f" % (dT, c, a) print "A:ODDS = %.15f" % a underOdds.append(a) print "WINNING PRIZE LEVELS FOLLOW" a = 1 + sum(underOdds) print "1 + sum(stacked) = %.15f" % a overOdds = [] for prize, odds in prizes: z = 0.00 if prize >= target: chance = 1.00 / odds / g.price z += a * chance print "Z+=%.15f after %d prize at raw chance of %.15f a=%.15f" % (z, prize, chance, a) overOdds.append(z) print "underOdds %.15f %s" % (sum(underOdds), str(underOdds)) print "overOdds %.15f %s" % (sum(overOdds), str(overOdds)) return overOdds def powerBallchanceOptions(gD): ''' Analysis of the powerBall Options, using a Chance Chart ''' legend = [] chance = [] for g in gD: #TODO WRONG IN HERE '''Getting a List of Odds Need to convert to a single Chance ''' chance.append(sum(oddsAboveTarget(g,1000000))) legend.append(g.name) print chance graphTitle = "Power Ball\nChance to Win for Various Break-Out Options\n(7-11-14 Data)" yLabel = "Cumulative Chance of Winning\nLower Prize Amounts Reinvested" n = len(chance) ind = numpy.arange(0.5,n,1.0) width = 0.95 plt.rcParams['figure.figsize'] = 50,25 fig, ax = plt.subplots() plt.bar(range(n), chance, width, color="r") ax.set_title(graphTitle, fontsize=50) ax.set_xticks(ind) ax.set_xticklabels(legend, fontsize=35) ax.set_ylabel(yLabel, fontsize=50) plt.xlabel("Cumulative Chance = 1/Odds", fontsize=50) sN = "./lottery/powerBall-Chance-Options.png" print "Working On %s" % sN plt.savefig(sN) #plt.show() print "FINISHED %s" % sN gD = pbOptions() for g in gD: #g.printLotteryGameData() #print "x" #print oddsAboveTarget(g,1000000) pass powerBallRPDOptions(gD) powerBallPrizeChart(gD) powerBallchanceOptions(gD)