#' Indicator function of an interval
#'
#' @param x real variable input, usually representing space, position, price, log-price, etc.
#' @param lb lower-bound of interval, defaults to negative infinity
#' @param K upper-bound of interval
#' @description {The indicator function returns 1 if the input is in the interval and 0 otherwise.}
#' @details {If the indicator function of a Borel set \eqn{B} is used as the payoff then the Feynman-Kac formula yields the law of \eqn{X_T\in B} for a given initial condition.}
#' @return numeric
#' @export payoff_indicator
payoff_indicator <- function(x, lb = -Inf, K)
{
ifelse(x > lb && x <= K, 1, 0)
}
#' Indicator function of an half-infinite interval
#'
#' @param x real variable input, usually representing space, position, price, log-price, etc.
#' @param K upper-bound of interval
#' @description {The indicator function returns 1 if the input is in the interval and 0 otherwise.}
#' @details {If the indicator function of a Borel set \eqn{B} is used as the payoff then the Feynman-Kac formula yields the law of \eqn{X_T\in B} for a given initial condition.}
#' @return numeric
#' @export payoff_cdf
payoff_cdf <- function(x, K)
{
payoff_indicator(x, lb = -Inf, K = K)
}
#' Payoff of call-option
#'
#' @param x real input
#' @param K strike of option
#' @description {The payoff function of a call option.}
#' @details {The positive part of the input less the strike.}
#' @return numeric
#' @export payoff_call
payoff_call <- function(x, K)
{
pmax(x - K, 0)
}
#' Payoff of put-option
#'
#' @param x real input
#' @param K strike of option
#' @description {The payoff function of a put option.}
#' @details {The positive part of the strike less the input}
#' @return numeric
#' @export payoff_put
payoff_put <- function(x, K)
{
pmax(K - x, 0)
}
#' Payoff of straddle-option
#'
#' @param x real input
#' @param K strike of option
#' @description {The payoff function of a straddle option.}
#' @details {The sum of a put and call on the same strike price.}
#' @return numeric
#' @export payoff_straddle
payoff_straddle <- function(x, K){
payoff_call(x, K) + payoff_put(x, K)
}
#' Payoff of strangle-option
#'
#' @param x real input
#' @param strike.p strike of put option
#' @param strike.c strike of call option
#' @description {The payoff function of a strangle option.}
#' @details {The sum of a call and put payoff on two different strikes but same expiry and underlying}
#' @return numeric
#' @export payoff_strangle
payoff_strangle <- function(x, strike.p, strike.c)
{
payoff_call(x, strike.c) + payoff_put(x, strike.p)
}
#' Payoff of put debit spread
#'
#' @param x real input
#' @param strike1 the lower strike, to be short
#' @param strike2 the upper strike, to be long
#' @description {The payoff function of a put debit spread option.}
#' @details {Long an upper strike and short a lower strike of two puts}
#' @return numeric
#' @export payoff_put_debit
payoff_put_debit <- function(x, strike1, strike2)
{
# Input is given from low to high
# Buy high strike put, sell low strike put
payoff_put(x, strike2) - payoff_put(x, strike1)
}
#' Payoff of call debit spread
#'
#' @param x real input
#' @param strike1 the lower strike, to be long
#' @param strike2 the upper strike, to be short
#' @description {The payoff function of a put debit spread option.}
#' @details {Long a lower strike and short an upper strike of two puts}
#' @return numeric
#' @export payoff_call_debit
payoff_call_debit <- function(x, strike1, strike2)
{
# Input is given from low to high
# Buy low strike call, sell high strike call
payoff_call(x, strike1) - payoff_call(x, strike2)
}
#' Payoff of long iron condor option
#'
#' @param x real input
#' @param strike1 the lower put strike, to be short
#' @param strike2 the upper put strike, to be long
#' @param strike3 the lower call strike, to be long
#' @param strike4 the upper call strike, to be short
#' @description {The payoff function of a long iron condor option.}
#' @details {Sum of a put-debit spread and call-debit spread}
#' @return numeric
#' @export payoff_iron_condor
payoff_iron_condor <- function(x, strike1, strike2, strike3, strike4)
{
payoff_put_debit(x, strike1, strike2)+payoff_call_debit(x, strike3, strike4)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.