I am trying to solve this equation for lambda λ using python.
in that, For i in the index column, P_0, c, t, D, F are given in the dataframe as below:
Given r = constant = 0.6
, Excel Solver can solve the equation for lambda easily. But I am new to python and I have been struggling with python sympy to find a way to solve it. Please help! Thanks alot!
Edit: this is my dataframe dataframe
This is my python code. It takes forever to run while Excel Solver took less than 1 second so I think there must be something wrong with it.
import sympy as sy
x = sy.Symbol('x', real =True)
coupon = max(cal_lambda['c'])
r = 0.6
F = 100
P = max(cal_lambda['P_O'])
component1 = 0
component2 = 0
for i1, i2 in zip(cal_lambda['T'],cal_lambda['D']):
component1 += coupon*np.e**(-x*i1*1/100*i2)
component2 += r*np.e**(-x*0.5*1/100*i2)
component3 = F*np.e**(-x*cal_lambda['T'].tail(1)*cal_lambda['D'].tail(1))
Equation = sy.Eq(component1 + component2 + component3,P)
sol = sy.solve(Equation)
print(sol)