Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168741
Image: ubuntu2004
def myfun(dZ, dt): S = 70; V = 0.3; T = 3.0; R = 0.02; X = 70; q=0; #S = S/X; #X= X/X; V=V*sqrt(T); R=R*T; temp_discount = 1.0/(1.0 + R * dt); temp1 = dt * (R - q - V * V * 0.5)*0.5/dZ; temp2 = dt * V * V / dZ / dZ; alpha = temp_discount*(-temp1 + 0.5*temp2); beta = temp_discount * (1- temp2); gamma = temp_discount * ( temp1 + 0.5*temp2); return alpha, beta, gamma; def metric1(dZ, dt): alpha, beta, gamma=myfun(dZ, dt); eps_u=alpha-0.25; eps_m=beta-0.5; #eps_m=0; eps_d=gamma-0.25; return eps_u^2+eps_d^2+eps_m^2;
vv=minimize(lambda x:metric1(x[0],x[1]), [1,1]); print(vv[0],vv[1]); print(myfun(vv[0],vv[1]));
Warning: Maximum number of function evaluations has been exceeded. (0.0441686919501, 0.00360785064818) (0.252670892077329, 0.500566723699687, 0.246545960033662)