ProportionalDividendsPriceNGreeks
Updated: 15 Dec 2013
Use the table-valued function ProportionalDividendsPriceNGreeks to calculate the price, delta, gamma, theta, vega, rho, and lambda of American and European options 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.
Price, delta, gamma, and theta are calculated directly from the binomial tree. Vega and rho are calculated using a first-order forward finite difference.
Syntax
SELECT * FROM [wctOptions].[wct].[ProportionalDividendsPriceNGreeks](
<@CallPut, nvarchar(4000),>
,<@AmEur, nvarchar(4000),>
,<@AssetPrice, float,>
,<@StrikePrice, float,>
,<@TimeToMaturity, float,>
,<@RiskFreeRate, float,>
,<@Dividend_RangeQuery, nvarchar(max),>
,<@Volatility, 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 proportion 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.
@Volatility
the volatility of the relative price change of the underlying asset. @Volatility 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
RETURNS TABLE (
[Price] [float] NULL,
[Delta] [float] NULL,
[Gamma] [float] NULL,
[Theta] [float] NULL,
[Vega] [float] NULL,
[Rho] [float] NULL,
[Lambda] [float] NULL
)
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)
· If @RV is NULL, then @RV is set to 'P'.
· 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.
· To improve performance, the vega calculation in ProportionalDividendsPriceNGreeks is different than the vega calculation in ProportionalDividends.
· To improve performance, the rho calculation in ProportionalDividendsPriceNGreeks is different than the rho calculation in ProportionalDividends.
· To calculate the price and Greeks using discrete dividends (where the dividend is specified with a date and a percentage) use BinomialDiscreteDividends.
Example
Calculate the price and Greeks for an American call option expiring in one year with asset price of 478, a strike price of 500 and a volatility of 30%. 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 *
FROM wct.ProportionalDividendsPriceNGreeks(
'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
,0.30 --Volatility
,100 --Number of Steps
)
This produces the following result.
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
43.17176
|
0.463623
|
0.002781
|
-0.09181
|
1.833062
|
1.557834
|
5.133256
|
In this example, we calculate different option values by changing the volatility. We use the SeriesFloat function to generate volatilities between .20 and .40. Note the use of CROSS APPLY with a table-valued function.
SELECT n.SeriesValue as volatility
,k.*
FROM wct.SeriesFloat(0.20,0.40,.01,NULL,NULL)n
CROSS APPLY wct.ProportionalDividendsPriceNGreeks(
'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
,n.SeriesValue --Volatility
,100 --Number of Steps
)k
This produces the following result.
volatility
|
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
0.2
|
24.93099
|
0.406094
|
0.004124
|
-0.06438
|
1.757269
|
1.475521
|
7.786006
|
0.21
|
26.68826
|
0.413289
|
0.003943
|
-0.06731
|
1.750447
|
1.495156
|
7.402207
|
0.22
|
28.43871
|
0.420003
|
0.003778
|
-0.07023
|
1.768155
|
1.474775
|
7.059439
|
0.23
|
30.20687
|
0.426345
|
0.003625
|
-0.07311
|
1.869251
|
1.490093
|
6.746569
|
0.24
|
32.07612
|
0.432553
|
0.003474
|
-0.0758
|
1.862693
|
1.504201
|
6.445923
|
0.25
|
33.93881
|
0.438408
|
0.003335
|
-0.07849
|
1.85673
|
1.516533
|
6.174609
|
0.26
|
35.79554
|
0.44395
|
0.003207
|
-0.08117
|
1.851267
|
1.527296
|
5.928345
|
0.27
|
37.64681
|
0.449216
|
0.003089
|
-0.08384
|
1.846229
|
1.536667
|
5.703671
|
0.28
|
39.49304
|
0.454233
|
0.002979
|
-0.0865
|
1.841549
|
1.544796
|
5.49776
|
0.29
|
41.33458
|
0.459028
|
0.002876
|
-0.08916
|
1.837175
|
1.551815
|
5.308273
|
0.3
|
43.17176
|
0.463623
|
0.002781
|
-0.09181
|
1.833062
|
1.557834
|
5.133256
|
0.31
|
45.00482
|
0.468037
|
0.002691
|
-0.09445
|
1.829172
|
1.562954
|
4.971062
|
0.32
|
46.83399
|
0.472288
|
0.002607
|
-0.09708
|
1.825473
|
1.567259
|
4.820293
|
0.33
|
48.65947
|
0.476389
|
0.002528
|
-0.09971
|
1.821938
|
1.570825
|
4.679751
|
0.34
|
50.4814
|
0.480355
|
0.002454
|
-0.10233
|
1.818544
|
1.573719
|
4.548405
|
0.35
|
52.29995
|
0.484197
|
0.002383
|
-0.10494
|
1.81527
|
1.575998
|
4.425363
|
0.36
|
54.11522
|
0.487925
|
0.002317
|
-0.10755
|
1.812292
|
1.577715
|
4.309843
|
0.37
|
55.92751
|
0.491549
|
0.002254
|
-0.11014
|
1.812167
|
1.559676
|
4.201162
|
0.38
|
57.73968
|
0.495095
|
0.002194
|
-0.11273
|
1.809169
|
1.532855
|
4.098665
|
0.39
|
59.54885
|
0.498552
|
0.002137
|
-0.11531
|
1.806234
|
1.533413
|
4.001885
|
0.4
|
61.35508
|
0.501924
|
0.002083
|
-0.11788
|
1.803352
|
1.533566
|
3.910351
|
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 *
FROM wct.ProportionalDividendsPriceNGreeks(
'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)'
,0.30
,100
)k
This produces the following result on 2013-12-12. Your results will be different.
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
43.4956
|
0.476115
|
0.002909
|
-0.09585
|
1.813845
|
1.490775
|
5.232324
|
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 *
FROM wct.ProportionalDividendsPriceNGreeks(
'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)'
,0.30
,100
)k
This produces the following result.
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
43.58636
|
0.476371
|
0.002904
|
-0.09573
|
1.816345
|
1.495475
|
5.224235
|
In this example we put some equity options trades into a table, with a separate table containing the closing price and volatilities 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 price and Greeks 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. Once again, note the use of CROSS APPLY.
/*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 price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
('ABC',495,0.35)
,('DEF',125,0.3)
,('GHI',62.5,0.25)
)p(ticker,price,vol)
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
(1,'ABC','2014-08-09',470,'C')
,(2,'ABC','2014-08-20',480,'P')
,(3,'ABC','2014-11-10',490,'P')
,(4,'ABC','2014-09-14',500,'C')
,(5,'DEF','2014-11-14',100,'C')
,(6,'DEF','2014-12-12',110,'C')
,(7,'DEF','2014-08-11',120,'P')
,(8,'DEF','2014-08-26',130,'C')
,(9,'GHI','2014-08-04',50,'C')
,(10,'GHI','2014-12-28',55,'C')
,(11,'GHI','2014-10-09',60,'P')
,(12,'GHI','2014-11-14',65,'C')
)o(rn,ticker,expiry,strike,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
,A.expiry
,B.vol
,k.*
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
CROSS APPLY wct.ProportionalDividendsPriceNGreeks(
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)) + ''''
,B.vol
,100
)k
DROP TABLE #div
DROP TABLE #prices
DROP TABLE #options
This produces the following result, which has been reformatted for presentation purposes.
rn
|
ticker
|
z
|
expiry
|
vol
|
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
1
|
ABC
|
C
|
2014-08-09
|
0.35
|
64.0897
|
0.6064
|
0.0028
|
-0.1325
|
1.4887
|
1.2892
|
4.6832
|
2
|
ABC
|
P
|
2014-08-20
|
0.35
|
51.2889
|
-0.4102
|
0.0027
|
-0.0911
|
1.555
|
-1.5035
|
-3.9593
|
3
|
ABC
|
P
|
2014-11-10
|
0.35
|
65.9756
|
-0.4288
|
0.0023
|
-0.0741
|
1.796
|
-2.2449
|
-3.217
|
4
|
ABC
|
C
|
2014-09-14
|
0.35
|
54.2923
|
0.5236
|
0.0026
|
-0.1243
|
1.6752
|
1.4129
|
4.7734
|
5
|
DEF
|
C
|
2014-11-14
|
0.3
|
29.1872
|
0.8187
|
0.0072
|
-0.0193
|
0.3061
|
0.5727
|
3.5063
|
6
|
DEF
|
C
|
2014-12-12
|
0.3
|
22.9395
|
0.7168
|
0.0089
|
-0.0221
|
0.4185
|
0.5796
|
3.906
|
7
|
DEF
|
P
|
2014-08-11
|
0.3
|
9.3807
|
-0.3793
|
0.0125
|
-0.0198
|
0.3853
|
-0.3329
|
-5.054
|
8
|
DEF
|
C
|
2014-08-26
|
0.3
|
10.5799
|
0.4915
|
0.0127
|
-0.0282
|
0.4064
|
0.3366
|
5.8072
|
9
|
GHI
|
C
|
2014-08-04
|
0.25
|
12.9964
|
0.9336
|
0.0156
|
-0.0086
|
0.0621
|
0.1126
|
4.4898
|
10
|
GHI
|
C
|
2014-12-28
|
0.25
|
9.2836
|
0.7521
|
0.0299
|
-0.0128
|
0.1744
|
0.1723
|
5.0633
|
11
|
GHI
|
P
|
2014-10-09
|
0.25
|
5.3993
|
-0.4328
|
0.0265
|
-0.0064
|
0.212
|
-0.2385
|
-5.0104
|
12
|
GHI
|
C
|
2014-11-14
|
0.25
|
4.0187
|
0.4321
|
0.0292
|
-0.0115
|
0.2177
|
0.1634
|
6.7198
|
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 ProportionalDividendPriceNGreeks 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 price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
('ABC',495,0.35)
,('DEF',125,0.3)
,('GHI',62.5,0.25)
)p(ticker,price,vol)
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
(1,'ABC','2014-08-09',470,'C')
,(2,'ABC','2014-08-20',480,'P')
,(3,'ABC','2014-11-10',490,'P')
,(4,'ABC','2014-09-14',500,'C')
,(5,'DEF','2014-11-14',100,'C')
,(6,'DEF','2014-12-12',110,'C')
,(7,'DEF','2014-08-11',120,'P')
,(8,'DEF','2014-08-26',130,'C')
,(9,'GHI','2014-08-04',50,'C')
,(10,'GHI','2014-12-28',55,'C')
,(11,'GHI','2014-10-09',60,'P')
,(12,'GHI','2014-11-14',65,'C')
)o(rn,ticker,expiry,strike,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
,A.expiry
,B.vol
,k.*
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
CROSS APPLY wct.ProportionalDividendsPriceNGreeks(
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)) + ''''
,B.vol
,100
)k
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
|
expiry
|
vol
|
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
1
|
ABC
|
C
|
2014-08-09
|
0.35
|
64.0897
|
0.6064
|
0.0028
|
-0.1325
|
1.4887
|
1.2892
|
4.6832
|
2
|
ABC
|
P
|
2014-08-20
|
0.35
|
51.2889
|
-0.4102
|
0.0027
|
-0.0911
|
1.555
|
-1.5035
|
-3.9593
|
3
|
ABC
|
P
|
2014-11-10
|
0.35
|
65.9756
|
-0.4288
|
0.0023
|
-0.0741
|
1.796
|
-2.2449
|
-3.217
|
4
|
ABC
|
C
|
2014-09-14
|
0.35
|
54.2923
|
0.5236
|
0.0026
|
-0.1243
|
1.6752
|
1.4129
|
4.7734
|
5
|
DEF
|
C
|
2014-11-14
|
0.3
|
29.1872
|
0.8187
|
0.0072
|
-0.0193
|
0.3061
|
0.5727
|
3.5063
|
6
|
DEF
|
C
|
2014-12-12
|
0.3
|
22.9395
|
0.7168
|
0.0089
|
-0.0221
|
0.4185
|
0.5796
|
3.906
|
7
|
DEF
|
P
|
2014-08-11
|
0.3
|
9.3807
|
-0.3793
|
0.0125
|
-0.0198
|
0.3853
|
-0.3329
|
-5.054
|
8
|
DEF
|
C
|
2014-08-26
|
0.3
|
10.5799
|
0.4915
|
0.0127
|
-0.0282
|
0.4064
|
0.3366
|
5.8072
|
9
|
GHI
|
C
|
2014-08-04
|
0.25
|
12.9964
|
0.9336
|
0.0156
|
-0.0086
|
0.0621
|
0.1126
|
4.4898
|
10
|
GHI
|
C
|
2014-12-28
|
0.25
|
9.2836
|
0.7521
|
0.0299
|
-0.0128
|
0.1744
|
0.1723
|
5.0633
|
11
|
GHI
|
P
|
2014-10-09
|
0.25
|
5.3993
|
-0.4328
|
0.0265
|
-0.0064
|
0.212
|
-0.2385
|
-5.0104
|
12
|
GHI
|
C
|
2014-11-14
|
0.25
|
4.0187
|
0.4321
|
0.0292
|
-0.0115
|
0.2177
|
0.1634
|
6.7198
|
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 price information into a table*/
SELECT *
INTO #prices
FROM (VALUES
('ABC',495,0.35)
,('DEF',125,0.3)
,('GHI',62.5,0.25)
)p(ticker,price,vol)
/*put the options into a table*/
SELECT *
INTO #options
FROM (VALUES
(1,'ABC','2014-08-09',470,'C')
,(2,'ABC','2014-08-20',480,'P')
,(3,'ABC','2014-11-10',490,'P')
,(4,'ABC','2014-09-14',500,'C')
,(5,'DEF','2014-11-14',100,'C')
,(6,'DEF','2014-12-12',110,'C')
,(7,'DEF','2014-08-11',120,'P')
,(8,'DEF','2014-08-26',130,'C')
,(9,'GHI','2014-08-04',50,'C')
,(10,'GHI','2014-12-28',55,'C')
,(11,'GHI','2014-10-09',60,'P')
,(12,'GHI','2014-11-14',65,'C')
)o(rn,ticker,expiry,strike,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
SELECT A.rn
,A.ticker
,A.z
,A.expiry
,B.vol
,k.*
FROM #options A
INNER JOIN #prices B
ON A.ticker = B.ticker
INNER JOIN #rates C
ON A.expiry = C.expiry
CROSS APPLY wct.ProportionalDividendsPriceNGreeks(
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)) + '''' ,B.vol
,100
)k
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
|
expiry
|
vol
|
Price
|
Delta
|
Gamma
|
Theta
|
Vega
|
Rho
|
Lambda
|
1
|
ABC
|
C
|
2014-08-09
|
0.35
|
60.984
|
0.5935
|
0.0029
|
-0.1212
|
1.5028
|
1.2231
|
4.8176
|
2
|
ABC
|
P
|
2014-08-20
|
0.35
|
55.1905
|
-0.4278
|
0.0027
|
-0.1082
|
1.5694
|
-1.641
|
-3.8367
|
3
|
ABC
|
P
|
2014-11-10
|
0.35
|
71.811
|
-0.4501
|
0.0023
|
-0.0927
|
1.8062
|
-2.4518
|
-3.1029
|
4
|
ABC
|
C
|
2014-09-14
|
0.35
|
50.9857
|
0.5066
|
0.0027
|
-0.1138
|
1.6768
|
1.3041
|
4.9179
|
5
|
DEF
|
C
|
2014-11-14
|
0.3
|
27.9444
|
0.8157
|
0.0082
|
-0.0163
|
0.3033
|
0.4455
|
3.6489
|
6
|
DEF
|
C
|
2014-12-12
|
0.3
|
21.5964
|
0.7024
|
0.0097
|
-0.0191
|
0.4257
|
0.5027
|
4.0654
|
7
|
DEF
|
P
|
2014-08-11
|
0.3
|
10.2808
|
-0.4013
|
0.0125
|
-0.0237
|
0.3913
|
-0.3804
|
-4.8795
|
8
|
DEF
|
C
|
2014-08-26
|
0.3
|
9.7875
|
0.4689
|
0.0128
|
-0.0251
|
0.4059
|
0.3055
|
5.9891
|
9
|
GHI
|
C
|
2014-08-04
|
0.25
|
12.7382
|
0.9395
|
0.0151
|
-0.0054
|
0.0508
|
0.1014
|
4.6098
|
10
|
GHI
|
C
|
2014-12-28
|
0.25
|
8.8597
|
0.76
|
0.0327
|
-0.0112
|
0.1781
|
0.1698
|
5.361
|
11
|
GHI
|
P
|
2014-10-09
|
0.25
|
6.0193
|
-0.461
|
0.0264
|
-0.0086
|
0.2133
|
-0.262
|
-4.7867
|
12
|
GHI
|
C
|
2014-11-14
|
0.25
|
3.6391
|
0.4122
|
0.0309
|
-0.0105
|
0.2132
|
0.1437
|
7.08
|