Beispiel #1
0
        public static void RunBSOptTest(Boolean CP, double fwdPrice, double strike, double vol, double r, double t)
        {
            var result = (object[, ])BlackScholesMertonModel.Greeks(CP, fwdPrice, strike, vol, t);

            Debug.WriteLine(String.Format("Premium : {0} Delta : {1} Gamma : {2} Vega : {3} Theta : {4} Rho : {5}", result[0, 0], result[0, 1], result[0, 2], result[0, 3], result[0, 4], result[0, 5]));
            Debug.WriteLine(String.Format("Premium : {0} Delta : {1} Gamma : {2} Vega : {3} Theta : {4} Rho : {5}", result[1, 0], result[1, 1], result[1, 2], result[1, 3], result[1, 4], result[1, 5]));
        }
Beispiel #2
0
        /// <summary>
        /// Standard (Black-Scholes) option valuation
        /// r = Continuously compounded interest rate between now and time t.
        /// Discount factor is exp(-r * t).
        /// Different combinations in inputs to the generalized model instantiate different models:
        /// b=r (the cost of carry rate = the risk free rate). Black Scholes 1973 stock option model.
        /// b=r-q, where q is the continuous dividend yield. Merton 1973 stock option model.
        /// b=0. The Black 1976 futures option model.
        /// b=0 and r=0. Assay 1982 margined futures option model.
        /// b=r - rf, rf being the foreign rate. Garman Kohlhagen 1983 currency option model.
        /// </summary>
        /// <param name="callFlag">The call/put flag.</param>
        /// <param name="price">The stock price S. Price fixed today for purchase of asset at time t</param>
        /// <param name="strike">The strike price K. Exercise price of option</param>
        /// <param name="rate">The risk free rate.</param>
        /// <param name="costOfCarry">The cost of carry rate.</param>
        /// <param name="vol">Volatility of the relative price change of the underlying asset S.
        /// Per cent volatility in units of (year)^(-1/2)</param>
        /// <param name="t">Time in years to the maturity of the option.</param>
        /// <returns>An array of results for Black Scholes.</returns>
        public object BSMGeneralisedWithGreeks(bool callFlag, double price, double strike,
                                               double rate, double costOfCarry, double vol, double t)
        {
            var model = BlackScholesMertonModel.BSMGeneralisedWithGreeks(callFlag, price, strike, rate, costOfCarry, vol, t);

            return(model);
        }
Beispiel #3
0
        public void ConstructorTest()
        {
            const bool   CallFlag = true;
            const double FwdPrice = 0.04884062563019196;
            const double Strike   = 0.0496484493972347;
            const double Vol      = 0.194919996223031;
            const double T        = 0.00821917808219178;

            // First do a run to load stuff, but with different values so that cache can't be used
            BlackScholesMertonModel blackScholesMertonModelPreload
                = new BlackScholesMertonModel(CallFlag, FwdPrice + 0.01, Strike, Vol, T);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            BlackScholesMertonModel blackScholesMertonModel
                = new BlackScholesMertonModel(CallFlag, FwdPrice, Strike, Vol, T);

            stopwatch.Stop();

            Debug.Print("Time (ms):" + stopwatch.Elapsed.TotalMilliseconds);

            Assert.AreEqual(8.29482796203315E-05, blackScholesMertonModel.Value, 1e-9);
            Assert.AreEqual(0.178921151487557, blackScholesMertonModel.SpotDelta, 1e-9);
            Assert.AreEqual(302.880152685535, blackScholesMertonModel.Gamma, 1e-9);
            Assert.AreEqual(0.00115749210381365, blackScholesMertonModel.Vega, 1e-9);
            Assert.AreEqual(0.013725116687299, blackScholesMertonModel.Theta, 1e-9);
            Assert.AreEqual(-6.81766681810943E-07, blackScholesMertonModel.Rho, 1e-9);
        }
Beispiel #4
0
        /// <summary>
        /// Functionality to price a Black vanilla payer swaption.
        /// </summary>
        /// <param name="swapRate">Swap rate expressed as a decimal.
        /// Example: 0.07 for a swap rate of 7%.</param>
        /// <param name="annuityFactor">Annuity factor, for the swap
        /// associated with the swaption.</param>
        /// <param name="sigma">Black yield volatility expressed as a decimal.
        /// Example: 0.1191 for a volatility of 11.91%.</param>
        /// <returns>Price of a Black vanilla payer swaption.</returns>
        private double PriceBlackVanillaPayerSwaption(double swapRate, double annuityFactor, double sigma)
        {
            var model = new BlackScholesMertonModel(true, swapRate, _strike, sigma, _optionExpiry);
            // Compute and return the price of a Black vanilla payer swaption.
            var price = annuityFactor * model.Value;

            return(price);
        }
Beispiel #5
0
        public static void RunBSMGeneralisedOptTest()
        {
            var result1 = (object[, ])BlackScholesMertonModel.BSMGeneralisedWithGreeks(false, _fwdPrice, _strike, _rate, _caRRY, _volatility, _time);

            Debug.WriteLine(String.Format("Premium : {0} Delta : {1} Gamma : {2} Vega : {3} Theta : {4} Rho : {5}", result1[1, 0], result1[1, 1], result1[1, 2], result1[1, 3], result1[1, 4], result1[1, 5]));
            Assert.AreEqual((double)result1[1, 0], 4.087d, 0.0001d);
            var result2 = (object[, ])BlackScholesMertonModel.BSMGeneralisedWithGreeks(true, -_fwdPrice, -_strike, _rate, _caRRY, -_volatility, _time);

            Debug.WriteLine(String.Format("Premium : {0} Delta : {1} Gamma : {2} Vega : {3} Theta : {4} Rho : {5}", result2[1, 0], result2[1, 1], result2[1, 2], result2[1, 3], result2[1, 4], result2[1, 5]));
            Assert.AreEqual((double)result2[1, 0], 4.087d, 0.0001d);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the swaption value.
        /// </summary>
        ///<param name="rate">The floating rate.</param>
        ///<param name="strikeRate">The strike rate.</param>
        ///<param name="volatility">The lognormal volatility.</param>
        ///<param name="timeToExpiry">The time to expiry.</param>
        ///<returns>The swaption value using BSM.</returns>
        public double GetSwaptionValue(double rate, double strikeRate, double volatility, double timeToExpiry)
        {
            var model = BlackScholesMertonModel.GetSwaptionValue(rate, strikeRate, volatility, timeToExpiry);

            return(model);
        }
Beispiel #7
0
        /// <summary>
        /// Standard (Black-Scholes) option valuation
        /// r = Continuously compounded interest rate between now and time t.
        /// Discount factor is exp(-r * t).
        /// </summary>
        /// <param name="callFlag">The call/put flag.</param>
        /// <param name="fwdPrice">Price fixed today for purchase of asset at time t</param>
        /// <param name="strike">Exercise price of option</param>
        /// <param name="vol">Per cent volatility in units of (year)^(-1/2)</param>
        /// <param name="t">Time in years to the maturity of the option.</param>
        /// <returns>An array of results for Black Scholes.</returns>
        public object Greeks(bool callFlag, double fwdPrice, double strike, double vol, double t)
        {
            var model = BlackScholesMertonModel.Greeks(callFlag, fwdPrice, strike, vol, t);

            return(model);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the put option value.
        /// </summary>
        ///<param name="floatRate">The floating rate.</param>
        ///<param name="strikeRate">The strike rate.</param>
        ///<param name="volatility">The lognormal volatility.</param>
        ///<param name="timeToExpiry">The time to expiry.</param>
        ///<returns>The put value using BSM.</returns>
        public decimal GetPutOptionValue(decimal floatRate, decimal strikeRate, decimal volatility, decimal timeToExpiry)
        {
            var model = BlackScholesMertonModel.GetPutOptionValue(floatRate, strikeRate, volatility, timeToExpiry);

            return(model);
        }