摘要:本文通过Python模拟对比两种经典概率游戏——圣彼得堡悖论和骰子点数实验,用可视化方式揭示期望值与实际收益的巨大差异。代码完整可运行,适合概率论学习者和量化爱好者。本文通过Python模拟和数学分析,对比了圣彼得堡悖论(期望无穷但多数亏损)与骰子点数实验(负期望必然本金耗尽)两种随机实验。模拟结果显示:骰子点数实验呈现"随机游走+负漂移"特征,约7000次实验后本金耗尽;圣彼得堡则长期横盘、偶尔跳跃,少数大奖决定最终收益。文章深入剖析了数学期望的局限性,从凯利公式视角探讨了极端分布下的策略选择,并引申出对投资仓位管理和风险控制的启示。完整代码提供了可复现的模拟实验。


一、引言

在概率论中,圣彼得堡论是一个著名的思想实验,它揭示了数学期望与实际决策之间的矛盾。而骰子点数实验(Sic Bo)作为一种传统随机实验,则展现了负期望值游戏的典型特征。

本文通过Python模拟两种游戏的资金曲线,直观展示:

  • 为什么"公平"的游戏可能让你本金耗尽
  • 为什么"不公平"的游戏可能让你高收益
  • 期望值理论的局限性

二、实验规则说明

2.1 骰子点数实验(大点数)

📌 规则:
- 3个骰子,点数和 4~10 为小点数,11~17 为大点数
- 豹子(三个相同)导致大小点数均不计
- 参与者每次投入10元,选择【大点数】
- 盈利:+10元,亏损:-10元元

数学期望计算:

  • 总组合数:6³ = 216种
  • 豹子组合:6种(111,222,333,444,555,666)
  • 大点数组合:108种(扣除豹子后约105种)
  • 成功概率 ≈ 48.6%,期望值为负*

2.2 圣彼得堡悖论

 规则:
- 不断抛硬币直到出现正面
- 连续n-1次反面,第n次正面
-回报 = 2^n 元元
- 每次入场门票10元

数学期望计算:

E = (1/2)×2 + (1/4)×4 + (1/8)×8 + ... = 1 + 1 + 1 + ... = ∞

理论上期望值是无穷大但实际实验中很少获得高额回报。。


三、Python模拟实现现

3.1骰子点数实验模拟函数验模拟函数数

    capital = start_capital
    history = [capital]
    rng = np.random.default_rng()
    for _ in range(max_rounds):
        if capital < bet:
            break
        dices = rng.integers(1,7,size=3)
        s = dices.sum()
        a,b,c = dices
        is_leopard = (a==b and b==c)
        if is_leopard:
            capital -= bet
        else:
            if 11 <= s <=17:
                capital += bet
            else:
                capital -= bet
        history.append(capital)
    return history

3.2圣彼得堡实验模拟函数数

def simulate_st_petersburg(start_capital=1000, ticket=10, max_games=10000):
    capital = start_capital
    history = [capital]
    rng = np.random.default_rng()
    for _ in range(max_games):
        if capital < ticket:
            break
        capital -= ticket
        n = 1
        while True:
            flip = rng.choice([0,1])
            if flip == 1:
                reward = 2**n
                capital += reward
                break
            n +=1
        history.append(capital)
    return history

3.3 可视化绘图

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(14,6))

#骰子点数实验资金曲线线
plt.subplot(1,2,1)
plt.plot(sicbo_history, color='#2E86AB', lw=1.2)
plt.axhline(y=1000, ls='--', c='red', alpha=0.6)
plt.title(骰子点数实验(投入大点数)资金曲线 | 每次投入10元元")
plt.xlabel("对局次数")
plt.ylabel("玩家资金")
plt.grid(alpha=0.3)

# 圣彼得堡资金曲线
plt.subplot(1,2,2)
plt.plot(sp_history, color='#A23B72', lw=1.2)
plt.axhline(y=1000, ls='--', c='red', alpha=0.6)
plt.title(圣彼得堡实验资金曲线 | 每次参与成本10元元")
plt.xlabel("游戏局数")
plt.ylabel("玩家资金")
plt.grid(alpha=0.3)

plt.tight_layout()
plt.show()

四、模拟结果分析

4.1 典型运行结果

=====骰子点数实验模拟结果果 =====总实验次数数:7234
最终资金:0参与者本金已耗尽。!

===== 圣彼得堡游戏模拟结果 =====总实验次数数:10000
最终资金:31250

4.2 资金曲线对比

特征骰子点数实验宝圣彼得堡
期望值正无穷
波动性中等极高
本金耗尽风险险
高收益可能能

4.3 关键观察

  1. 骰子点数实验曲线线*:呈现典型的"随机游走+负漂移"最终必然本金耗尽产
  2. 圣彼得堡实验曲线线*:长期横盘+偶尔跳跃几次高回报决定最终收益益
  3. 时间尺度骰子点数实验约7000局本金耗尽产,圣彼得堡可玩满10000局

五、数学原理深入

5.1 为什么骰子点数实验必亏??

total = 6**3  # 216种组合
leopard = 6   # 豹子数big_win = 105 # 大且非豹子点数子big_lose = 105 # 小且非豹子点数子

p_win = big_win / total  # ≈ 0.486
p_lose = (big_lose + leopard) / total  # ≈ 0.514

expectation = p_win * 10 + p_lose * (-10)  # ≈ -0.28元/局

每局期望亏损约0.28元,长期必然本金耗尽。。

5.2 圣彼得堡悖论的真相

虽然数学期望是无穷大,但:

奖金概率累计概率
2元1/250%
4元1/475%
8元1/887.5%
16元1/1693.75%
32元1/3296.875%
96.875%的回报≤32元,扣除10元投入,大部分时候是亏损的。只有极少数情况能获得高收益。。

5.3 凯利公式视角

对于圣彼得堡游戏最优投入比例例:

f* = (p×b - q) / b

但由回报分布极端端,传统凯利公式不适用,需要分数凯利固定比例策略。


六、完整代码

import numpy as np
import matplotlib.pyplot as plt
# 骰子点数实验模拟拟
def simulate_sicbo(start_capital=1000, bet=10, max_rounds=10000):
    capital = start_capital
    history = [capital]
    rng = np.random.default_rng()
    for _ in range(max_rounds):
        if capital < bet:
            break
        dices = rng.integers(1,7,size=3)
        s = dices.sum()
        a,b,c = dices
        is_leopard = (a==b and b==c)
        if is_leopard:
            capital -= bet
        else:
            if 11 <= s <=17:
                capital += bet
            else:
                capital -= bet
        history.append(capital)
    return history

# 圣彼得堡模拟
def simulate_st_petersburg(start_capital=1000, ticket=10, max_games=10000):
    capital = start_capital
    history = [capital]
    rng = np.random.default_rng()
    for _ in range(max_games):
        if capital < ticket:
            break
        capital -= ticket
        n = 1
        while True:
            flip = rng.choice([0,1])
            if flip == 1:
                reward = 2**n
                capital += reward
                break
            n +=1
        history.append(capital)
    return history

# 运行模拟
np.random.seed(42)
sicbo_history = simulate_sicbo()
sp_history = simulate_st_petersburg()

# 绘图
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(14,6))

plt.subplot(1,2,1)
plt.plot(sicbo_history, color='#2E86AB', lw=1.2)
plt.axhline(y=1000, ls='--', c='red', alpha=0.6, label="初始本金 1000")
plt.title(骰子点数实验(大点数)资金曲线 | 每次投入10单位元")
plt.xlabel(实验次数数")
plt.ylabel("玩家资金")
plt.grid(alpha=0.3)
plt.legend()

plt.subplot(1,2,2)
plt.plot(sp_history, color='#A23B72', lw=1.2)
plt.axhline(y=1000, ls='--', c='red', alpha=0.6, label="初始本金 1000")
plt.title(圣彼得堡实验资金曲线 | 单次参与成本10单位元")
plt.xlabel("游戏局数")
plt.ylabel("玩家资金")
plt.grid(alpha=0.3)
plt.legend()

plt.tight_layout()
plt.savefig(random_experiment_simulation.pngg', dpi=150)
plt.show()

# 输出统计
print("===== 骰宝模拟结果 =====")
print(f"总对局数:{len(sicbo_history)-1}")
print(f"最终资金:{sicbo_history[-1]}")

print("\n===== 圣彼得堡游戏模拟结果 =====")
print(f"总游戏局数:{len(sp_history)-1}")
print(f"最终资金:{sp_history[-1]}")

七、结论与启示

7.1 核心结论

  1. 期望值≠实际收益:圣彼得堡期望无穷但多数时候亏损
  2. 负期望必输骰子点数实验等模拟场景游戏长期必然本金耗尽产
  3. 波动性决定体验:高波动游戏需要更大本金承受回撤

7.2 投资启示

随机实验戏投资对应
骰子点数实验负期望望高频交易手续费损耗
圣彼得堡风险投资/期权策略
本金耗尽风险险仓位管理重要性

7.3 延伸思考

  • 如果圣彼得堡门票改为20元,结果如何?
    -骰子点数实验采用马丁格尔策略能避免亏损吗??
  • 如何确定最优停止时间?

八、参考文献

  1. Peters, O. (2011). The time resolution of the St Petersburg paradox. Philosophical Transactions of the Royal Society A
  2. Thorp, E. O. (1969). Optimal gambling systems for favorable games. Review of the International Statistical Institute
  3. 李贤平. 《概率论基础》. 高等教育出版社

💬 欢迎在评论区讨论:你认为圣彼得堡实验值得参与吗?**


本文代码已在Python 3.8+环境下测试通过,依赖库:numpy, matplotlib

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐