CustomDerivative {CustomDerivative} | R Documentation |
Custom Derivative R6 Class
Description
This class provides methods to create and price custom derivatives.
Details
An R6 class to create and price custom derivatives.
The class uses the Monte Carlo method for pricing. The price method simulates the underlying asset price paths and applies the payoff function to determine the option price.
Value
For price
, delta
, gamma
, theta
, vega
, and rho
: a numeric value.
Methods
- initialize(underlying_price, strike_price, time_to_maturity, volatility, risk_free_rate, payoff_function):
-
Constructor method. Initializes the parameters for the custom derivative.
- price():
-
Calculate the option price using the Monte Carlo method.
- delta():
-
Calculate the Delta of the option.
- gamma():
-
Calculate the Gamma of the option.
- theta():
-
Calculate the Theta of the option.
- vega():
-
Calculate the Vega of the option.
- rho():
-
Calculate the Rho of the option.
Public fields
underlying_price
The underlying asset price.
strike_price
The strike price of the option.
time_to_maturity
Time to maturity of the option.
volatility
The volatility of the underlying asset.
risk_free_rate
The risk-free rate.
payoff_function
The function that determines the payoff of the option.
Methods
Public methods
Method new()
Usage
CustomDerivative$new( underlying_price, strike_price, time_to_maturity, volatility, risk_free_rate, payoff_function )
Arguments
underlying_price
Initial price of the underlying asset.
strike_price
Strike price of the option.
time_to_maturity
Time to maturity in years.
volatility
Volatility of the underlying asset.
risk_free_rate
Risk-free rate (annual).
payoff_function
A function that calculates the option payoff. Calculate the option price using the Monte Carlo method.
Method price()
Usage
CustomDerivative$price()
Returns
Numeric value representing the option price. Calculate the Delta of the option.
Method delta()
Usage
CustomDerivative$delta()
Returns
Numeric value representing the Delta. Calculate the gamma of the option.
Method gamma()
Usage
CustomDerivative$gamma()
Returns
Numeric value representing the gamma Calculate the theta of the option.
Method theta()
Usage
CustomDerivative$theta()
Returns
Numeric value representing the theta Calculate the vega of the option.
Method vega()
Usage
CustomDerivative$vega()
Returns
Numeric value representing the vega Calculate the rho of the option.
Method rho()
Usage
CustomDerivative$rho()
Returns
Numeric value representing the rho
Method clone()
The objects of this class are cloneable with this method.
Usage
CustomDerivative$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# Define the payoff function for a European call option
call_payoff <- function(price) {
return(max(price - 100, 0))
}
# Create an instance of the CustomDerivative class
option <- CustomDerivative$new(100, 100, 1, 0.2, 0.05, call_payoff)
# Print Option Price and Greeks
cat("Option Price:", option$price(), "\n")
cat("Delta:", option$delta(), "\n")
cat("Gamma:", option$gamma(), "\n")
cat("Theta:", option$theta(), "\n")
cat("Vega:", option$vega(), "\n")
cat("Rho:", option$rho(), "\n")