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{CallTheta}, @var{PutTheta}] =} blstheta (@var{Price}, @var{Strike}, @var{Rate}, @var{Time}, @var{Volatility})
18## @deftypefnx {Function File} {[@var{CallTheta}, @var{PutTheta}] =} blstheta (@var{Price}, @var{Strike}, @var{Rate}, @var{Time}, @var{Volatility}, @var{Yield})
19## Compute the Black-Scholes theta.
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 Black-Scholes theta, the rate of change of the option value with
38## respect to the time-to-expiry.
39##
40## @seealso{blsdelta, blsgamma, blslambda, blsprice, blsrho, blsvega}
41## @end deftypefn
42
43function [CallTheta, PutTheta] = blstheta (Price, Strike, Rate, Time, ...
44                                           Volatility, Yield = 0)
45
46  if (nargin < 5 || nargin > 6)
47    print_usage ();
48  endif
49
50  blscheck ("blstheta", Price, Strike, Rate, Time, Volatility, Yield);
51
52  sqrtT       = sqrt (Time);
53  sigma_sqrtT = Volatility .* sqrtT;
54
55  d1 = 1 ./ sigma_sqrtT .* (log (Price ./ Strike) + (Rate - Yield + Volatility.^2 / 2) .* Time);
56  d2 = d1 - sigma_sqrtT;
57
58  phi1 = normcdf (d1);
59  phi2 = normcdf (d2);
60
61  disc  = exp (-Yield .* Time);
62  shift = -disc .* Price .* normpdf (d1) .* Volatility / 2 ./ sqrtT;
63  t1    = Rate .* Strike   .* exp (-Rate .* Time);
64  t2    = Yield .* Price .* disc;
65
66  CallTheta = shift - t1 .*      phi2  + t2 .*  phi1     ;
67  PutTheta  = shift + t1 .* (1 - phi2) + t2 .* (phi1 - 1);
68
69endfunction
70
71## Tests
72%!test
73%! [CallTheta, PutTheta] = blstheta (90:10:110, 100, 0.04, 1, 0.2, 0.01);
74%! assert (CallTheta, [-4.2901 -5.2337 -5.1954], 1e-4)
75%! assert (PutTheta, [-1.3380 -2.3806 -2.4413], 1e-4)
76
77## Test input validation
78%!error blstheta ()
79%!error blstheta (1)
80%!error blstheta (1, 2)
81%!error blstheta (1, 2, 3)
82%!error blstheta (1, 2, 3, 4)
83