Last active
July 8, 2024 20:52
-
-
Save mushanyoung/f91c0990fbba3f3cd9e7dea845b43b38 to your computer and use it in GitHub Desktop.
计算扑克线下保险的真实期望值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Iterate folded cards in [0, 14] from undealt_cards then calculate the actual EV. | |
def calculate_ev_for_unseen_cards(undealt_cards, outs): | |
ev_sum = 0 | |
count = 0 | |
for folded_cards in range(0, 15): | |
actual_undealt_cards = undealt_cards - folded_cards | |
# actual_undealt_cards must be a positive number in real life. | |
if actual_undealt_cards > 0: | |
# let the actual_outs be a float number, this will lead to the same | |
# result as simulating large enough amounts of integer actual_outs then | |
# combining their EV sum. | |
actual_outs = outs - folded_cards * (outs / undealt_cards) | |
actual_odds = actual_outs / actual_undealt_cards | |
ev_sum += actual_odds | |
count += 1 | |
return ev_sum / count if count > 0 else outs / undealt_cards | |
def run_simulation(insurance_cost = 0.05): | |
sum_cost_ev = 0 | |
sum_actual_ev = 0 | |
# Iterate undealt cards in [1, 42]. | |
for undealt_cards in range(1, 43): | |
# Iterate outs in [0, undealt_cards]. | |
for outs in range(0, undealt_cards + 1): | |
cost_ev = outs / undealt_cards * insurance_cost | |
actual_ev = calculate_ev_for_unseen_cards(undealt_cards, outs) | |
sum_cost_ev += cost_ev | |
sum_actual_ev += actual_ev | |
return sum_cost_ev / sum_actual_ev | |
average_ev_ratio = run_simulation() | |
print(f"线下保险的真实期望值比例: {average_ev_ratio:.04f}") | |
################################################################# | |
# 线下保险的真实期望值比例: 0.0500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment