Closed HristinaSaparevska closed 1 year ago
A couple of things are going wrong here. First, I do not understand how you can run this code without errors. E.g. (p_A**(1-ϵ))((1/2) + ((p_B**(1-ϵ)-p_A**(1-ϵ))/(2t*(1-ϵ))))
is not valid python code.
Second, it is not a good idea to define separate functions for A and B when, in fact, they are the same functions.
Third, in the function fixed point
, x[0]
should be compared to reaction_function_A
(not B); although, as said, it is better not to have _A
and _B
to start with.
Fourth, the function fixed_point
returns optimal prices. So it is a bit confusing to have the function equilibrium_output
.
Does this help to work on this further?
Hello, Thank you very much for your answer. We managed to figure out the solution to the fixed point function. In addition, we defined separate functions for A and B because our profit functions are not symmetric and we would have gotten diferent results. There is just one thing that we do not understand. Why is (p_A(1-ϵ))((1/2) + ((p_B(1-ϵ)-p_A*(1-ϵ))/(2t(1-ϵ)))) not a valid python code. Is it because of the symbol "ϵ"? We changed it but we are not sure what else to change. Thank you in advance!
multiplication should be explicit: e.g. $2*t$ instead of $2t$
We have the indifferent consumer:
$\hat{x} = \frac{1}{2} + \frac{p_B^{1-ϵ}-p_A^{1-ϵ}}{2t(1-ϵ)}$
These are the profits of the firms
$\pi_A = \hat{x} p_A^{1-ϵ}$, $\pi_B = (1-\hat{x}) p_B^{1-ϵ}$
We need to take the FOC of $\pi_A$ (maximize it) with respect to $p_A$ and then do the same for $\pi_B$ and $p_B$. Then we solve the system for $p_A$ and $p_B$ and get the equilibrium prices:
$p_A = p_B = (t(1-ε))^{\frac{1}{1-ε}}$
When we tried to calculate the equilibrium prices for different values of epsilon and t=1 we got the same result of $p_A = 0.000006$ and we think that the prices should be different for the different values of the parameter. Could you tell us where we are making a mistake?
The code:
def profit_A(p_A,p_B,t,ϵ): return (p_A*(1-ϵ))((1/2) + ((p_B(1-ϵ)-p_A(1-ϵ))/(2t(1-ϵ))))
def reaction_function_A(p_B,t,ϵ): return optimize.fminbound(lambda p_A: -profit_A(p_A,p_B,t,ϵ),0,1)
def profit_B(p_A,p_B,t,ϵ): return (p_A(1-ϵ))(1-((1/2) + ((p_B(1-ϵ)-p_A(1-ϵ))/(2*t(1-ϵ)))))
def reaction_function_B(p_A,t,ϵ): return optimize.fminbound(lambda p_B: -profit_B(p_A,p_B,t,ϵ),0,1)
def fixed_point(x,t,ϵ): return [ x[0] - reaction_function_B(x[1],t,ϵ), x[1] - reaction_function_A(x[0],t,ϵ)]
optimize.fsolve(lambda x: fixed_point(x,1,0), [0.5,0.5])
x0 = [0.2, 0.2]
def equilibrium_output(t, ϵ): sol = optimize.fsolve(lambda x: fixed_point(x, t, ϵ), x0) return sol
equilibrium_output (0.5, 0.5)
t = 1 range_ϵ = np.arange (0,1,0.1) range_p_A = [equilibrium_output (t, ϵ) [0] for ϵ in range_ϵ]
df = pd.DataFrame({'ϵ': range_ϵ, 'p_A': range_p_A})