README.md

GreenSim

Nested Green Simulation Algorithm.

Description

This package is an implementation of Nested Green Simulation Algorithm.

Suppose in a nested simulation setting, we simulate scenarios in the outer step and then estimate an objective function's expected value conditional on the corresponding outer scenario in the inner step. Nested Green Simulation Algorithm reuses samples from a single distribution to construct all inner scenarios' estimators via importance sampling.

Installation

Install GreenSim from GitHub:

library(devtools)
devtools::install_github("chenqi57/GreenSim")
library(GreenSim)

or directly from the GreenSim_1.1.0.tar.gz:

install.packages("GreenSim_1.1.0.tar.gz", repos = NULL, type = "source")
library(GreenSim)

Function

Fourteen functions are contained in this package. Seven functions are the implementation of nested Green Simulation methods, and the others are helper functions for density calculation, random varaible simulation and weight fitting.

Nested Green Simulation Methods

Density Calculation

Random Variable Simulation

Weight Fitting

Documentation

Documentations of the above functions can be accesed by typing ? before each function's name at the R command. For instance, the user can read the function NGS_MLR's arguments, output and examples in detail by typing ?NGS_MLR.

Example

Suppose you have a financial instrument consisting a zero-coupon bond with face value $10 and time-to-maturity one year, as well as a bonus of $10 if the underlying stock price S1 after one year from time 0 is greater than strike price K = 100. Hence, the objective function is h(x) = exp(-11r/12) [10 + 10I(S1>K)] where r is the annual risk-free rate.

We set up the function paramters in the following codes. ```r setup library(functional) r = 5e-2 # annual risk-free rate S0 = 100 # initial stock price vol = 30e-2 # annual volatility

tau = 1/12 # one month T = 1 # time-to-maturity from time 0

N_Out = 10 # number of outer scenarios N_In = 5e2 # number of inner scenarios

T2M = T - tau # time to maturity from outer scenario time

min <- qlnorm(1e-4, meanlog = (r-0.5vol^2)tau + log(S0), sdlog = (volsqrt(tau))) max <- qlnorm(1-1e-4, meanlog = (r-0.5vol^2)tau + log(S0), sdlog = (volsqrt(tau))) S_tau <- seq(from = min, to = max, length.out = N_Out) mu <- log(S_tau) + (r-0.5vol^2)T2M sig <- vol * sqrt(T2M) df <- Curry(dnorm, sd = sig) rf <- Curry(rnorm, sd = sig)

h = function(x){ return(exp(-T2Mr) * (10as.numeric(exp(x)>100)+10)) } # objective function M = 10 + 10 # upper bound sn = FALSE # without self-normalization


Then we use the `GreenSim` package to calculate the MLR, OIS, LS estimates as an example.
```r NGS
library(GreenSim)
MLR <- NGS_MLR(mu, df, rf, N_In, h, sn)
df_MLR <- data.frame(outer = S_tau, est = MLR, Method = rep("MLR", N_Out))

OIS <- NGS_OIS(mu, df, rf, N_In, h, M, sn)
df_OIS <- data.frame(outer = S_tau, est = OIS, Method = rep("OIS", N_Out))

LS <- NGS_LS(mu, df, rf, N_In, 0.8, h, sn)
df_LS <- data.frame(outer = S_tau, est = LS, Method = rep("LS", N_Out))

Finally we illustrate the estimates in the following plot. r plot library(ggplot2) df <- rbind(df_MLR, df_OIS, df_LS) ggplot(df) + geom_point(aes(x = outer, y = est, color = Method)) + labs(x = "Outer Scenario", y = "Estimated Fair Price", title = "Importance Sampling Estimates without Self-Normalization") + theme(plot.title = element_text(hjust = 0.5)) image



chenqi57/GreenSim documentation built on Dec. 19, 2021, 3:04 p.m.