1## Copyright (C) 2013 Parsiad Azimzadeh <parsiad.azimzadeh@gmail.com> 2## 3## This program is free software; you can redistribute it and/or modify it under 4## the terms of the GNU Lesser General Public License as published by the Free 5## Software Foundation; either version 3 of the License, or (at your option) any 6## later version. 7## 8## This program is distributed in the hope that it will be useful, but WITHOUT 9## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10## FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 11## for more details. 12## 13## You should have received a copy of the GNU Lesser General Public License 14## along with this program; if not, see <http://www.gnu.org/licenses/>. 15 16## -*- texinfo -*- 17## @deftypefn {Function File} {[@var{CallEl}, @var{PutEl}] =} blslambda (@var{Price}, @var{Strike}, @var{Rate}, @var{Time}, @var{Volatility}) 18## @deftypefnx {Function File} {[@var{CallEl}, @var{PutEl}] =} blslambda (@var{Price}, @var{Strike}, @var{Rate}, @var{Time}, @var{Volatility}, @var{Yield}) 19## Computes elasticity of option under the Black-Scholes model. 20## 21## @itemize 22## @item 23## Variable: @var{Price} The current price of the underlying asset. 24## @item 25## Variable: @var{Strike} The strike price the option is written on. 26## @item 27## Variable: @var{Rate} The risk-free interest rate. 28## @item 29## Variable: @var{Time} The time-to-expiry. 30## @item 31## Variable: @var{Volatility} The volatility of the underlying asset. 32## @item 33## Variable: @var{Yield} (Optional, default = 0) Annualized, continuously 34## compounded rate of dividends of the underlying asset. 35## @end itemize 36## 37## Computes the elasticity of an option under the Black-Scholes model. 38## Elasticity measures the percent change in the option price per percent change 39## in the underlying asset price. 40## 41## Update: the following bug has been fixed in MATLAB R2014a(5.3): 42## There is a bug in the MATLAB version of blslambda in which the deltas of the 43## option are not discounted by @var{Yield} in the nonzero dividend case. That 44## is, they compute normcdf(d1) * S / V when they should compute 45## exp(-Yield*T) * normcdf(d1) * S / V. At the time of writing, this bug is 46## present in the financial toolbox shipped with R2013a. Both this version of 47## blslambda and that shipped with R2013a agree when there are no dividends. 48## 49## @seealso{blsdelta, blsgamma, blsprice, blsrho, blstheta, blsvega} 50## @end deftypefn 51 52function [CallEl, PutEl] = blslambda (Price, Strike, Rate, Time, ... 53 Volatility, Yield = 0) 54 55 if (nargin < 5 || nargin > 6) 56 print_usage (); 57 endif 58 59 blscheck ("blslambda", Price, Strike, Rate, Time, Volatility, Yield); 60 61 [Call, Put] = blsprice (Price, Strike, Rate, Time, Volatility, Yield); 62 [CallDelta, PutDelta] = blsdelta (Price, Strike, Rate, Time, Volatility, ... 63 Yield); 64 65 CallEl = CallDelta .* Price ./ Call; 66 PutEl = PutDelta .* Price ./ Put; 67 68endfunction 69 70## Tests 71%!test 72%! [CallEl, PutEl] = blslambda (90:10:110, 100, 0.04, 1, 0.2); 73%! assert (CallEl, [7.7536 6.2258 5.0647], 1e-4) 74%! assert (PutEl, [-4.8955 -6.3639 -7.8941], 1e-4) 75%!test 76%! [CallEl, PutEl] = blslambda (90:10:110, 100, 0.04, 1, 0.2, 0.01); 77%! assert (CallEl, [7.9108 6.3601 5.1762], 1e-4) 78%! assert (PutEl, [-4.7695 -6.2139 -7.7255], 1e-4) 79 80## Test input validation 81%!error blslambda () 82%!error blslambda (1) 83%!error blslambda (1, 2) 84%!error blslambda (1, 2, 3) 85%!error blslambda (1, 2, 3, 4) 86