R Studio

Option Surfaces

Posted on

## (European) Option Surfaces OptionSurface <- function(EOres, label, fov=60) { axis.col <- “black” text.col <- axis.col ylab <- label xlab <- “Underlying” zlab <- “Volatility” y <- EOres ## clear scene: clear3d() clear3d(type=”bbox”) clear3d(type=”lights”) ## setup env: ## bg3d(color=”#887777″) bg3d(color=”#DDDDDD”) light3d() rgl.viewpoint(fov=fov) ##rgl.bg(col=”white”, fogtype=”exp2″) ##rgl.bg(col=”black”, fogtype=”exp2″) ##rgl.bg(col=”black”, fogtype=”exp”) ##rgl.bg(col=”white”, fogtype=”exp”) x <- (1:nrow(y)) z <- […]

R Studio

Option Pricing Functions

Posted on

## Option pricing Functions EuropeanOption <- function(type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility) { UseMethod(“EuropeanOption”) } EuropeanOption.default <- function(type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility) { type <- match.arg(type, c(“call”, “put”)) val <- europeanOptionEngine(type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility) class(val) <- c(“EuropeanOption”, “Option”) val } AmericanOption <- function(type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility, […]

R Studio

Monte Carlo Simulation Step by Step Approach

Posted on

## How to perform a Monte Carlo Simulation? ## First Step: # Write a function to generate the option’s innovations. # Use scrambled normal Sobol numbers: sobolInnovations = function(mcSteps, pathLength, init, …) { # Create Normal Sobol Innovations: innovations = rnorm.sobol(mcSteps, pathLength, init, …) # Return Value: innovations } ## Second Step: # Write a […]

R Studio

MCS_Simulation

Posted on

# Monte Carlo Simulation / Simulation.r # basic parameters unit_cost <- 1.50 # per unit variable cost unit_price <- 4.00 # unit price per item unit_disp <- 0.20 # cost for the disposal of unsold inventories # simulate 3000 profits for 20K, 40K & 60K units each profit <- rep(NA, 3000) set.seed(1) for (i in […]

R Studio

MCS for single and multi assets

Posted on

# MCS for single and multi assets asset.paths <- function(s0, mu, sigma, nsims = 10000, periods = c(0, 1) # time periods at which to simulate prices ) { s0 = as.vector(s0) nsteps = len(periods) dt = c(periods[1], diff(periods)) if( len(s0) == 1 ) { drift = mu – 0.5 * sigma^2 if( nsteps == […]

R Studio

Hull_White_Calibration

Posted on

## model – # Define the Model Parameters for a Heston-Nandi Option: model = list(lambda = -0.5, omega = 2.3e-6, alpha = 2.9e-6, beta = 0.85, gamma = 184.25) S = X = 100 Time.inDays = 252 r.daily = 0.05/Time.inDays sigma.daily = sqrt((model$omega + model$alpha) / (1 – model$beta – model$alpha * model$gamma^2)) data.frame(S, X, […]

R Studio

Heston Nandi Garch_Greeks

Posted on

## model – # Define the Model Parameters for a Heston-Nandi Option: model = list(lambda = -0.5, omega = 2.3e-6, alpha = 2.9e-6, beta = 0.85, gamma = 184.25) S = X = 100 Time.inDays = 252 r.daily = 0.05/Time.inDays sigma.daily = sqrt((model$omega + model$alpha) / (1 – model$beta – model$alpha * model$gamma^2)) data.frame(S, X, […]

R Studio

Heston Nandi Garch

Posted on

## hngarchSim – # Simulate a Heston Nandi Garch(1,1) Process: # Symmetric Model – Parameters: model = list(lambda = 4, omega = 8e-5, alpha = 6e-5, beta = 0.7, gamma = 0, rf = 0) ts = hngarchSim(model = model, n = 500, n.start = 100) par(mfrow = c(2, 1), cex = 0.75) ts.plot(ts, col […]