Login     Register

        Contact Us     Search

XLeratorDB/financial-options Documentation

SQL Server proportional dividends implied volatility


ProportionalDividendsIV

Updated: 15 Dec 2013


Use the scalar function ProportionalDividendsIV to calculate the implied volatility of American or European option paying proportional dividends using a Cox Ross Rubinstein Binomial as described in The Complete Guide to Option Pricing Formulas, Second Edition, by Espen Gaarder Haug, PhD.
Syntax
SELECT [wctOptions].[wct].[ProportionalDividendsIV](
  <@CallPut, nvarchar(4000),>
 ,<@AmEur, nvarchar(4000),>
 ,<@AssetPrice, float,>
 ,<@StrikePrice, float,>
 ,<@TimeToMaturity, float,>
 ,<@RiskFreeRate, float,>
 ,<@Dividend_RangeQuery, nvarchar(max),>
 ,<@Price, float,>
 ,<@NumberOfSteps, int,>)
Arguments
@CallPut
identifies the option as being a call ('C') or a put ('P'). @CallPut is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar.
@AmEur
identifies the option as being American ('A') or European ('E'). @AmEur is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar.
@AssetPrice
the price of the underlying asset. @AssetPrice is an expression of type float or of a type that can be implicitly converted to float.
@StrikePrice
the exercise price of the option. @StrikePrice is an expression of type float or of a type that can be implicitly converted to float.
@TimeToMaturity
the time to expiration of the option, expressed in years. @TimeToMaturity is an expression of type float or of a type that can be implicitly converted to float.
@RiskFreeRate
the annualized, continuously compounded zero-coupon risk-free rate over the life of the option. @RiskFreeRate is an expression of type float or of a type that can be implicitly converted to float.
@Dividend_RangeQuery
a string containing an SQL statement which, when executed, provides the function with the times and proportions of the dividends to be used in the calculation. The results of the SQL must contain exactly two columns, the first being the time value, as a float or as a value that implicitly converts to float, and the second being the dividend amount as float, or as a value that implicitly converts to float. @Dividend_RangeQuery is an expression of type nvarchar or of a type that can be implicitly converted to nvarchar.
@Price
the price of the option. @Price is an expression of type float or of a type that can be implicitly converted to float.
@NumberOfSteps
the number of steps in the binomial tree. @NumberOfSteps is an expression of type int or of a type that can be implicitly converted to int.
Return Type
float
Remarks
·         @Volatility must be greater than zero (@Volatility > 0).
·         @TimeToMaturity must be greater than zero (@TimeToMaturity > 0).
·         @AssetPrice must be greater than zero (@AssetPrice > 0).
·         @StrikePrice must be greater than zero (@StrikePrice > 0).
·         @NumberOfSteps must be greater than 1 (@NumberOfSteps > 1)
·         Negative time values returned by @Dividend_RangeQuery are ignored.
·         Time values returned by @Dividend_RangeQuery that are greater than @TimeToMaturity are ignored.
·         If @RiskFreeRate is NULL then @RiskFreeRate is set to zero.
·         If @NumberOfSteps is NULL then @NumberOfSteps is set to 100.
·         To calculate the price and/or Greeks of the option use ProportionalDividends.
·         Use the table-value function ProportionalDividendsTree to see the underlying price, intrinsic value, and option value for each node on the binomial tree.
·         To calculate the implied volatility using discrete dividends (where the dividend is specified with a time and a monetary value rather than a proportion) use BinomialDiscreteDividendsIV.
Examples
Calculate the volatility for an American call option expiring in one year with an underlying asset value of 478, a strike price of 500 and a price of 43.17. The risk-free rate is 2.75%. Dividends will be paid quarterly in the following proportions.

T
Div
0.25
.010
0.50
.011
0.75
.012
1.00
.013

The number of steps is 100.
SELECT wct.ProportionalDividendsIV(
       'C'        --Put/Call
      ,'A'        --American/European
      ,478        --Asset Price
      ,500        --Strike Price
      ,1          --Time-to-maturity
      ,.0275      --Risk-free rate
      ,'SELECT *
       FROM (VALUES
            (0.25,0.010),
            (0.50,0.011),
            (0.75,0.012),
            (1.00,0.013)
            )n(T,D)'    --Proportional Dividends
      ,43.17            --Price
      ,100              --Number of Steps
      ) as [Volatility]

This produces the following result.
            Volatility
----------------------
               0.29999


In this example we look at how to use dates in the function, using the
YEARFRAC and CALCDATE functions from XLeratorDB/financial. We will use the GETDATE() function as the start date for the calculations. The option expires on November 27th, 2014 with dividends payable on February 6th, May 6th, August 6th, and November 6th, 2014.
SELECT wct.ProportionalDividendsIV(
       'C'
      ,'A'
      ,478
      ,500
      ,wct.YEARFRAC(GETDATE(),'2014-11-27',NULL)
      ,.0275
      ,'SELECT *
       FROM (VALUES
(wct.YEARFRAC(GETDATE(),wct.CALCDATE(2014,2,6),NULL),0.010),
(wct.YEARFRAC(GETDATE(),wct.CALCDATE(2014,5,6),NULL),0.011),
(wct.YEARFRAC(GETDATE(),wct.CALCDATE(2014,8,6),NULL),0.012),
(wct.YEARFRAC(GETDATE(),wct.CALCDATE(2014,11,6),NULL),0.013)
            )n(T,D)'
      ,43.17
      ,100
      ) as [Volatility]

This produces the following result on 2013-12-12. You results will be different.
            Volatility
----------------------
              0.298207


In this example, we use 
@date_start as a datetime variable to establish the starting point for calculating the time-to-expiry and @date_start_string as a string variable to be used in @Dividend_RangeQuery.
DECLARE @date_start as datetime = cast('2013-12-11' as datetime)
DECLARE @date_start_string as varchar(max) = '''' + convert(varchar,@date_start,112) + ''''
SELECT wct.ProportionalDividendsIV(
       'C'
      ,'A'
      ,478
      ,500
      ,wct.YEARFRAC(@date_start,'2014-11-27',NULL)
      ,.0275           
      ,'SELECT *
       FROM (VALUES
(wct.YEARFRAC(' + @date_start_string + ',wct.CALCDATE(2014,2,6),NULL),0.010),
(wct.YEARFRAC(' + @date_start_string + ',wct.CALCDATE(2014,5,6),NULL),0.011),
(wct.YEARFRAC(' + @date_start_string + ',wct.CALCDATE(2014,8,6),NULL),0.012),
(wct.YEARFRAC(' + @date_start_string + ',wct.CALCDATE(2014,11,6),NULL),0.013)
            )n(T,D)'
      ,43.17
      ,100
      ) as [Volatility]

This produces the following result.
            Volatility
----------------------
               0.29771


In this example we put some equity options trades into a table, with a separate table containing the closing price and prices for each ticker and a third table containing the dividend information. This example shows one way to combine the information from multiples tables to calculate the theoretical value of the option. This example holds the risk-free rate constant, which you wouldn't want to do in practice and we will add a discount factor table and calculate the interpolated risk-free rate in another example.
/*Put dividend information into a table*/
SELECT *
INTO #div
FROM (VALUES
('ABC','2013-12-15',0.010)
,('ABC','2014-03-15',0.0105)
,('ABC','2014-06-15',0.0110)
,('ABC','2014-09-15',0.0115)
,('ABC','2014-12-15',0.0120)
,('DEF','2014-01-17',.005)
,('DEF','2014-04-17',.005)
,('DEF','2014-07-17',.005)
,('DEF','2014-10-17',.005)
,('DEF','2015-01-17',.005)
,('GHI','2014-02-17',.020)
,('GHI','2014-05-17',.021)
,('GHI','2014-08-17',.022)
,('GHI','2014-11-17',.023)
,('GHI','2015-02-17',.030)
)d(ticker,date_div,amt_div)
 
/*Put underlying price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
       ('ABC',495)
      ,('DEF',125)
      ,('GHI',62.5)
      )p(ticker,price)
 
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
       (1,'ABC','2014-08-09',470,64.09,'C')
      ,(2,'ABC','2014-08-20',480,51.29,'P')
      ,(3,'ABC','2014-11-10',490,65.98,'P')
      ,(4,'ABC','2014-09-14',500,54.29,'C')
      ,(5,'DEF','2014-11-14',100,29.19,'C')
      ,(6,'DEF','2014-12-12',110,22.94,'C')
      ,(7,'DEF','2014-08-11',120,9.38,'P')
      ,(8,'DEF','2014-08-26',130,10.58,'C')
      ,(9,'GHI','2014-08-04',50,13.00,'C')
      ,(10,'GHI','2014-12-28',55,9.28,'C')
      ,(11,'GHI','2014-10-09',60,5.40,'P')
      ,(12,'GHI','2014-11-14',65,4.02,'C')
      )o(rn,ticker,expiry,strike,price,z)
 
/*Establish the start date for calculation purposes*/
DECLARE @date_start as datetime = cast('2013-12-11' as datetime)
DECLARE @date_start_string as varchar(max) = '''' + convert(varchar,@date_start,112) + ''''
SELECT A.rn
,A.ticker
,A.z
,B.price as underlying
,A.strike
,A.expiry
,A.price
,wct.ProportionalDividendsIV(
       A.z
      ,'A'
      ,B.price
      ,A.strike
      ,wct.YEARFRAC(@date_start,A.expiry,NULL)
      ,.0275           
,'SELECT wct.YEARFRAC(' + @date_start_string + ',date_div,NULL),amt_div FROM #div WHERE ticker = ' + '''' + CAST(A.ticker as varchar(max)) + ''''
      ,A.price         
      ,100
      ) as [Volatility]
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
 
DROP TABLE #div
DROP TABLE #prices
DROP TABLE #options

This produces the following result, which has been reformatted for presentation purposes.

rn
ticker
z
underlying
strike
expiry
price
Volatility
1
ABC
C
495
470
2014-08-09
64
0.350002
2
ABC
P
495
480
2014-08-20
51
0.350007
3
ABC
P
495
490
2014-11-10
66
0.350025
4
ABC
C
495
500
2014-09-14
54
0.349986
5
DEF
C
125
100
2014-11-14
29
0.300091
6
DEF
C
125
110
2014-12-12
23
0.300013
7
DEF
P
125
120
2014-08-11
9.4
0.299982
8
DEF
C
125
130
2014-08-26
11
0.300003
9
GHI
C
62.5
50
2014-08-04
13
0.250576
10
GHI
C
62.5
55
2014-12-28
9.3
0.249791
11
GHI
P
62.5
60
2014-10-09
5.4
0.250031
12
GHI
C
62.5
65
2014-11-14
4
0.250058



For large volumes of data having many options for a single ticker, it will be more efficient to calculate the time values of the dividends outside of the
ProportionalDividendIV function and simply use the pre-calculated values in @Dividend_RangeQuery.
/*Put dividend information into a table*/
SELECT *
INTO #div
FROM (VALUES
('ABC','2013-12-15',0.010)
,('ABC','2014-03-15',0.0105)
,('ABC','2014-06-15',0.0110)
,('ABC','2014-09-15',0.0115)
,('ABC','2014-12-15',0.0120)
,('DEF','2014-01-17',.005)
,('DEF','2014-04-17',.005)
,('DEF','2014-07-17',.005)
,('DEF','2014-10-17',.005)
,('DEF','2015-01-17',.005)
,('GHI','2014-02-17',.020)
,('GHI','2014-05-17',.021)
,('GHI','2014-08-17',.022)
,('GHI','2014-11-17',.023)
,('GHI','2015-02-17',.030)
)d(ticker,date_div,amt_div)
 
/*Put underlying price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
       ('ABC',495)
      ,('DEF',125)
      ,('GHI',62.5)
      )p(ticker,price)
 
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
       (1,'ABC','2014-08-09',470,64.09,'C')
      ,(2,'ABC','2014-08-20',480,51.29,'P')
      ,(3,'ABC','2014-11-10',490,65.98,'P')
      ,(4,'ABC','2014-09-14',500,54.29,'C')
      ,(5,'DEF','2014-11-14',100,29.19,'C')
      ,(6,'DEF','2014-12-12',110,22.94,'C')
      ,(7,'DEF','2014-08-11',120,9.38,'P')
      ,(8,'DEF','2014-08-26',130,10.58,'C')
      ,(9,'GHI','2014-08-04',50,13.00,'C')
      ,(10,'GHI','2014-12-28',55,9.28,'C')
      ,(11,'GHI','2014-10-09',60,5.40,'P')
      ,(12,'GHI','2014-11-14',65,4.02,'C')
      )o(rn,ticker,expiry,strike,price,z)
 
/*Establish the start date for calculation purposes*/
DECLARE @date_start as datetime = cast('2013-12-11' as datetime)
 
/*Put the #div values into another table with date converted to a
 fraction of a year*/
SELECT ticker
,wct.YEARFRAC(@date_start,date_div,NULL) as T
,amt_div as D
INTO #tdiv
FROM #div
 
SELECT A.rn
,A.ticker
,A.z
,B.price as underlying
,A.strike
,A.expiry
,A.price
,wct.ProportionalDividendsIV(
       A.z
      ,'A'
      ,B.price
      ,A.strike
      ,wct.YEARFRAC(@date_start,A.expiry,NULL)
      ,.0275           
,'SELECT T,D FROM #tdiv WHERE ticker = ' + '''' + CAST(A.ticker as varchar(max)) + ''''      ,A.price         
      ,100
      ) as [Volatility]
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
 
DROP TABLE #div
DROP TABLE #prices
DROP TABLE #options
DROP TABLE #tdiv

This produces the following result, which has been reformatted for presentation purposes.

rn
ticker
z
underlying
strike
expiry
price
Volatility
1
ABC
C
495
470
2014-08-09
64
0.350002
2
ABC
P
495
480
2014-08-20
51
0.350007
3
ABC
P
495
490
2014-11-10
66
0.350025
4
ABC
C
495
500
2014-09-14
54
0.349986
5
DEF
C
125
100
2014-11-14
29
0.300091
6
DEF
C
125
110
2014-12-12
23
0.300013
7
DEF
P
125
120
2014-08-11
9.4
0.299982
8
DEF
C
125
130
2014-08-26
11
0.300003
9
GHI
C
62.5
50
2014-08-04
13
0.250576
10
GHI
C
62.5
55
2014-12-28
9.3
0.249791
11
GHI
P
62.5
60
2014-10-09
5.4
0.250031
12
GHI
C
62.5
65
2014-11-14
4
0.250058



In this example, we will use the same inputs as above, with the exception that we will have a table of discount factors and use the
DFINTERP function to convert the discount factors into risk-free rates to be used in the function.
/*Put dividend information into a table*/
SELECT *
INTO #div
FROM (VALUES
('ABC','2013-12-15',0.010)
,('ABC','2014-03-15',0.0105)
,('ABC','2014-06-15',0.0110)
,('ABC','2014-09-15',0.0115)
,('ABC','2014-12-15',0.0120)
,('DEF','2014-01-17',.005)
,('DEF','2014-04-17',.005)
,('DEF','2014-07-17',.005)
,('DEF','2014-10-17',.005)
,('DEF','2015-01-17',.005)
,('GHI','2014-02-17',.020)
,('GHI','2014-05-17',.021)
,('GHI','2014-08-17',.022)
,('GHI','2014-11-17',.023)
,('GHI','2015-02-17',.030)
)d(ticker,date_div,amt_div)
 
/*Put underlying price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
       ('ABC',495)
      ,('DEF',125)
      ,('GHI',62.5)
      )p(ticker,price)
 
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
       (1,'ABC','2014-08-09',470,64.09,'C')
      ,(2,'ABC','2014-08-20',480,51.29,'P')
      ,(3,'ABC','2014-11-10',490,65.98,'P')
      ,(4,'ABC','2014-09-14',500,54.29,'C')
      ,(5,'DEF','2014-11-14',100,29.19,'C')
      ,(6,'DEF','2014-12-12',110,22.94,'C')
      ,(7,'DEF','2014-08-11',120,9.38,'P')
      ,(8,'DEF','2014-08-26',130,10.58,'C')
      ,(9,'GHI','2014-08-04',50,13.00,'C')
      ,(10,'GHI','2014-12-28',55,9.28,'C')
      ,(11,'GHI','2014-10-09',60,5.40,'P')
      ,(12,'GHI','2014-11-14',65,4.02,'C')
      )o(rn,ticker,expiry,strike,price,z)
 
/*Establish the start date for calculation purposes*/
DECLARE @date_start as datetime = cast('2013-12-11' as datetime)
 
/*Put the #div values into another table with date converted to a
 fraction of a year*/
SELECT ticker
,wct.YEARFRAC(@date_start,date_div,NULL) as T
,amt_div as D
INTO #tdiv
FROM #div
 
/*Put the discount factors into a table*/
SELECT wct.TENOR2DATE(tenor,@date_start,NULL,'') as date_df
,df
INTO #df
FROM (
   SELECT 'ON',0.999995555575309 UNION ALL
   SELECT 'TN',0.999991111170370 UNION ALL
   SELECT '1W',0.999956112706425 UNION ALL
   SELECT '2W',0.999916450742048 UNION ALL
   SELECT '1M',0.999804481000583 UNION ALL
   SELECT '2M',0.999574621744643 UNION ALL
   SELECT '3M',0.999241679910437 UNION ALL
   SELECT '6M',0.998800609148515 UNION ALL
   SELECT '9M',0.998022836090921 UNION ALL
   SELECT '1Y',0.997197057207847 UNION ALL
   SELECT '2Y',0.996311568695976
       )n(tenor, df)
 
/*Calculate the risk-free rate for each expiry date in the portfolio*/
SELECT expiry
,wct.DFINTERP(date_df,df,expiry,@date_start,'CC') as Rf
INTO #rates
FROM #df, #options
GROUP BY expiry
 
/*Calculate the implied volatility*/
SELECT A.rn
,A.ticker
,A.z
,B.price as underlying
,A.strike
,A.expiry
,A.price
,wct.ProportionalDividendsIV(
       A.z
      ,'A'
      ,B.price
      ,A.strike
      ,wct.YEARFRAC(@date_start,A.expiry,NULL)
      ,C.rf
      ,'SELECT T,D FROM #tdiv WHERE ticker = ' + '''' + CAST(A.ticker as varchar(max)) + ''''      ,A.price         
      ,100
      ) as [Volatility]
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
INNER JOIN #rates C
ON A.expiry = C.expiry
 
DROP TABLE #div
DROP TABLE #prices
DROP TABLE #options
DROP TABLE #tdiv
DROP TABLE #df
DROP TABLE #rates

This produces the following result, which has been reformatted for presentation purposes.

rn
ticker
z
underlying
strike
expiry
price
Volatility
1
ABC
C
495
470
2014-08-09
64
0.370674
2
ABC
P
495
480
2014-08-20
51
0.325173
3
ABC
P
495
490
2014-11-10
66
0.317773
4
ABC
C
495
500
2014-09-14
54
0.369713
5
DEF
C
125
100
2014-11-14
29
0.340214
6
DEF
C
125
110
2014-12-12
23
0.331324
7
DEF
P
125
120
2014-08-11
9.4
0.276995
8
DEF
C
125
130
2014-08-26
11
0.31953
9
GHI
C
62.5
50
2014-08-04
13
0.291677
10
GHI
C
62.5
55
2014-12-28
9.3
0.273327
11
GHI
P
62.5
60
2014-10-09
5.4
0.220995
12
GHI
C
62.5
65
2014-11-14
4
0.267842

 


Copyright 2008-2013 WestClinTech LLC         Privacy Policy        Terms of Service