R Studio

Gaussian_Copula vs t_Copula

Posted on

library(copula) # declare a Gaussian copula class with a 0.7 correlation norm.cop <- normalCopula(0.7) # generate 500 realizations of two uniformly distributed random variables # with the Gaussian copula dependency structure set.seed(117) u1 <- rCopula(500, norm.cop) # define a t-copula class with a 0.7 correlation and 4 degrees of freedom t.cop <- tCopula(0.7, df = […]

R Studio

CRR_BS Convergence

Posted on

#Simulation install.packages.(“sde”) # Brownian motion is very easy to simulate. To start off, let’s simulate a single instance of # Brownian motion for 100 generations of discrete time in which the variance of the diffusion # process is ??2 = 0.01 per generation. t <- 0:100 # time sig2 <- 0.01 ## first, simulate a […]

R Studio

Brownian Motion Simulation

Posted on

#Simulation install.packages.(“sde”) # Brownian motion is very easy to simulate. To start off, let’s simulate a single instance of # Brownian motion for 100 generations of discrete time in which the variance of the diffusion # process is ??2 = 0.01 per generation. t <- 0:100 # time sig2 <- 0.01 ## first, simulate a […]

R Studio

Bermudan swaption valuation using several short-rate models

Posted on

## Bermudan swaption valuation using several short-rate models # This data replicates sample code shipped with QuantLib 0.3.10 results params <- list(tradeDate=as.Date(‘2002-2-15’), settleDate=as.Date(‘2002-2-19’), startDate=as.Date(‘2003-2-19’), maturity=as.Date(‘2008-2-19’), dt=.25, payFixed=TRUE, strike=.05, method=”G2Analytic”, interpWhat=”discount”, interpHow=”loglinear”) setEvaluationDate(as.Date(‘2002-2-15’)) # Market data used to construct the term structure of interest rates tsQuotes <- list(d1w =0.05, # d1m =0.0372, # fut1=96.2875, # fut2=96.7875, […]

R Studio

Bermudan Swaption Function

Posted on

## RQuantLib function BermudanSwaption ## ## BermudanSwaption <- function(params, ts, swaptionMaturities, swapTenors, volMatrix) { UseMethod(“BermudanSwaption”) } BermudanSwaption.default <- function(params, ts, swaptionMaturities, swapTenors, volMatrix) { # Check that params list names if (!is.list(params) || length(params) == 0) { stop(“The params parameter must be a non-empty list”, call.=FALSE) } if(is.null(params$startDate)){ params$startDate=advance(“UnitedStates”,params$tradeDate, 1, 3) warning(“swaption start date not […]

R Studio

Arithmetic Asian Option

Posted on

library(fOptions) ## MC simulation ## Step 1: function to generate the option’s innovations. ## Use normal pseudo random numbers pseudoInnovations = function(mcSteps, pathLength,init){ #Create normal pseudo random numbers innovations = rnorm.pseudo(mcSteps, pathLength,init) #Return value innovations } ## Step 2: function to generate the option’s price paths. wienerPath = function(eps) { # Generate the Paths: path […]