Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in greek's calculations #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function OPTIONDELTA(price, strike, volatility, interest, dividend, days, option
function OPTIONGAMMA(price, strike, volatility, interest, dividend, days) {
var d1 = D1_(price, strike, volatility, interest, dividend, days);
var time = days/365;
var eqt = Math.exp(-dividend * time);
var eqt = Math.exp(-interest * time);
var asqrtT = volatility * Math.sqrt(time);

return Math.exp(-1 * Math.pow(d1, 2)/2)/Math.sqrt(2*Math.PI)*eqt/(price*asqrtT);
Expand All @@ -63,14 +63,15 @@ function OPTIONTHETA(price, strike, volatility, interest, dividend, days, option
var time = days/365;
var eqt = Math.exp(-dividend * time);
var xert = Math.exp(-interest * time) * strike;
var nd1 = NORMDIST_(D1_(price, strike, volatility, interest, dividend, days));

if (optiontype == "Put")
{
return (-(price*Math.exp(-1*Math.pow(d1,2)/2)/Math.sqrt(2*Math.PI)*volatility*eqt/(2*Math.sqrt(time)))+(interest*xert*nd1)-(dividend*price*nd1*eqt))/365;
var nNegD2 = NORMDIST_(-D2_(price, strike, volatility, interest, dividend, days));
return (-(price*Math.exp(-1*Math.pow(d1,2)/2)/Math.sqrt(2*Math.PI)*volatility*eqt/(2*Math.sqrt(time)))+(interest*xert*nNegD2)-(dividend*price*nNegD2*eqt))/365;
}

return (-(price*Math.exp(-1*Math.pow(d1,2)/2)/Math.sqrt(2*Math.PI)*volatility*eqt/(2*Math.sqrt(time)))-(interest*xert*nd1)+(dividend*price*nd1*eqt))/365;

var nD2 = NORMDIST_(D2_(price, strike, volatility, interest, dividend, days));
return (-(price*Math.exp(-1*Math.pow(d1,2)/2)/Math.sqrt(2*Math.PI)*volatility*eqt/(2*Math.sqrt(time)))-(interest*xert*nD2)+(dividend*price*nD2*eqt))/365;
}


Expand All @@ -90,7 +91,7 @@ function OPTIONTHETA(price, strike, volatility, interest, dividend, days, option
function OPTIONVEGA(price, strike, volatility, interest, dividend, days) {
var d1 = D1_(price, strike, volatility, interest, dividend, days);
var time = days/365;
var eqt = Math.exp(-dividend * time);
var eqt = Math.exp(-interest * time);

return Math.exp(-1*Math.pow(d1,2)/2)/Math.sqrt(2*Math.PI)*eqt*price*Math.sqrt(time)/100;
}
Expand Down