odds — Prize odds & expected value¶
Exact combinatorics from official rules: winning combinations, probabilities, expected prize per bet and return rate; includes DLT additional-bet and compound-bet variants.
odds ¶
Classes¶
LotteryPac ¶
中奖概率与奖金期望计算框架。
各彩种的奖级、中奖条件与奖金均以官方游戏规则为准(详见 config.py 中的规则来源), 浮动奖按默认假设值计算期望,可用环境变量覆盖(键名见各配置类的 *_prize_env)。
Methods:¶
hyper_c
staticmethod
¶
单池超几何组合数:号码池 total 个、每期开出 drawn 个、投注 pick 个时, 恰有 hit 个投注号码被开出的组合数。
lottery_pac_c ¶
lottery_pac_c(red_sum: int, red_aim: int, red_get: int, blue_sum: int = 1, blue_aim: int = 1, blue_get: int = 1) -> int
双池乐透(红/蓝两区独立,如双色球、大乐透)命中 (red_get, blue_get) 的组合数。
get_prize_level
staticmethod
¶
根据命中情况反查奖级。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prize_role
|
dict
|
dict, 奖级 → 命中组合集合的映射(如 {1: {(6, 1)}, ...})。 |
required |
hit
|
tuple
|
tuple, 实际命中情况(如 (红命中数, 蓝命中数))。 |
required |
Returns:
| Type | Description |
|---|---|
|
int, 奖级(1 起);未中奖返回 None。 |
resolve_prize
staticmethod
¶
解析某奖级的单注奖金:环境变量覆盖优先于默认值。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
award
|
dict
|
dict, 奖级 → 默认奖金映射。 |
required |
env_map
|
Optional[dict]
|
Optional[dict], 奖级 → 环境变量名映射;None 表示无覆盖项。 |
required |
level
|
int
|
int, 奖级。 |
required |
Returns:
| Type | Description |
|---|---|
float
|
float, 单注奖金(元)。 |
get_expectation_dataframe ¶
按投注方式汇总单注期望奖金(元)与返奖率。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bet_price
|
Optional[float]
|
float, 覆盖单注价格(如大乐透追加投注为 3 元);None 时用配置默认。 |
None
|
**kwargs
|
透传给 get_odds_dataframe(如 if_pool_over_800m、if_add_bet)。 |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame columns: lottery_name, play_type, bet_price_yuan, expected_value_yuan, return_rate。 |
QlcPac ¶
Bases: LotteryPac
七乐彩中奖概率与奖金期望。
投注 7 个号码,开奖为 7 个基本号码 + 1 个特别号码(同池,特别号从剩余号码中开出), 属于多类别超几何分布:命中 (基本号 r 个, 特别号 s 个) 的组合数为 C(7, r) * C(1, s) * C(22, 7 - r - s),总组合数为 C(30, 7)。
DltPac ¶
Bases: LotteryPac
超级大乐透中奖概率与奖金期望(现行七个奖级规则)。
QxcPac ¶
Bases: LotteryPac
7星彩中奖概率与奖金期望。
前六位每位 0-9(按位比对),最后一位 0-14,共 10^6 * 15 种组合。 命中 (前区 f 位, 最后一位 l) 的组合数为 C(6, f) * 9^(6-f) * (1 if l else 14)。
Functions:¶
load_prize_odds ¶
Return the per-prize odds table for a game.
Exact combinatorics on top of the current official rules (source URLs in
config.py): winning combinations, probabilities, prize amounts, prize type.
中文说明
返回指定彩种各奖级的中奖组合数、中奖概率与奖金明细表——规则来源均为 官网(cwl.gov.cn / lottery.gov.cn,见 config.py)。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lottery_name
|
str
|
str, must in ('ssq', 'qlc', 'kl8', '3d', 'dlt', 'pls', 'plw', 'qxc'). |
'ssq'
|
**kwargs
|
:param pick: int, only for kl8, 1-10, default None(返回全部玩法). :param if_pool_over_800m: boolean, only for dlt, default False. :param if_add_bet: boolean, only for dlt, default False. 追加投注:浮动奖按 80% 兑付。 |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame |
load_prize_expectation ¶
返回指定彩种的单注期望奖金(元)与返奖率。
浮动奖按 config.py 中的默认假设值计算(可用环境变量覆盖), 因此返奖率为基于假设值的静态期望, 实际返奖率以当期开奖公告为准。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lottery_name
|
str
|
str, must in ('ssq', 'qlc', 'kl8', '3d', 'dlt', 'pls', 'plw', 'qxc'). |
'ssq'
|
**kwargs
|
:param pick: int, only for kl8, 1-10, default None(返回全部玩法). :param if_pool_over_800m: boolean, only for dlt, default False. :param if_add_bet: boolean, only for dlt, default False. 追加投注:3 元/注,浮动奖按 80% 兑付。 |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame |
load_dlt_compound_expectation ¶
load_dlt_compound_expectation(n_red: int = 5, m_blue: int = 2, if_pool_over_800m: bool = False, if_add_bet: bool = False) -> DataFrame
返回大乐透复式投注的注数、成本与整票期望。
复式票选定 \(n_{red}\) 个前区号码与 \(m_{blue}\) 个后区号码,组合为 \(\binom{n_{red}}{5}\times\binom{m_{blue}}{2}\) 注单式。开奖后前区命中 \(r\) 个、后区命中 \(b\) 个时:
由期望的线性性,整票期望恒等于 总注数 × 单式期望(返奖率不变), 复式只改变成本与方差。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_red
|
int
|
int, 前区号码个数,5-35。 |
5
|
m_blue
|
int
|
int, 后区号码个数,2-12。 |
2
|
if_pool_over_800m
|
bool
|
boolean, 奖池 ≥ 8 亿元档固定奖,default False. |
False
|
if_add_bet
|
bool
|
boolean, 复式追加(3 元/注,浮动奖 80%),default False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame(单行) columns: lottery_name, n_red, m_blue, total_bets, cost_yuan, expected_prize_yuan, return_rate |