首页 » 技术分享 » 世界杯买球算法

世界杯买球算法

 

今年世界杯不太平,大家买球的输了不少吧,反正我一直在输,研究了下赔率和返还率,写了个算法。在确定预期收入的情况下,确定各赔率下的压金,可以根据实际情况从中选择两个投注,赢面大些。

返还率 = 预期收入 / 总投入

想算算威廉希尔和竞彩官方有没有稳赢的组合,结果没有。

import requests
from bs4 import BeautifulSoup
import json


class fiFa():
    def __init__(self, atuple):
        # self.winOdds = winOdds
        # self.drawOdds = drawOdds
        # self.lossOdds = lossOdds
        self.winOdds,self.drawOdds,self.lossOdds = atuple
        self.winOdds,self.drawOdds,self.lossOdds = float(self.winOdds),float(self.drawOdds),float(self.lossOdds)
        winput = 100 / self.winOdds
        drawput = 100 / self.drawOdds
        lossput = 100 / self.lossOdds
        totalput = winput + drawput + lossput
        self.winper = winput / totalput
        self.drawper = drawput / totalput
        self.lossper = lossput / totalput


    def printf(self, win=None, draw=None, loss=None):
        if win != None:
            total = win / self.winper
            my_draw_put = total * self.drawper
            my_loss_put = total * self.lossper
            print("胜压:{}\n平压:{}\n负压:{}\n总投入:{}\n预期收入:{}\n".format(win, my_draw_put, my_loss_put, total, win*self.winOdds))


        elif draw != None:
            total = draw / self.drawper
            my_win_put = total * self.winper
            my_loss_put = total * self.lossper
            print("胜压:{}\n平压:{}\n负压:{}\n总投入:{}\n预期收入:{}\n".format(my_win_put, draw, my_loss_put, total, draw*self.drawOdds))


        elif loss != None:
            total = loss / self.lossper
            my_win_put = total * self.winper
            my_draw_put = total * self.drawper
            print("胜压:{}\n平压:{}\n负压:{}\n总投入:{}\n预期收入:{}\n".format(my_win_put, draw, loss, total, loss*self.lossOdds))


    def per(self):
        print("赢的概率{}\n平的概率draw{}\n负的概率loss{}".format(self.winper, self.drawper, self.lossper))


    def expincome(self, exp):
        win_put = exp / self.winOdds
        draw_put = exp / self.drawOdds
        loss_put = exp / self.lossOdds
        # total = win_put + draw_put + loss_put
        return win_put, draw_put, loss_put


# 想算算威廉希尔和竞彩官方有没有稳赢的组合,结果没有。
def sy(a, b):
    exp = 100
    t = a.expincome(exp)
    w = b.expincome(exp)
    z = tuple(zip(t, w))
    for i in z[0]:
        for j in z[1]:
            for p in z[2]:
                myinput = i + j + p
                if myinput < exp:
                    print("______稳赢组合______:", i, j, p)


def vs_information(num,rjson):
    h_cn = rjson['data'][num]['h_cn']
    a_cn = rjson['data'][num]['a_cn']
    date = rjson['data'][num]['date']
    time = rjson['data'][num]['time']
    print('比赛日期:{} {} {}VS{}'.format(date,time,h_cn,a_cn))
    print('胜%s,平%s,负%s' % get_odds(num,rjson))


def get_odds(num,rjson):
    vin = rjson['data'][num]['had']['h']
    draw = rjson['data'][num]['had']['d']
    loss = rjson['data'][num]['had']['a']
    return vin,draw,loss


def result(num,rjson,p=100):    
    vs_information(num,rjson)
    jingcai = fiFa(get_odds(num,rjson))
    jingcai.printf(win=p)


if __name__ == '__main__':
    # 抓取实时赔率
    html = requests.get("http://i.sporttery.cn/odds_calculator/get_odds?i_format=json&i_callback=getData&poolcode[]=hhad&poolcode[]=had&_=1529656976684")
    rjson = json.loads(html.text.lstrip('getData(').rstrip(');'))
    for id in rjson['data']:
        if rjson['data'][id]['l_cn'] == "世界杯":
            result(id,rjson)
    

结果:

转载自原文链接, 如需删除请联系管理员。

原文链接:世界杯买球算法,转载请注明来源!

0