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
> <[email protected] (mailto:[email protected])> 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 <[email protected] 
> > (mailto:[email protected])> 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 <[email protected] 
> > (mailto:[email protected])> 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
> >  
> > _______________________________________________
> > [email protected] (mailto:[email protected]) 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
> >  
> > _______________________________________________
> > [email protected] (mailto:[email protected]) 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
>  
>  



        [[alternative HTML version deleted]]

_______________________________________________
[email protected] 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.

Reply via email to