[R-SIG-Finance] options profit/loss graph (beginner question)

Enrico Schumann enricoschumann at yahoo.de
Fri Nov 25 10:46:20 CET 2011


Hi Uwe

Am 25.11.2011 09:05, schrieb Uwe Voelker:
>
> I'm completely new to R, but I hope it is good suited for this task. I

It is (but you will have to learn a bit about using it).

> found fOptions from rmetrics package, but it only evaluates options.
> I'm missing the link to the graph/plot. I googled a lot and could not

The "link" is the graphics and plotting capabilities that come with R. 
Start with ?plot.

>
> Can you please point me to an example?

Here is a very simple example:

## a call under Black--Scholes--Merton
callBSM <- function(S,X,tau,r,q,vol) {
     if (tau > 0) {
         d1 <- (log(S/X) + (r - q + vol^2 / 2)*tau) / (vol*sqrt(tau))
         d2 <- d1 - vol*sqrt(tau)
         S * exp(-q * tau) * pnorm(d1) - X * exp(-r * tau) * pnorm(d2)
     } else {
         pmax(S-X,0)
     }

}

## now
S <- 70:130 ## evaluate for these spot prices
X <- 100; tau <- 1; r <- 0.02; q <- 0.01; vol  <- 0.2
plot(S, callBSM(S,X,tau,r,q,vol), col = grey(.7), type="l", ylab = "payoff")

## some time later
tau <- 0.5
lines(S, callBSM(S,X,tau,r,q,vol), col = grey(.5), type="l")

## expiry
tau <- 0
lines(S, callBSM(S,X,tau,r,q,vol), col = grey(.3), type="l")


##
... or you may want to have a look at
http://dirk.eddelbuettel.com/code/rquantlib.html

Regards,
Enrico



>
> Thanks a lot,
> with kind regards,
> Uwe
>
> _______________________________________________
> R-SIG-Finance at 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.
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/



More information about the R-SIG-Finance mailing list