Article Image
Article Image
read

Various Stochastic Models used in Options Theory.

The QuantLib project is open-source software that prioritizes a comprehensive software framework for quantitative finance. The user can download the QuantLib project and have access to a library for modeling, trading, and risk management in real time. QuantLib is written in C++ with clean object programming using design patterns such as creational, behavioral, and structural.

  • Students can master the library that is used in the real world and contribute to it in a meaningful way.
  • Researchers can have a framework at hand which vastly reduces the amount of low-level work necessary to build models.
  • Ability to have a sustainable framework for pricing and risk management orices.

My research for QuantLib is primarily using the Equity models to price derivatives such as eurpoean options and american options. Other models such as credit derivatives include convertible bonds and floating interes rate bonds.

Equity Options

Example 1: Black-Scholes European Option.

The Black-Scholes-Merton is a pricing model used for financial instruments. It is primarily used in stock option valuation by determining the valuation of an asset (call option) with six variables: volatility, type, underlying stock price, strike price, and the risk-free rate. Below is the example we use to demonstrate the principle of hedging to eliminate risk. The Black-Scholes model is essentially a second-order partial differential equation:

Where we price the call option:

Calculating D1 and D2:

Using Python for Black-Scholes

Black-Scholes Model for European call option

    def euro_call(spot_price, strike_price, maturity_date, current_date, risk_free_rate, volatility):

     d1 = (np.log(spot_price/strike_price) + (risk_free_rate + 0.5 * volatility **2) * maturity_date)/(volatility * np.sqrt(maturity_date - current_date))
     d2 = (np.log(spot_price/strike_price) + (risk_free_rate - 0.5 * volatility **2) * maturity_date)/(volatility * np.sqrt(maturity_date - current_date))    
     call = (spot_price * stats.norm.cdf(d1)- strike_price * np.exp(-risk_free_rate * (maturity_date -current_date)) * stats.norm.cdf(d2))

     return call

As we see from the code above, we successfully modeled a black-scholes european cal option by calculating the d1 and d2 functions with the original six variables.

Using Geometric Brownian Motion:

Underlying stock prices can be framed as a GBM process that follows a random walk. Therefore, let’s denote the process as a stochastic differential and Ito’s Lemma. Where the mu is the drift, the sigma is the volatility, and the Z is the standard normal random variable.

    # Monte Carlo simulation

     spot_price = spot_price * np.exp((risk_free_rate - 0.5 * volatility **2) * maturity_date + volatility * np.sqrt(maturity_date) * Z)
     Call_option = np.exp(-risk_free_rate * maturity_date)* np.mean(np.maximum(spot_price - strike_price, 0))

In the Monte Carlo simulation, we will use call_option to model the first equation of the Geometric brownian motion and BSM as the second equation. The final yields were Black-Scholes: 8.021 and Monte Carlo: 8.19

Using the QuantLib engine.

Assume we are purchasing a European call option for TSLA with a strike price of $14.38 maturing on May 15th, 2016. Assume the spot price is $12.80, the volatility is 20%, and the dividend yield of 1.63%. Short-term risk-free 0.01%. We shall value this option on October 5, 2015. We see that the theoretical price of the option is 0.24 using the AnalyticEuropeanEngine().

C++ Implementation.

    #include <ql/qldefines.hpp>
    #if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC)
    #  include <ql/auto_link.hpp>
    #endif
    #include <ql/instruments/vanillaoption.hpp>
    #include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
    #include <ql/pricingengines/vanilla/analyticeuropeanvasicekengine.hpp>
    #include <ql/pricingengines/vanilla/analytichestonengine.hpp>
    #include <ql/pricingengines/vanilla/binomialengine.hpp>
    #include <ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp>

    #include <ql/time/calendars/target.hpp>
    #include <ql/utilities/dataformatters.hpp>
    #include <iostream>
    #include <iomanip>

    using namespace QuantLib;

    int main(int, char* []) {

        try {

                std::cout << std::endl;

                // set up dates
                Calendar calendar = TARGET();
                Date todaysDate(15, May, 2016);
                Date settlementDate(8, October, 2015);
                Settings::instance().evaluationDate() = todaysDate;

                // our options
                Option::Type type(Option::Put);
                Real underlying = 12.80;
                Real strike = 14.38;
                Spread dividendYield = 0.00;
                Rate riskFreeRate = 0.001;
                Volatility volatility = 0.20;
                Date maturity(15, May, 2016);
                DayCounter dayCounter = Actual365Fixed();

                std::cout << "Option type = "  << type << std::endl;
                std::cout << "Maturity = "        << maturity << std::endl;
                std::cout << "Underlying price = "        << underlying << std::endl;
                std::cout << "Strike = "                  << strike << std::endl;
                std::cout << "Risk-free interest rate = " << io::rate(riskFreeRate)
                          << std::endl;
                std::cout << "Dividend yield = " << io::rate(dividendYield)
                          << std::endl;
                std::cout << "Volatility = " << io::volatility(volatility)
                          << std::endl;
                std::cout << std::endl;
                std::string method;
                std::cout << std::endl ;
                
                // options
                VanillaOption europeanOption(payoff, europeanExercise);
                VanillaOption bermudanOption(payoff, bermudanExercise);
                VanillaOption americanOption(payoff, americanExercise);

                // Analytic formulas:

                // Black-Scholes for European
                method = "Black-Scholes";
                europeanOption.setPricingEngine(ext::shared_ptr<PricingEngine>(new AnalyticEuropeanEngine(bsmProcess)));
                std::cout << std::setw(widths[0]) << std::left << method
                          << std::fixed
                          << std::setw(widths[1]) << std::left << europeanOption.NPV()
                          << std::setw(widths[2]) << std::left << "N/A"
                          << std::setw(widths[3]) << std::left << "N/A"
                          << std::endl;

Example 2: Binomial Tree Model for TSLA European Option.

Let’s use the information from above to construct a binomial tree. We still use the information from above, however, we do use a function to create the binomial tree named binomial_price. The code snippet below shows the convergence of the binomial tree comapring the price and bsm process.

C++ Implementation:

        // Binomial method: Additive equiprobabilities
        method = "Additive equiprobabilities";
        europeanOption.setPricingEngine(ext::shared_ptr<PricingEngine>(
                new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps)));
        bermudanOption.setPricingEngine(ext::shared_ptr<PricingEngine>(
                new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps)));
        americanOption.setPricingEngine(ext::shared_ptr<PricingEngine>(
                new BinomialVanillaEngine<AdditiveEQPBinomialTree>(bsmProcess, timeSteps)));
        std::cout << std::setw(widths[0]) << std::left << method
                  << std::fixed
                  << std::setw(widths[1]) << std::left << europeanOption.NPV()
                  << std::setw(widths[2]) << std::left << bermudanOption.NPV()
                  << std::setw(widths[3]) << std::left << americanOption.NPV()
                  << std::endl;
Blog Logo

Nijaz Kovacevic


Published

Image

Nijaz Kovacevic

Quantitative Analysis - Software Engineering - Mathematics

Back to Overview