Option Pricing in VBA

March 20, 2018 | Author: rndomperson | Category: Black–Scholes Model, Option (Finance), Subroutine, Securities (Finance), Microsoft Excel


Comments



Description

Black Scholes FX Derivatives Pricing Formula UDF in Excel VBAIntroduction Fischer Black, Myron Scholes and Robert Merton made significant advances in the field of derivatives pricing with their papers published in 1973. The development of a transparent and reasonably robust option pricing model underpinned the transformational growth of the derivatives market over the decades to follow. In this document the key assumptions of the Black Scholes model are defined, the analytical solutions to the Black Scholes differential equations stated. Having shown the solutions, this document shows the development of the VBA user defined functions required for implementation of Black Scholes analytical pricing solutions using Excel. The key benefits of defining a custom function in Excel for pricing Black Scholes include    Saving time – custom functions enable reusability of the function across different worksheets when placed in an add-in Reduced risk of user error Functions are also extensible The Black Scholes Model of FX Spot Rates According to the Black Scholes model, the path of FX spot rates is defined by the following stochastic partial differential equation dS = (r - rf -1/2sigma^2)dt + sigma dz where dz is a standard Brownian motion, defined by dz = epsilon * sqrt(dt) where epsilon is a standard normal random variable; dS is the change in FX spot rate, r is the risk-free interest rate, rf is the foreign risk-free interest rate, sigma the volatility of the currency. The model implies that dS/S follows a normal distribution with mean r - rf -1/2sigma^2, and standard deviation sigma * epsilon * sqrt(dt)) As such the price at time 0 < t <= T is given by St = S0 * exp( (r – rf - ½ sigma^2) dt + sigma * epsilon * sqrt(dt)) The price of a European call option is given by Max (St – K, 0) where St is the final spot rate at expiry. 1 Nyasha Madavo, Exceltasks Ltd which under the no-arbitrage assumptions. and f=max(K-S. is constant and the same for all maturities 7.Black Scholes FX Derivatives Pricing Formula UDF in Excel VBA Black Scholes Option Pricing Assumptions The Black Scholes Merton differential equation is derived using the following assumptions: 1. No transactions costs or taxes. There are no dividends during the life of the asset* Black Scholes Stochastic Differential Equations Given the above assumptions. These are the solutions to the Black Scholes equation. Security trading is continuous 6. The risk-free rate of interest.0) for a put. r. 0) at expiry for a call. The FX spot rate follows the model above 2. the following formulas are derived. then create a riskless portfolio of one short call option and long delta amount of shares. C = S0N(d1) – K*exp(-rT)*N(d2) P=K*exp(-rT)*N(-d2) – S0(N-d1) D1 = (ln(S0/k)+(r+sigma^2/2)T)/sigma*sqrt(T) D2 = (ln(S0/k)+(r-sigma^2/2)T)/sigma*sqrt(T) = d1 – sigma*sqrt(T) 2 Nyasha Madavo. Black and Scholes use Ito’s lemma to derive a differential equation for the price of an option. all securities perfectly divisible 4. No riskless arbitrage opportunities exist 5. Short selling with full use of proceeds is allowed 3. must earn the risk-free rate of return. Using this model they arrive at the following differential equation: Df/dt + rSdf/ds + 1/2 sigma^2*S^2*d^2f/dS^2 = rf Using either risk-neutral valuation or solving the partial differential equation using the boundary conditions that f = max(S-K. Exceltasks Ltd . r as double. we need to create a function that returns an array. rf as double. N as long) as double Depending on how we wish to use the function in future. we may also want to define the parameters as being passed in by value. rf. the full code would be as follows: Function Black_Scholes(ByVal S As Double. ByVal r As Double. N) The proper way to define the function would be Function Black_Scholes (S as double. N (number of simulations) and should return the call price and the put price. S. The main issue with reusability of functions is performance. ByVal r as double. Exceltasks Ltd . and by explicitly defining each and every variable’s data type. sigma as double. K as double. Custom functions are slower than Excel’s built-in functions. t as double. sigma. rf.5 * sigma ^ 2) * t c = sigma * Sqr(t) 3 Nyasha Madavo.0. Excel VBA has late and early binding depending on the data type declarations.rf + 0. ByVal t As Double. but their performance can be optimised. ByVal t as double. ByVal rf As Double. early binding is recommended. So where a ‘lazy’ function declaration may look like Function Black_Scholes (S. This would protect encapsulation of the function if calling it from a subroutine – an important The Black Scholes VBA Custom Function (cont) step when moving towards an object-orientated approach. t.5 * sigma ^ 2) * t b_put = (r . ByVal sigma As Double) As Double Dim d1 As Double Dim d2 As Double Dim a As Double Dim b1 As Double Dim b2 As Double Dim c As Double Dim call_price As Double Dim put_price As Double a = Log(S0 / K) b_call = (r . Late binding slows down VBA code execution noticeably over many different simulation cycles. ByVal K as double. K. r. ByVal rf as double.rf . As such. r. sigma. ByVal sigma as double) as double As such. t. To return the two values.Black Scholes FX Derivatives Pricing Formula UDF in Excel VBA The Black Scholes VBA Custom Function The function takes in 6 parameters. K. ByVal K As Double. This is done by not defining the variables of the function as variant. Function Black_Scholes (ByVal S as double. including the array returned by the function. press Ctrl + Shift + Enter. put_price) End Sub vbLf & "Black Scholes(Asset Price." & _ End Sub 4 Nyasha Madavo.NormSDist(-d1) Black_Scholes = Array(call_price. Volatility (%))" Application.NormSDist(d1) .K * Exp(-r * t) * WorksheetFunction. Risk free interest rate (%). Description:=sFn_Description.NormSDist(d2) put_price = K * Exp(-r * t) * WorksheetFunction.Black Scholes FX Derivatives Pricing Formula UDF in Excel VBA The Black Scholes VBA Custom Function (cont) d1 = (a + b1) / c d2 = (Log(S0 / K) + b2) / (sigma * Sqr(t)) call_price = Black_Scholes = S0 * Exp(-rf * t) * WorksheetFunction. Strike. enter the formula." & _ vbLf & "Select the output cells.NormSDist(-d2) . Exceltasks Ltd . Asset yield (%). Category:=1 Advanced VBA – Get Excel to add user tips In order to enhance the usability of the function one could add a subroutine to add user tips and show it in the list of Excel functions Sub UDF_Function_Descriptions() Dim sFn_Description As String sFn_Description = "Returns the price of a vanilla call and a put option in two cells.MacroOptions Macro:="Black_Scholes". Time Interval (years).S0 * Exp(rf * t) * WorksheetFunction. according to the Black Scholes model. Exceltasks Ltd .Black Scholes FX Derivatives Pricing Formula UDF in Excel VBA 5 Nyasha Madavo.
Copyright © 2024 DOKUMEN.SITE Inc.