R Studio

Arithmetic Asian Option

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 = (b-sigma*sigma/2)*delta.t + sigma*sqrt(delta.t)*eps
  # Return Value:
  path }

## Step 3: function for the payoff for an Asian Call or Put:
arithmeticAsianPayoff = function(path) {
  # Compute the Call/Put Payoff Value:
  SM = mean(S*exp(cumsum(path)))
  if (TypeFlag == "c") payoff = exp(-r*Time)*max(SM-X, 0)
  if (TypeFlag == "p") payoff = exp(-r*Time)*max(0, X-SM)
  # Return Value:
  payoff }

## Final Step: Set global parameters for the  option:
TypeFlag <<- "c"; S <Time <
  # Do the Asian Simulation with pseudo random numbers:
  mc = MonteCarloOption(delta.t=1/360, pathLength=30, mcSteps=5000,
                        mcLoops = 50, init = TRUE, innovations.gen = pseudoInnovations,
                        path.gen = wienerPath, payoff.calc = arithmeticAsianPayoff,
                        antithetic = TRUE, standardization = FALSE, trace = TRUE)
# Plot the MC Iteration Path:
par(mfrow = c(1, 1))
mcPrice = cumsum(mc)/(1:length(mc))
plot(mcPrice, type = "l", main = "Arithmetic Asian Option",
     xlab = "Monte Carlo Loops", ylab = "Option Price")