The purpose of this document is to present the results of the function getPutPrice from custom-made putOptionPricer (.Rcpp) package to calculate the theoretical value of put down and out option with a barrier active between the moment of pricing and the option expiry.
The put down and out option means that the barieer is set below the price, so the price has to decrease to reach the barrier and the option is cancelled when asset price reaches the barrier.
I present the relation between the theoretical price of the option and two factors(simultaneously):
The default values for the getPutPrice fucntion are:
The value of b was chosen to be 120 so as to slightly influence the valuation.
The Monte Carlo simulation iterations was set to 1000000.
As we can observe below, the price of the option is the most expensive when time to expire is the the shortest (0.01). It is because of the fact that the Strike price is higher then Spot price meaning that we start with a profit. The longer the time to maturity the lower the option price.
In accordance with the Honor Code, I certify that my answers here are my own work, and I did not make my solutions available to anyone else.
# Load packages
library(dplyr)
library(ggplot2)
library(tidyverse)
library(putOptionPricer)
# Build an R function: option price vs. time to maturity + volatility
getPutPriceExpiryVol <- function(expiry, vol){
return(putOptionPricer::getPutPrice(Expiry = expiry,
Vol = vol,
b = 120,
NumberOfPaths = 1000000))
}
# Define expiry and volatility lists
expiry <- seq(0.01, 0.99, by = 0.01)
vol <- seq(0.01, 0.24, by = 0.04)
# Initialize a matrix to store the results
prices_matrix <- matrix(nrow = length(expiry), ncol = length(vol))
# Loop over all combinations of expiry and volatility
for(i in 1:length(expiry)) {
for(j in 1:length(vol)) {
prices_matrix[i, j] <- getPutPriceExpiryVol(expiry[i], vol[j])
}
}
# Convert the matrix to a data frame for easier handling (optional)
prices_df <- as.data.frame(prices_matrix)
# Change the colnames
colnames(prices_df) <- vol
# Add Expiry column
prices_df$Expiry <- expiry
# Make the dataframe longer
prices_long <- prices_df %>%
pivot_longer(cols = -Expiry, names_to = "Volatility", values_to = "Price")
# Plot the prices vs maturity + volatility
ggplot(prices_long,
aes(x = Expiry, y = Price, color = as.factor(Volatility))) +
geom_line() +
labs(x = "Time to maturity",
y = "Put Option Price",
color = "Volatility") +
theme_minimal() +
scale_color_discrete(name = "Volatility") +
ggtitle("Option Price vs Time to maturity")