19/10/2024, 13:27 Game Theory Lab Experiment 9.
ipynb - Colab
import numpy as np
# Probabilities for the market state
prob_good = 0.5
prob_neutral = 0.3
prob_bad = 0.2
# Payoffs depending on the actions and market state
payoffs = {
'both_enter': {
'good': {'low': 20, 'high': 15},
'neutral': {'low': 10, 'high': 5},
'bad': {'low': -10, 'high': -10}
},
'one_enters': {
'good': 25,
'neutral': 12,
'bad': 5
},
'no_entry': 0
}
# Types of firms (Low-cost and High-cost)
types = ['low', 'high']
# Function to calculate expected payoff for entering the market
def expected_payoff(enter, firm_type, other_firm_enter, beliefs):
expected_payoff = 0
if enter:
if other_firm_enter:
for state in ['good', 'neutral', 'bad']:
payoff = payoffs['both_enter'][state][firm_type]
expected_payoff += beliefs[state] * payoff
else:
for state in ['good', 'neutral', 'bad']:
payoff = payoffs['one_enters'][state]
expected_payoff += beliefs[state] * payoff
else:
expected_payoff = payoffs['no_entry']
return expected_payoff
# Function to find the best response for a firm
def best_response(firm_type, beliefs, other_firm_strategy):
# Calculate the expected payoffs for both strategies (entering and not entering)
payoff_enter = expected_payoff(True, firm_type, other_firm_strategy, beliefs)
payoff_no_enter = expected_payoff(False, firm_type, other_firm_strategy, beliefs)
if payoff_enter > payoff_no_enter:
return True # Enter the market
else:
return False # Don't enter the market
# Beliefs about the market state
beliefs = {'good': prob_good, 'neutral': prob_neutral, 'bad': prob_bad}
# Iterate until equilibrium is found
def find_bayesian_nash_equilibrium():
firm_a_strategy = {'low': True, 'high': True} # Initial guess: both enter
firm_b_strategy = {'low': True, 'high': True}
for _ in range(100): # Iterate to find the equilibrium
for firm_type in types:
firm_a_best_response = best_response(firm_type, beliefs, firm_b_strategy[firm_type])
firm_b_best_response = best_response(firm_type, beliefs, firm_a_strategy[firm_type])
firm_a_strategy[firm_type] = firm_a_best_response
firm_b_strategy[firm_type] = firm_b_best_response
return firm_a_strategy, firm_b_strategy
# Find and print the Bayesian Nash Equilibrium
firm_a_equilibrium, firm_b_equilibrium = find_bayesian_nash_equilibrium()
print("Firm A's equilibrium strategy:", firm_a_equilibrium)
print("Firm B's equilibrium strategy:", firm_b_equilibrium)
[Link] 1/2
19/10/2024, 13:27 Game Theory Lab Experiment [Link] - Colab
Firm A's equilibrium strategy: {'low': True, 'high': True}
Firm B's equilibrium strategy: {'low': True, 'high': True}
[Link] 2/2