A list of javascript function to calculate Call and put, delta, gamma, vega ,Theta and rho
function D1BlackScholes(S,K,r,sigma,q,T,t) { sigma2=sigma*sigma; TT=T-t; r1=ln(S/K)+TT*(r-q+sigma2*0.5); r2=sigma*Math.sqrt(TT); return r1/r2; //value=1/(sigma*Math.sqrt(T-t))* } function D2BlackScholes(S,K,r,sigma,q,T,t) { return (ln(S/K)+(T-t)*(r-q-(sigma*sigma*0.5)))/(sigma*Math.sqrt(T-t)); } function CallBlackScholes(S,K,r,sigma,q,T,t) { return NCDF(D1BlackScholes(S,K,r,sigma,q,T,t),0,1)*S-(NCDF(D2BlackScholes(S,K,r,sigma,q,T,t),0,1)*K*Math.exp(-r*(T-t))); } function PutBlackScholes(S,K,r,sigma,q,T,t) { return NCDF(-D2BlackScholes(S,K,r,sigma,q,T,t),0,1)*K*Math.exp(-r*(T-t))-NCDF(-D1BlackScholes(S,K,r,sigma,q,T,t),0,1)*S; } function CallBlackScholesDelta(S,K,r,sigma,q,T,t) { return NCDF(D1BlackScholes(S,K,r,sigma,q,T,t),0,1); } function PutBlackScholesDelta(S,K,r,sigma,q,T,t) { return NCDF(D1BlackScholes(S,K,r,sigma,q,T,t),0,1)-1; } function CallBlackScholesGamma(S,K,r,sigma,q,T,t) { return NormalDens(D1BlackScholes(S,K,r,sigma,q,T,t))/(S*sigma*Math.sqrt(T-t)); } function PutBlackScholesGamma(S,K,r,sigma,q,T,t) { return CallBlackScholesGamma(S,K,r,sigma,q,T,t); } function CallBlackScholesVega(S,K,r,sigma,q,T,t) { return NormalDens(D1BlackScholes(S,K,r,sigma,q,T,t))*(S*Math.sqrt(T-t)); } function PutBlackScholesVega(S,K,r,sigma,q,T,t) { return CallBlackScholesVega(S,K,r,sigma,q,T,t); } function CallBlackScholesTheta(S,K,r,sigma,q,T,t) { return (S*NormalDens(D1BlackScholes(S,K,r,sigma,q,T,t))*sigma/(2*Math.sqrt(T-t)))-(r*K*Math.exp(-r*(T-t))*NCDF(D2BlackScholes(S,K,r,sigma,q,T,t),0,1)); } function PutBlackScholesTheta(S,K,r,sigma,q,T,t) { return (S*NormalDens(D1BlackScholes(S,K,r,sigma,q,T,t))*sigma/(2*Math.sqrt(T-t)))+(r*K*Math.exp(-r*(T-t))*NCDF(-D2BlackScholes(S,K,r,sigma,q,T,t),0,1)); } function CallBlackScholesRho(S,K,r,sigma,q,T,t) { return K*(T-t)*Math.exp(-r*(T-t))*NCDF(D2BlackScholes(S,K,r,sigma,q,T,t),0,1); } function PutBlackScholesRho(S,K,r,sigma,q,T,t) { return -K*(T-t)*Math.exp(-r*(T-t))*NCDF(-D2BlackScholes(S,K,r,sigma,q,T,t),0,1); }
No comments:
Post a Comment