maybe :) Just dont use the function blindly. I have written it ages ago and it worked, but I used b = r-d, as this is a general BS vanilla option approach, well at least some book told me that. but the I realised that having r,d instead r,b is a bit more intuitive and all further developments were made this way, while copy pasting the code from this with a slight probability of accidental edits.
When building a framework you would never use a function which calculates more than you need. In c++ it is usually a class with methods to calculate greeks. I have done the same in R. It looked something like this: http://quant-day.blogspot.co.uk/2013/06/scenario-analysis-and-trading-options.html However I would do it whole different way if I was to do it again⦠Anyways, I do not know what are you up to, but if you are doing something more serious than simple playing with packages then writing your own functions when you can is always a good idea. Kind regards,-- Dominykas Grigonis On Thursday, 17 April 2014 at 20:50, Pedro Baltazar wrote: > Maybe with > > if (tau==0){ > out <- c(max(S0-K,0),rep(NA,8)) > colnames(out) <- > c("value","delta","lambda","gamma","vega","vomma","theta","rho","rhoQ") > }else{ > > and the > > Concise summary of valuation for EuropeanOption > value delta gamma vega theta rho divRho > 50 NA NA NA NA NA NA > > > > On Thu, Apr 17, 2014 at 7:49 PM, Dominykas Grigonis > <dominykasgrigo...@gmail.com (mailto:dominykasgrigo...@gmail.com)> wrote: > > I guess you have a point⦠> > > > vaBSgreeks <- function(S0, K, r, d, tau, vol, opt){ > > if (tau==0){ > > out <- rep(NA,9) > > colnames(out) <- > > c("value","delta","lambda","gamma","vega","vomma","theta","rho","rhoQ") > > }else{ > > b = r-d > > d_1 <- (log(S0/K)+(b+vol^2/2)*tau)/(vol*sqrt(tau)); > > d_2 <- (log(S0/K)+(b-vol^2/2)*tau)/(vol*sqrt(tau)); > > if(opt==0){ > > value <- S0*exp(-d*tau)*stats::pnorm( > > d_1,0,1)-K*exp(-r*tau)*stats::pnorm(d_2,0,1) > > delta <- exp(-d*tau)*stats::pnorm( d_1,0,1) > > gamma <- > > (1/sqrt(2*pi)*exp(-d_1^2/2))/(S0*vol*sqrt(tau))*exp(-d*tau) > > vega <- S0*sqrt(tau)*(1/sqrt(2*pi)*exp(-d_1^2/2))*exp(-d*tau) > > vomma <- vega*d_1*d_2/vol > > theta <- > > -S0*(1/sqrt(2*pi)*exp(-d_1^2/2))*vol*exp(-d*tau)/(2*sqrt(tau))+ > > > > d*S0*stats::pnorm(d_1,0,1)*exp(-d*tau)-r*K*exp(-r*tau)*stats::pnorm(d_2,0,1) > > rho <- K*tau*exp(-r*tau)*stats::pnorm(d_2,0,1) > > rhoQ <- -tau*exp(-d*tau)*S0*stats::pnorm(d_1,0,1) > > lambda <- delta*S0/value > > }else if(opt==1){ > > value <- > > -S0*exp(-d*tau)*stats::pnorm(-d_1,0,1)+K*exp(-r*tau)*stats::pnorm(-d_2,0,1) > > delta <- -exp(-d*tau)*stats::pnorm(-d_1,0,1) > > gamma <- > > (1/sqrt(2*pi)*exp(-d_1^2/2))/(S0*vol*sqrt(tau))*exp(-d*tau) > > vega <- S0*sqrt(tau)*(1/sqrt(2*pi)*exp(-d_1^2/2))*exp(-d*tau) > > vomma <- vega*d_1*d_2/vol > > theta <- > > -S0*(1/sqrt(2*pi)*exp(-d_1^2/2))*vol*exp(-d*tau)/(2*sqrt(tau))- > > > > d*S0*stats::pnorm(-d_1,0,1)*exp(-d*tau)+r*K*exp(-r*tau)*stats::pnorm(-d_2,0,1) > > rho <- -K*tau*exp(-r*tau)*stats::pnorm(-d_2,0,1) > > rhoQ <- tau*exp(-d*tau)*S0*stats::pnorm(-d_1,0,1) > > lambda <- delta*S0/value > > }else{ > > stop("opt=0 means CALL; opt=1 means PUT") > > } > > return(cbind(value,delta,lambda,gamma,vega,vomma,theta,rho,rhoQ)) > > } > > } > > > > vaBSgreeks(100,100,0.05,0.05,1, 0.1,0) > > > > > > Kind regards, > > -- > > Dominykas Grigonis > > > > On Thursday, 17 April 2014 at 15:11, Pedro Baltazar wrote: > > > > If they don't exists the function should return NA, right? > > > > On Thu, Apr 17, 2014 at 2:38 PM, Dominykas Grigonis > > <dominykasgrigo...@gmail.com (mailto:dominykasgrigo...@gmail.com)> wrote: > > > > Theoretically greeks at maturity do not exist. If you want this, then you > > could just write your own if statement: value = max(S-K,0), delta = > > ifelse(S>K,1,0), gamma = ifelse(S=K, Inf, 0), vega = 0, theta =0?, rho = 0, > > divRho = 0 > > > > > > Kind regards, > > -- > > Dominykas Grigonis > > > > On Thursday, 17 April 2014 at 14:14, Pedro Baltazar wrote: > > > > The "theoretical" value of a call option at maturity is max(S-K,0). > > > > So, I am wondering if there is any a implementation justification not > > to put an some extra "if"s to check this corner cases > > > > Also, when using this function to calibrate other quantitities (where > > maturity is a variable) the fact that it gives zero for maturity=0, > > might have impact in finding max ou min. > > > > Thanks > > > > On Thu, Apr 17, 2014 at 2:04 PM, Ryan Abbate <ryan.abb...@gmail.com > > (mailto:ryan.abb...@gmail.com)> wrote: > > > > The reason is that you define the maturity date as zero, even though this > > particular option is otherwise in-the-money. Try entering maturity = 1 and > > you'll have values that are intuitive. > > > > Hope this helps. > > -Ryan > > > > > > On Thu, Apr 17, 2014 at 8:54 AM, Pedro Baltazar <pedro...@gmail.com > > (mailto:pedro...@gmail.com)> wrote: > > > > > > Hello, > > > > why this package gives the value zero, and not (underlying - strike) = > > 50, at maturity? > > > > EuropeanOption("call", underlying=150, strike=100, dividendYield=0.00, > > riskFreeRate=0.03, maturity=0.0,volatility=0.2) > > > > Concise summary of valuation for EuropeanOption > > value delta gamma vega theta rho divRho > > 0 0 0 0 0 0 0 > > > > Thanks > > > > -- > > Pedro Baltazar > > > > _______________________________________________ > > R-SIG-Finance@r-project.org (mailto:R-SIG-Finance@r-project.org) mailing > > list > > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > > -- Subscriber-posting only. If you want to post, subscribe first. > > -- Also note that this is not the r-help list where general R questions > > should go. > > > > > > > > > > -- > > Pedro Baltazar > > > > _______________________________________________ > > R-SIG-Finance@r-project.org (mailto:R-SIG-Finance@r-project.org) mailing > > list > > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > > -- Subscriber-posting only. If you want to post, subscribe first. > > -- Also note that this is not the r-help list where general R questions > > should go. > > > > > > > > > > -- > > Pedro Baltazar > > > > > > > -- > Pedro Baltazar > > [[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.