finMath lib documentation

net.finmath.functions
Class AnalyticFormulas

java.lang.Object
  extended by net.finmath.functions.AnalyticFormulas

public class AnalyticFormulas
extends Object

This class implements some functions as static class methods. It provides functions like

Version:
1.9
Author:
Christian Fries
Date:
27.04.2012

Method Summary
static double bachelierOptionImpliedVolatility(double forward, double optionMaturity, double optionStrike, double payoffUnit, double optionValue)
          Calculates the Bachelier option implied volatility of a call, i.e., the payoff max(S(T)-K,0), where S follows a normal process with constant volatility.
static double bachelierOptionValue(double forward, double volatility, double optionMaturity, double optionStrike, double payoffUnit)
          Calculates the option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a normal process with constant volatility, i.e., a Bachelier model.
static RandomVariableInterface bachelierOptionValue(RandomVariableInterface forward, RandomVariableInterface volatility, double optionMaturity, double optionStrike, RandomVariableInterface payoffUnit)
          Calculates the option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a normal process with constant volatility, i.e., a Bachelier model.
static double blackModelCapletValue(double forward, double volatility, double optionMaturity, double optionStrike, double periodLength, double discountFactor)
          Calculate the value of a caplet assuming the Black'76 model.
static double blackModelDgitialCapletValue(double forward, double volatility, double periodLength, double discountFactor, double optionMaturity, double optionStrike)
          Calculate the value of a digital caplet assuming the Black'76 model.
static double blackModelSwaptionValue(double forwardSwaprate, double volatility, double optionMaturity, double optionStrike, double swapAnnuity)
          Calculate the value of a swaption assuming the Black'76 model.
static double blackScholesATMOptionValue(double volatility, double optionMaturity, double forward, double payoffUnit)
          Calculates the Black-Scholes option value of an atm call option.
static double blackScholesDigitalOptionDelta(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          Calculates the delta of a digital option under a Black-Scholes model
static double blackScholesDigitalOptionValue(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          Calculates the Black-Scholes option value of a digital call option.
static double blackScholesGeneralizedOptionValue(double forward, double volatility, double optionMaturity, double optionStrike, double payoffUnit)
          Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a log-normal process with constant log-volatility.
static RandomVariableInterface blackScholesGeneralizedOptionValue(RandomVariableInterface forward, RandomVariableInterface volatility, double optionMaturity, double optionStrike, RandomVariableInterface payoffUnit)
          Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a log-normal process with constant log-volatility.
static double blackScholesOptionDelta(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero.
static RandomVariableInterface blackScholesOptionDelta(RandomVariableInterface initialStockValue, RandomVariableInterface riskFreeRate, RandomVariableInterface volatility, double optionMaturity, double optionStrike)
          Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero.
static RandomVariableInterface blackScholesOptionDelta(RandomVariableInterface initialStockValue, RandomVariableInterface riskFreeRate, RandomVariableInterface volatility, double optionMaturity, RandomVariableInterface optionStrike)
          Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero.
static double blackScholesOptionGamma(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          This static method calculated the gamma of a call option under a Black-Scholes model
static RandomVariableInterface blackScholesOptionGamma(RandomVariableInterface initialStockValue, RandomVariableInterface riskFreeRate, RandomVariableInterface volatility, double optionMaturity, double optionStrike)
          This static method calculated the gamma of a call option under a Black-Scholes model
static double blackScholesOptionImpliedVolatility(double forward, double optionMaturity, double optionStrike, double payoffUnit, double optionValue)
          Calculates the Black-Scholes option implied volatility of a call, i.e., the payoff max(S(T)-K,0), where S follows a log-normal process with constant log-volatility.
static double blackScholesOptionRho(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          This static method calculated the rho of a call option under a Black-Scholes model
static double blackScholesOptionValue(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0), where S follows a log-normal process with constant log-volatility.
static double blackScholesOptionVega(double initialStockValue, double riskFreeRate, double volatility, double optionMaturity, double optionStrike)
          This static method calculated the vega of a call option under a Black-Scholes model
static double huntKennedyCMSAdjustedRate(double forwardSwaprate, double volatility, double swapAnnuity, double optionMaturity, double swapMaturity, double payoffUnit)
          Calculate the adjusted forward swaprate corresponding to a change of payoff unit from the given swapAnnuity to the given payoffUnit using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.
static double huntKennedyCMSFloorValue(double forwardSwaprate, double volatility, double swapAnnuity, double optionMaturity, double swapMaturity, double payoffUnit, double optionStrike)
          Calculate the value of a CMS strike using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.
static double huntKennedyCMSOptionValue(double forwardSwaprate, double volatility, double swapAnnuity, double optionMaturity, double swapMaturity, double payoffUnit, double optionStrike)
          Calculate the value of a CMS option using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.
static double margrabeExchangeOptionValue(double spot1, double spot2, double volatility1, double volatility2, double correlation, double optionMaturity)
          Calculates the value of an Exchange option under a generalized Black-Scholes model, i.e., the payoff \( max(S_{1}(T)-S_{2}(T),0) \), where \( S_{1} \) and \( S_{2} \) follow a log-normal process with constant log-volatility and constant instantaneous correlation.
static double price(Date settlementDate, Date maturityDate, double coupon, double yield, double redemption, int frequency)
          Re-implementation of the Excel PRICE function (a rather primitive bond price formula).
static double price(double timeToMaturity, double coupon, double yield, double redemption, int frequency)
          Re-implementation of the Excel PRICE function (a rather primitive bond price formula).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

blackScholesGeneralizedOptionValue

public static double blackScholesGeneralizedOptionValue(double forward,
                                                        double volatility,
                                                        double optionMaturity,
                                                        double optionStrike,
                                                        double payoffUnit)
Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a log-normal process with constant log-volatility. The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward and/or the option strike is zero.

Parameters:
forward - The forward of the underlying.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike. If the option strike is ≤ 0.0 the method returns the value of the forward contract paying S(T)-K in T.
payoffUnit - The payoff unit (e.g., the discount factor)
Returns:
Returns the value of a European call option under the Black-Scholes model.

blackScholesGeneralizedOptionValue

public static RandomVariableInterface blackScholesGeneralizedOptionValue(RandomVariableInterface forward,
                                                                         RandomVariableInterface volatility,
                                                                         double optionMaturity,
                                                                         double optionStrike,
                                                                         RandomVariableInterface payoffUnit)
Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a log-normal process with constant log-volatility. The model specific quantities are considered to be random variable, i.e., the function may calculate an per-path valuation in a single call.

Parameters:
forward - The forward of the underlying.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike. If the option strike is ≤ 0.0 the method returns the value of the forward contract paying S(T)-K in T.
payoffUnit - The payoff unit (e.g., the discount factor)
Returns:
Returns the value of a European call option under the Black-Scholes model.

blackScholesOptionValue

public static double blackScholesOptionValue(double initialStockValue,
                                             double riskFreeRate,
                                             double volatility,
                                             double optionMaturity,
                                             double optionStrike)
Calculates the Black-Scholes option value of a call, i.e., the payoff max(S(T)-K,0), where S follows a log-normal process with constant log-volatility.

Parameters:
initialStockValue - The spot value of the underlying.
riskFreeRate - The risk free rate r (df = exp(-r T)).
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike. If the option strike is ≤ 0.0 the method returns the value of the forward contract paying S(T)-K in T.
Returns:
Returns the value of a European call option under the Black-Scholes model.

blackScholesATMOptionValue

public static double blackScholesATMOptionValue(double volatility,
                                                double optionMaturity,
                                                double forward,
                                                double payoffUnit)
Calculates the Black-Scholes option value of an atm call option.

Parameters:
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
forward - The forward, i.e., the expectation of the index under the measure associated with payoff unit.
payoffUnit - The payoff unit, i.e., the discount factor or the anuity associated with the payoff.
Returns:
Returns the value of a European at-the-money call option under the Black-Scholes model

blackScholesOptionDelta

public static double blackScholesOptionDelta(double initialStockValue,
                                             double riskFreeRate,
                                             double volatility,
                                             double optionMaturity,
                                             double optionStrike)
Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero. In the case forward = option strike = 0 the method returns 1.0.

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The delta of the option

blackScholesOptionDelta

public static RandomVariableInterface blackScholesOptionDelta(RandomVariableInterface initialStockValue,
                                                              RandomVariableInterface riskFreeRate,
                                                              RandomVariableInterface volatility,
                                                              double optionMaturity,
                                                              double optionStrike)
Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero. In the case forward = option strike = 0 the method returns 1.0.

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The delta of the option

blackScholesOptionDelta

public static RandomVariableInterface blackScholesOptionDelta(RandomVariableInterface initialStockValue,
                                                              RandomVariableInterface riskFreeRate,
                                                              RandomVariableInterface volatility,
                                                              double optionMaturity,
                                                              RandomVariableInterface optionStrike)
Calculates the delta of a call option under a Black-Scholes model The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward or the option strike is zero. In the case forward = option strike = 0 the method returns 1.0.

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The delta of the option

blackScholesOptionGamma

public static double blackScholesOptionGamma(double initialStockValue,
                                             double riskFreeRate,
                                             double volatility,
                                             double optionMaturity,
                                             double optionStrike)
This static method calculated the gamma of a call option under a Black-Scholes model

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The gamma of the option

blackScholesOptionGamma

public static RandomVariableInterface blackScholesOptionGamma(RandomVariableInterface initialStockValue,
                                                              RandomVariableInterface riskFreeRate,
                                                              RandomVariableInterface volatility,
                                                              double optionMaturity,
                                                              double optionStrike)
This static method calculated the gamma of a call option under a Black-Scholes model

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The gamma of the option

blackScholesOptionVega

public static double blackScholesOptionVega(double initialStockValue,
                                            double riskFreeRate,
                                            double volatility,
                                            double optionMaturity,
                                            double optionStrike)
This static method calculated the vega of a call option under a Black-Scholes model

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The vega of the option

blackScholesOptionRho

public static double blackScholesOptionRho(double initialStockValue,
                                           double riskFreeRate,
                                           double volatility,
                                           double optionMaturity,
                                           double optionStrike)
This static method calculated the rho of a call option under a Black-Scholes model

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The rho of the option

blackScholesOptionImpliedVolatility

public static double blackScholesOptionImpliedVolatility(double forward,
                                                         double optionMaturity,
                                                         double optionStrike,
                                                         double payoffUnit,
                                                         double optionValue)
Calculates the Black-Scholes option implied volatility of a call, i.e., the payoff

max(S(T)-K,0)

, where S follows a log-normal process with constant log-volatility.

Parameters:
forward - The forward of the underlying.
optionMaturity - The option maturity T.
optionStrike - The option strike. If the option strike is ≤ 0.0 the method returns the value of the forward contract paying S(T)-K in T.
payoffUnit - The payoff unit (e.g., the discount factor)
optionValue - The option value.
Returns:
Returns the implied volatility of a European call option under the Black-Scholes model.

blackScholesDigitalOptionValue

public static double blackScholesDigitalOptionValue(double initialStockValue,
                                                    double riskFreeRate,
                                                    double volatility,
                                                    double optionMaturity,
                                                    double optionStrike)
Calculates the Black-Scholes option value of a digital call option.

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
Returns the value of a European call option under the Black-Scholes model

blackScholesDigitalOptionDelta

public static double blackScholesDigitalOptionDelta(double initialStockValue,
                                                    double riskFreeRate,
                                                    double volatility,
                                                    double optionMaturity,
                                                    double optionStrike)
Calculates the delta of a digital option under a Black-Scholes model

Parameters:
initialStockValue - The initial value of the underlying, i.e., the spot.
riskFreeRate - The risk free rate of the bank account numerarie.
volatility - The Black-Scholes volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
Returns:
The delta of the digital option

blackModelCapletValue

public static double blackModelCapletValue(double forward,
                                           double volatility,
                                           double optionMaturity,
                                           double optionStrike,
                                           double periodLength,
                                           double discountFactor)
Calculate the value of a caplet assuming the Black'76 model.

Parameters:
forward - The forward (spot).
volatility - The Black'76 volatility.
optionMaturity - The option maturity
optionStrike - The option strike.
periodLength - The period length of the underlying forward rate.
discountFactor - The discount factor corresponding to the payment date (option maturity + period length).
Returns:
Returns the value of a caplet under the Black'76 model

blackModelDgitialCapletValue

public static double blackModelDgitialCapletValue(double forward,
                                                  double volatility,
                                                  double periodLength,
                                                  double discountFactor,
                                                  double optionMaturity,
                                                  double optionStrike)
Calculate the value of a digital caplet assuming the Black'76 model.

Parameters:
forward - The forward (spot).
volatility - The Black'76 volatility.
periodLength - The period length of the underlying forward rate.
discountFactor - The discount factor corresponding to the payment date (option maturity + period length).
optionMaturity - The option maturity
optionStrike - The option strike.
Returns:
Returns the price of a digital caplet under the Black'76 model

blackModelSwaptionValue

public static double blackModelSwaptionValue(double forwardSwaprate,
                                             double volatility,
                                             double optionMaturity,
                                             double optionStrike,
                                             double swapAnnuity)
Calculate the value of a swaption assuming the Black'76 model.

Parameters:
forwardSwaprate - The forward (spot)
volatility - The Black'76 volatility.
optionMaturity - The option maturity.
optionStrike - The option strike.
swapAnnuity - The swap annuity corresponding to the underlying swap.
Returns:
Returns the value of a Swaption under the Black'76 model

margrabeExchangeOptionValue

public static double margrabeExchangeOptionValue(double spot1,
                                                 double spot2,
                                                 double volatility1,
                                                 double volatility2,
                                                 double correlation,
                                                 double optionMaturity)
Calculates the value of an Exchange option under a generalized Black-Scholes model, i.e., the payoff \( max(S_{1}(T)-S_{2}(T),0) \), where \( S_{1} \) and \( S_{2} \) follow a log-normal process with constant log-volatility and constant instantaneous correlation. The method also handles cases where the forward and/or option strike is negative and some limit cases where the forward and/or the option strike is zero.

Parameters:
spot1 - Value of \( S_{1}(0) \)
spot2 - Value of \( S_{2}(0) \)
volatility1 - Volatility of \( \log(S_{1}(t)) \)
volatility2 - Volatility of \( \log(S_{2}(t)) \)
correlation - Instantaneous correlation of \( \log(S_{1}(t)) \) and \( \log(S_{2}(t)) \)
optionMaturity - The option maturity \( T \).
Returns:
Returns the value of a European exchange option under the Black-Scholes model.

bachelierOptionValue

public static double bachelierOptionValue(double forward,
                                          double volatility,
                                          double optionMaturity,
                                          double optionStrike,
                                          double payoffUnit)
Calculates the option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a normal process with constant volatility, i.e., a Bachelier model.

Parameters:
forward - The forward of the underlying.
volatility - The Bachelier volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
payoffUnit - The payoff unit (e.g., the discount factor)
Returns:
Returns the value of a European call option under the Bachelier model.

bachelierOptionValue

public static RandomVariableInterface bachelierOptionValue(RandomVariableInterface forward,
                                                           RandomVariableInterface volatility,
                                                           double optionMaturity,
                                                           double optionStrike,
                                                           RandomVariableInterface payoffUnit)
Calculates the option value of a call, i.e., the payoff max(S(T)-K,0) P, where S follows a normal process with constant volatility, i.e., a Bachelier model.

Parameters:
forward - The forward of the underlying.
volatility - The Bachelier volatility.
optionMaturity - The option maturity T.
optionStrike - The option strike.
payoffUnit - The payoff unit (e.g., the discount factor)
Returns:
Returns the value of a European call option under the Bachelier model.

bachelierOptionImpliedVolatility

public static double bachelierOptionImpliedVolatility(double forward,
                                                      double optionMaturity,
                                                      double optionStrike,
                                                      double payoffUnit,
                                                      double optionValue)
Calculates the Bachelier option implied volatility of a call, i.e., the payoff

max(S(T)-K,0)

, where S follows a normal process with constant volatility.

Parameters:
forward - The forward of the underlying.
optionMaturity - The option maturity T.
optionStrike - The option strike. If the option strike is ≤ 0.0 the method returns the value of the forward contract paying S(T)-K in T.
payoffUnit - The payoff unit (e.g., the discount factor)
optionValue - The option value.
Returns:
Returns the implied volatility of a European call option under the Bachelier model.

huntKennedyCMSOptionValue

public static double huntKennedyCMSOptionValue(double forwardSwaprate,
                                               double volatility,
                                               double swapAnnuity,
                                               double optionMaturity,
                                               double swapMaturity,
                                               double payoffUnit,
                                               double optionStrike)
Calculate the value of a CMS option using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.

Parameters:
forwardSwaprate - The forward swap rate
volatility - Volatility of the log of the swap rate
swapAnnuity - The swap annuity
optionMaturity - The option maturity
swapMaturity - The swap maturity
payoffUnit - The payoff unit, e.g., the discount factor corresponding to the payment date
optionStrike - The option strike
Returns:
Value of the CMS option

huntKennedyCMSFloorValue

public static double huntKennedyCMSFloorValue(double forwardSwaprate,
                                              double volatility,
                                              double swapAnnuity,
                                              double optionMaturity,
                                              double swapMaturity,
                                              double payoffUnit,
                                              double optionStrike)
Calculate the value of a CMS strike using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.

Parameters:
forwardSwaprate - The forward swap rate
volatility - Volatility of the log of the swap rate
swapAnnuity - The swap annuity
optionMaturity - The option maturity
swapMaturity - The swap maturity
payoffUnit - The payoff unit, e.g., the discount factor corresponding to the payment date
optionStrike - The option strike
Returns:
Value of the CMS strike

huntKennedyCMSAdjustedRate

public static double huntKennedyCMSAdjustedRate(double forwardSwaprate,
                                                double volatility,
                                                double swapAnnuity,
                                                double optionMaturity,
                                                double swapMaturity,
                                                double payoffUnit)
Calculate the adjusted forward swaprate corresponding to a change of payoff unit from the given swapAnnuity to the given payoffUnit using the Black-Scholes model for the swap rate together with the Hunt-Kennedy convexity adjustment.

Parameters:
forwardSwaprate - The forward swap rate
volatility - Volatility of the log of the swap rate
swapAnnuity - The swap annuity
optionMaturity - The option maturity
swapMaturity - The swap maturity
payoffUnit - The payoff unit, e.g., the discount factor corresponding to the payment date
Returns:
Convexity adjusted forward rate

price

public static double price(Date settlementDate,
                           Date maturityDate,
                           double coupon,
                           double yield,
                           double redemption,
                           int frequency)
Re-implementation of the Excel PRICE function (a rather primitive bond price formula). The re-implementation is not exact, because this function does not consider daycount conventions.

Parameters:
settlementDate - Valuation date.
maturityDate - Maturity date of the bond.
coupon - Coupon payment.
yield - Yield (discount factor, using frequency: 1/(1 + yield/frequency).
redemption - Redemption (notional repayment).
frequency - Frequency (1,2,4).
Returns:
price Clean price.

price

public static double price(double timeToMaturity,
                           double coupon,
                           double yield,
                           double redemption,
                           int frequency)
Re-implementation of the Excel PRICE function (a rather primitive bond price formula). The re-implementation is not exact, because this function does not consider daycount conventions. We assume we have (int)timeToMaturity/frequency future periods and the running period has an accrual period of timeToMaturity - frequency * ((int)timeToMaturity/frequency).

Parameters:
timeToMaturity - The time to maturity.
coupon - Coupon payment.
yield - Yield (discount factor, using frequency: 1/(1 + yield/frequency).
redemption - Redemption (notional repayment).
frequency - Frequency (1,2,4).
Returns:
price Clean price.

Copyright © 2014 Christian P. Fries.

Copyright © 2014. All rights reserved.