From 72d149832c90d96a158d7af8cf3ce326130c374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Thu, 13 Feb 2014 23:47:34 -0500 Subject: [PATCH] ajouts Epps --- .Rbuildignore | 2 ++ .gitignore | 1 + DESCRIPTION | 5 +++-- NAMESPACE | 0 R/parity.R | 7 +++---- R/putEpps.R | 38 ++++++++++++++++++++++++++++++++++++++ man/parity.Rd | 30 ++++++++++++++++++++++++++++++ man/putEpps.Rd | 36 ++++++++++++++++++++++++++++++++++++ man/zerobond.Rd | 30 ++++++++++++++++++++++++++++++ 9 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 .Rbuildignore create mode 100644 NAMESPACE create mode 100644 R/putEpps.R create mode 100644 man/parity.Rd create mode 100644 man/putEpps.Rd create mode 100644 man/zerobond.Rd diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..91114bf --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,2 @@ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/.gitignore b/.gitignore index a0fd3b3..6c38bf7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ # Example code in package build process *-Ex.R +.Rproj.user diff --git a/DESCRIPTION b/DESCRIPTION index d7a9399..190dd1a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,8 @@ Version: 0.1 Date: 2014-02-11 Author: Francois Pelletier Maintainer: Francois Pelletier -Description: This is a package gathering different functions to work with option pricing +Description: This is a package gathering different functions to work with + option pricing Suggests: MASS -License: LGPL-3 \ No newline at end of file +License: LGPL-3 diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..e69de29 diff --git a/R/parity.R b/R/parity.R index e33eecb..11de830 100644 --- a/R/parity.R +++ b/R/parity.R @@ -8,7 +8,6 @@ #' Put-Call Parity #' @param optionvalue Option price -#' @param stockprice Stock price #' @param strikeprice Strike price #' @param eval.time Evaluation time #' @param expiry.time Expiry time @@ -17,15 +16,15 @@ #' @return Option price #' #' @author François Pelletier -parity <- function(optionvalue,stockprice,strikeprice,eval.time,expiry.time,rate,toPut=TRUE) +parity <- function(optionvalue,strikeprice,eval.time,expiry.time,rate,toPut=TRUE) { if(toPut) { - optionvalue-stockprice+strikeprice*zerobond(eval.time,expiry.time,rate) + optionvalue-1+strikeprice*zerobond(eval.time,expiry.time,rate) } else { - stockprice+optionvalue-strikeprice*zerobond(eval.time,expiry.time,rate) + 1+optionvalue-strikeprice*zerobond(eval.time,expiry.time,rate) } } diff --git a/R/putEpps.R b/R/putEpps.R new file mode 100644 index 0000000..5ae6c8d --- /dev/null +++ b/R/putEpps.R @@ -0,0 +1,38 @@ +# European put option pricing using characteristic function +# +# Author: Francois Pelletier +# +# LGPL 3.0 +############################################################################### + +#' European put option pricing using characteristic function +#' +#' As seen in Epps (2009) +#' @param char.fn Characteristic function of the price level at expiry time +#' @param strikeprice Strike price, relative to a unit stock price +#' @param eval.time Evaluation time +#' @param expiry.time Expiry time +#' @param rate Continuously compounded interest rate (force of interest) +#' @param ... Parameters of the characteristic function +#' @param int.bounds Integration bounds for the integrate() method used. Defaults to infinite bounds. +#' @return European put option price +#' +#' @author Francois Pelletier +putEpps <- function(char.fn,strikeprice,eval.time,expiry.time,rate,...,int.bounds=c(-Inf,Inf)) +{ + # function to integrate (zhi) + zhi <- function(x,char.fn,strikeprice,eval.time,expiry.time,rate,...) + { + Re(strikeprice^{-1i*x} * + char.fn(x,strikeprice,eval.time,expiry.time,rate,...) / + (x*(1i+x))) + } + # function to integrate with strike price as first parameter + integrate.K <- function(strikeprice,zhi,int.bounds,eval.time,expiry.time,rate,...) + { + exp(-rate*(expiry.time-eval.time)) * + strikeprice * + (.5 - integrate(zhi,int.bounds[1],int.bounds[2],strikeprice,eval.time,expiry.time,rate,...)$value / (2*pi)) + } + mclapply(as.vector(strikeprice),integrate.K,zhi,int.bounds,eval.time,expiry.time,rate,...) +} \ No newline at end of file diff --git a/man/parity.Rd b/man/parity.Rd new file mode 100644 index 0000000..2f7b33f --- /dev/null +++ b/man/parity.Rd @@ -0,0 +1,30 @@ +\name{parity} +\alias{parity} +\title{Put-Call Parity} +\usage{ +parity(optionvalue, strikeprice, eval.time, expiry.time, rate, toPut = TRUE) +} +\arguments{ + \item{optionvalue}{Option price} + + \item{strikeprice}{Strike price} + + \item{eval.time}{Evaluation time} + + \item{expiry.time}{Expiry time} + + \item{rate}{Continuously compounded interest rate (force + of interest)} + + \item{toPut}{Boolean, Call to Put or Put to Call ?} +} +\value{ +Option price +} +\description{ +Put-Call Parity +} +\author{ +François Pelletier +} + diff --git a/man/putEpps.Rd b/man/putEpps.Rd new file mode 100644 index 0000000..92cb8b9 --- /dev/null +++ b/man/putEpps.Rd @@ -0,0 +1,36 @@ +\name{putEpps} +\alias{putEpps} +\title{European put option pricing using characteristic function} +\usage{ +putEpps(char.fn, strikeprice, eval.time, expiry.time, rate, ..., + int.bounds = c(-Inf, Inf)) +} +\arguments{ + \item{char.fn}{Characteristic function of the price level + at expiry time} + + \item{strikeprice}{Strike price, relative to a unit stock + price} + + \item{eval.time}{Evaluation time} + + \item{expiry.time}{Expiry time} + + \item{rate}{Continuously compounded interest rate (force + of interest)} + + \item{...}{Parameters of the characteristic function} + + \item{int.bounds}{Integration bounds for the integrate() + method used. Defaults to infinite bounds.} +} +\value{ +European put option price +} +\description{ +As seen in Epps (2009) +} +\author{ +Francois Pelletier +} + diff --git a/man/zerobond.Rd b/man/zerobond.Rd new file mode 100644 index 0000000..77d8f04 --- /dev/null +++ b/man/zerobond.Rd @@ -0,0 +1,30 @@ +\name{zerobond} +\alias{zerobond} +\title{zerobond} +\usage{ +zerobond(eval.time, expiry.time, rate, face = 1) +} +\arguments{ + \item{eval.time}{Evaluation time} + + \item{expiry.time}{Expiry time} + + \item{rate}{Continuously compounded interest rate (force + of interest)} + + \item{face}{Face value} +} +\value{ +Actualised price of bond +} +\description{ +Evaluate the price of a zero coupon bond +} +\details{ +Evaluates the actualised price of a bond using interest +rate and face value +} +\author{ +François Pelletier +} +