小言_互联网的博客

[世界杯]根据赔率计算各种组合可能性与赔率

1254人阅读  评论(0)

目录

一、背景

二、数据输入

2.1 赔率示意图

2.2 代码

三、数据处理

3.1 计算各种组合可能性

3.2 修正概率

四、输出结果


一、背景

本文以世界杯体彩“混合过关”4场串胜平负为的赔率进行编码

其他类型如比分 、总进球数可以参考代码进行相应修改

需要的库:numpy与pandas

二、数据输入

2.1 赔率示意图

 2.2 代码

采用字典保存各比赛对应的胜平负的赔率


  
  1. import pandas as pd
  2. import numpy as np
  3. vs1 = { "胜": 2.38, "平": 2.93, "负": 2.65} #厄瓜多尔-塞内加尔
  4. vs2 = { "胜": 13.0, "平": 6.20, "负": 1.11} #卡塔尔-荷兰
  5. vs3 = { "胜": 3.58, "平": 3.16, "负": 1.84} #伊朗-美国
  6. vs4 = { "胜": 7.35, "平": 4.16, "负": 1.31} #威尔士-英格兰

三、数据处理

3.1 计算各种组合可能性

计算采用的公式主要为:(图中10%为抽水率,仅为假设)

其中0.9913为初步计算得到的体彩抽水率,实际不准确,该数值仅供初步计算,之后需要根据计算所得的概率进行相应修正


  
  1. count = 1
  2. probList = []
  3. probListIndex = []
  4. probVs = []
  5. timesList = []
  6. vsCode1 = []
  7. vsCode2 = []
  8. vsCode3 = []
  9. vsCode4 = []
  10. for key1,each1 in vs1.items():
  11. for key2,each2 in vs2.items():
  12. for key3,each3 in vs3.items():
  13. for key4,each4 in vs4.items():
  14. # print(count,key1,key2,key3,each1*each2*each3)
  15. prob = 99.13 / (each1*each2*each3*each4)
  16. #print(count,key1,key2,key3,key4,prob)
  17. probList.append(prob)
  18. probListIndex.append(count)
  19. probVs.append(key1+key2+key3+key4)
  20. timesList.append(each1*each2*each3*each4)
  21. vsCode1.append(key1)
  22. vsCode2.append(key2)
  23. vsCode3.append(key3)
  24. vsCode4.append(key4)
  25. count += 1
  26. data = pd.DataFrame(probList,index = probListIndex,columns=[ "prob"])
  27. data_temp = pd.DataFrame(probVs,index = probListIndex,columns=[ "vs"])
  28. data_times = pd.DataFrame(timesList,index = probListIndex,columns=[ "times"])
  29. data_vs1 = pd.DataFrame(vsCode1,index = probListIndex,columns=[ "vs1"])
  30. data_vs2 = pd.DataFrame(vsCode2,index = probListIndex,columns=[ "vs2"])
  31. data_vs3 = pd.DataFrame(vsCode3,index = probListIndex,columns=[ "vs3"])
  32. data_vs4 = pd.DataFrame(vsCode4,index = probListIndex,columns=[ "vs4"])
  33. # data = data.add(data_temp,fill_value=False)
  34. data[ "vs"] = data_temp[ "vs"]
  35. data[ "vs1"] = data_vs1[ "vs1"]
  36. data[ "vs2"] = data_vs2[ "vs2"]
  37. data[ "vs3"] = data_vs3[ "vs3"]
  38. data[ "vs4"] = data_vs4[ "vs4"]
  39. data[ "times"] = data_times[ "times"]
  40. data = data.sort_values(by= "prob",ascending= False)
  41. data[ "total_prob"] = 0
  42. sum_prob = 0
  43. for each in data.index:
  44. # print(each)
  45. sum_prob += data[ "prob"].loc[each]
  46. data[ "total_prob"].loc[each] = sum_prob

3.2 修正概率

该段代码无实际含义,仅为修正由于采用估计抽水率计算所得的概率偏差

主要思路是采用数据标准化后并将数据映射到合理的区间,并对部分概率进行转换


  
  1. total_prob_min = data[ "total_prob"]. min()
  2. data[ "total_prob"] = (data[ "total_prob"]-data[ "total_prob"]. min())/(data[ "total_prob"]. max()-data[ "total_prob"]. min())*( 100-total_prob_min)+total_prob_min
  3. data[ "total_prob"].iloc[ 0] = (data[ "total_prob"].iloc[ 1]*data[ "total_prob"].iloc[ 0])/(data[ "prob"].iloc[ 1]+data[ "total_prob"].iloc[ 0])
  4. temp = data[ "total_prob"] - data[ "total_prob"].shift( 1)
  5. temp[ 0] = data[ "total_prob"].iloc[ 0]
  6. data[ "prob"] = temp
  7. data[ "prob"].iloc[ 0] = data[ "total_prob"].iloc[ 0]
  8. data.to_csv( r"C:\Users\kkkk\Desktop\世界杯1129.csv")

四、输出结果

prob该组合可能性,total_prob为累计可能性,times为赔率,VS1~4为该组合对应的胜平负

 以11.29日赛程为参考,卡塔尔与威尔士大概率负,因此采用Excel筛选出相关组合,在所列组合中选取赔率较高的组合。

五、代码


  
  1. import pandas as pd
  2. import numpy as np
  3. vs1 = { "胜": 2.38, "平": 2.93, "负": 2.65}
  4. vs2 = { "胜": 13.0, "平": 6.20, "负": 1.11}
  5. vs3 = { "胜": 3.58, "平": 3.16, "负": 1.84}
  6. vs4 = { "胜": 7.35, "平": 4.16, "负": 1.31}
  7. count = 1
  8. probList = []
  9. probListIndex = []
  10. probVs = []
  11. timesList = []
  12. vsCode1 = []
  13. vsCode2 = []
  14. vsCode3 = []
  15. vsCode4 = []
  16. for key1,each1 in vs1.items():
  17. for key2,each2 in vs2.items():
  18. for key3,each3 in vs3.items():
  19. for key4,each4 in vs4.items():
  20. # print(count,key1,key2,key3,each1*each2*each3)
  21. prob = 99.13 / (each1*each2*each3*each4)
  22. print(count,key1,key2,key3,key4,prob)
  23. probList.append(prob)
  24. probListIndex.append(count)
  25. probVs.append(key1+key2+key3+key4)
  26. timesList.append(each1*each2*each3*each4)
  27. vsCode1.append(key1)
  28. vsCode2.append(key2)
  29. vsCode3.append(key3)
  30. vsCode4.append(key4)
  31. count += 1
  32. data = pd.DataFrame(probList,index = probListIndex,columns=[ "prob"])
  33. data_temp = pd.DataFrame(probVs,index = probListIndex,columns=[ "vs"])
  34. data_times = pd.DataFrame(timesList,index = probListIndex,columns=[ "times"])
  35. data_vs1 = pd.DataFrame(vsCode1,index = probListIndex,columns=[ "vs1"])
  36. data_vs2 = pd.DataFrame(vsCode2,index = probListIndex,columns=[ "vs2"])
  37. data_vs3 = pd.DataFrame(vsCode3,index = probListIndex,columns=[ "vs3"])
  38. data_vs4 = pd.DataFrame(vsCode4,index = probListIndex,columns=[ "vs4"])
  39. # data = data.add(data_temp,fill_value=False)
  40. data[ "vs"] = data_temp[ "vs"]
  41. data[ "vs1"] = data_vs1[ "vs1"]
  42. data[ "vs2"] = data_vs2[ "vs2"]
  43. data[ "vs3"] = data_vs3[ "vs3"]
  44. data[ "vs4"] = data_vs4[ "vs4"]
  45. data[ "times"] = data_times[ "times"]
  46. data = data.sort_values(by= "prob",ascending= False)
  47. data[ "total_prob"] = 0
  48. sum_prob = 0
  49. for each in data.index:
  50. # print(each)
  51. sum_prob += data[ "prob"].loc[each]
  52. data[ "total_prob"].loc[each] = sum_prob
  53. total_prob_min = data[ "total_prob"]. min()
  54. data[ "total_prob"] = (data[ "total_prob"]-data[ "total_prob"]. min())/(data[ "total_prob"]. max()-data[ "total_prob"]. min())*( 100-total_prob_min)+total_prob_min
  55. data[ "total_prob"].iloc[ 0] = (data[ "total_prob"].iloc[ 1]*data[ "total_prob"].iloc[ 0])/(data[ "prob"].iloc[ 1]+data[ "total_prob"].iloc[ 0])
  56. temp = data[ "total_prob"] - data[ "total_prob"].shift( 1)
  57. temp[ 0] = data[ "total_prob"].iloc[ 0]
  58. data[ "prob"] = temp
  59. data[ "prob"].iloc[ 0] = data[ "total_prob"].iloc[ 0]
  60. data.to_csv( r"C:\Users\kkkk\Desktop\世界杯1129.csv")


转载:https://blog.csdn.net/zsllsz2022/article/details/128106774
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场