DBA Data[Home] [Help]

PACKAGE: APPS.XTR_FX_FORMULAS

Source


1 PACKAGE XTR_FX_FORMULAS AS
2 /* $Header: xtrfxfls.pls 120.2 2005/06/29 08:06:01 badiredd ship $ */
3 
4 --
5 /*-----------------------------------------------------------------------
6 FX_GK_OPTION_PRICE_CV
7 Cover procedure to calculate the price of a currency option
8 using Garman-Kohlhagen formula, which is the extension of
9 Black-Scholes formula.
10 
11 IMPORTANT: it is better to supply a Simple 30/360 (from GET_MD_FROM_SET)
12 interest rates for this procedure in order to avoid redundant conversions.
13 
14 IMPORTANT: this procedure is only accurate up to six decimal places due
15 to CUMULATIVE_NORM_DISTRIBUTION procedure it calls.
16 
17 GK_OPTION_CV_IN_REC_TYPE:
18 p_SPOT_DATE date
19 p_MATURITY_DATE date
20 p_RATE_DOM num
21 p_RATE_TYPE_DOM varchar2(1) DEFAULT 'S'
22 p_COMPOUND_FREQ_DOM num
23 p_DAY_COUNT_BASIS_DOM varchar2(15)
24 p_RF_RATE_FOR num
25 p_RATE_TYPE_FOR varchar2(1) DEFAULT 'S'
26 p_COMPOUND_FREQ_FOR num
27 p_DAY_COUNT_BASIS_FOR varchar2(15)
28 p_SPOT_RATE num
29 p_STRIKE_RATE num
30 p_VOLATILITY num
31 
32 GK_OPTION_CV_OUT_REC_TYPE:
33 p_CALL_PRICE num
34 p_PUT_PRICE num
35 p_FX_FWD_RATE num
36 p_Nd1 num
37 p_Nd2 num
38 p_Nd1_a num
39 p_Nd2_a num
40 
41 Formula:
42 1. Converts interest rates to fit the FX_GK_OPTION_PRICE assumptions.
43 2. Calls FX_GK_OPTION_PRICE.
44 
45 Example to calculate p_SPOT_RATE:
46 Given: CAD = foreign, USD = domestic
47 1 USD = 1.5 CADThen: p_SPOT_RATE = 0.666667
48 
49 p_SPOT_DATE = the spot date where the option value is evaluated
50 p_MATURITY_DATE = the maturity date where the option expires
51 p_RF_RATE_DOM = domestic risk free interest rate.
52 p_RATE_TYPE_DOM/FOR = the p_RF_RATE_DOM/FOR rate's type. 'S' for Simple
53  Rate. 'C' for Continuous Rate, and 'P' for Compounding Rate.
54 Default value = 'S' (Simple IR)
55 p_DAY_COUNT_BASIS_DOM/FOR = day count basis for p_RF_RATE_DOM/FOR.
56 p_RATE_FOR = foreign risk free interest rate.
57 p_SPOT_RATE = the current market exchange rate = the value of one unit
58 of the foreign currency measured in the domestic currency.
59 p_STRIKE_RATE = the strike price agreed in the option.
60 p_VOLATILITY = volatility
61 p_CALL_PRICE = theoretical fair value of the call.
62 p_PUT_PRICE = theoretical fair value of the put
63 p_FX_FWD_RATE = the forward rate of the exchange calculated from the
64 p_SPOT_RATE
65 p_Nd1/2 = cumulative distribution value given limit probability values
66 in Black's formula = N(x) (refer to Hull's Fourth Edition p.252)
67 p_Nd1/2_a = N'(x) in Black's formula (refer to Hull's Fourth Edition p.252)
68 p_COMPOUND_FREQ_DOM/FOR = frequencies of discretely compounded input/output
69 rate. This is only necessary if p_RATE_TYPE_DOM/FOR is 'P'.
70 -----------------------------------------------------------------------*/
71 TYPE GK_OPTION_CV_IN_REC_TYPE IS RECORD (p_SPOT_DATE date,
72 					p_MATURITY_DATE date,
73 					p_RATE_DOM NUMBER,
74 				p_RATE_TYPE_DOM varchar2(1) DEFAULT 'S',
75 					p_COMPOUND_FREQ_DOM NUMBER,
76 					p_DAY_COUNT_BASIS_DOM varchar2(15),
77 					p_RATE_FOR NUMBER,
78 				p_RATE_TYPE_FOR varchar2(1) DEFAULT 'S',
79 					p_COMPOUND_FREQ_FOR NUMBER,
80 					p_DAY_COUNT_BASIS_FOR varchar2(15),
81 					p_SPOT_RATE NUMBER,
82 					p_STRIKE_RATE NUMBER,
83 					p_VOLATILITY NUMBER);
84 
85 TYPE GK_OPTION_CV_OUT_REC_TYPE IS RECORD (p_CALL_PRICE NUMBER,
86 					p_PUT_PRICE NUMBER,
87 					p_FX_FWD_RATE NUMBER,
88 					p_Nd1 NUMBER,
89 					p_Nd2 NUMBER,
90 					p_Nd1_a NUMBER,
91 					p_Nd2_a NUMBER);
92 
93 PROCEDURE FX_GK_OPTION_PRICE_CV(p_in_rec IN GK_OPTION_CV_IN_REC_TYPE,
94 				p_out_rec OUT NOCOPY GK_OPTION_CV_OUT_REC_TYPE);
95 
96 /*-----------------------------------------------------------------------
97 Calculates the FX Spot Rate for different currencies exchange.
98 
99 Formula:
100 * If the BASIS_CONTRA/BASE is not 'C' (Commodity Unit Quote) then convert with FX FORWARD (HLD) Formula 1
101 * Check CURRENCY_CONTRA and CURRENCY_BASE if  cross-currency pair is involved then  use FX FORWARD (HLD) Formula 2
102 
103 Formula 1 is converting from Base Unit Quote to Commodity Unit Quote, and vice versa.
104 Formula 2 is to calculate the SPOT RATE(=Cross Rate)
105 
106 Assumption: p_RATE_ CONTRA and p_RATE_ BASE have the same day count basis.
107 
108 For IRS:  BASE = Receive Leg
109           CONTRA = Pay Leg
110 Example for FX:CHFGBP -> CHF = Base Currency
111                          GBP = Contra Currency
112 
113 IF there is a notion of BID and ASK then:
114 To find p_SPOT_RATE (BID/ASK):
115 FOR CONTRA:
116   IF p_BASIS_CONTRA = 'C' THEN
117      p_RATE_CONTRA (BID/ASK) = BID/ASK Rate of
118        Contra Currency
119   ELSE
120      p_RATE_CONTRA (BID/ASK) = ASK/BID Rate of
121         Contra Currency
122 FOR BASE:
123   IF p_BASIS_BASE = 'C' THEN
124     p_RATE_BASE (BID/ASK) = ASK/BID Rate of Base
125         Currency
126   ELSE
127     p_RATE_BASE (BID/ASK) = BID/ASK Rate of Base
128         Currency
129 
130 * p_RATE_CONTRA/BASE = FX rate of the contra/base side against USD
131 (p_RATE_CONTRA = Rate vs. USD Contra, p_RATE_ BASE = Rate vs. USD Base).
132 If the currency is USD then p_RATE = 1;
133 * p_CURRENCY_CONTRA/BASE = the currency for contra/base.
134 * p_BASIS_CONTRA/BASE indicates the quotation basis against USD for the CONTRA
135 BASE side, 'C' for Commodity Unit Quote (=USDGBP) and 'B' for Base Unit Quote=
136 GBPUSD) (Definitions are in FX Calculator HLD)
137 * p_SPOT_RATE = fair exchange rate of two different currencies.
138 -----------------------------------------------------------------------*/
139 
140 PROCEDURE FX_SPOT_RATE (p_currency_contra IN VARCHAR2,
141                         p_currency_base IN VARCHAR2,
142                         p_rate_contra IN NUMBER,
143                         p_rate_base IN NUMBER,
144                         p_basis_contra IN CHAR,
145                         p_basis_base IN CHAR,
146                         p_spot_rate IN OUT NOCOPY NUMBER);
147 
148 
149 
150 /*-------------------------------------------------------------------------
151 Calculates the FX Forward Rate
152 
153 Formula:
154 FX FORWARD (HLD) Formula 3
155 
156 Example for FX: CHFGBP -> CHF = Base Currency
157                           GBP = Contra Currency
158 
159 IF there is a notion of BID and ASK then:
160 To find p_FORWARD_RATE (BID):
161     p_SPOT_RATE = BID FX Spot Rate
162     p_BASE_CURR_INT_RATE = ASK Base Currency risk free interest rate.
163     p_CONTRA_CURR_INT_RATE = BID Contra Currency risk free interest rate.
164 
165 To find p_FORWARD_RATE (ASK):
166     p_SPOT_RATE = ASK FX Spot Rate
167     p_BASE_CURR_INT_RATE = BID Base Currency risk free interest rate.
168     p_CONTRA_CURR_INT_RATE = ASK Contra Currency risk free interest rate.
169 
170 
171 * p_SPOT_RATE = fair exchange rate of two different currencies.
172 * p_BASE/CONTRA_CURR_INT_RATE = risk free interest rate for the base/contra
173 currency.
174 * p_DAY_COUNT_BASE/CONTRA = number of days between the spot date and the
175 forward
176 date.
177 * p_ANNUAL_BASIS_BASE/CONTRA = number of days in a year of which the
178 * p_DAY_COUNT_BASE/CONTRA and the p_BASE/CONTRA_CURR_INT_RATE are based on.
179 -------------------------------------------------------------------------*/
180 
181 PROCEDURE FX_FORWARD_RATE (p_spot_rate IN NUMBER,
182                            p_base_curr_int_rate IN NUMBER,
183                            p_contra_curr_int_rate IN NUMBER,
184                            p_day_count_base IN NUMBER,
185                            p_day_count_contra IN NUMBER,
186                            p_annual_basis_base IN NUMBER,
187                            p_annual_basis_contra IN NUMBER,
188                            p_forward_rate IN OUT NOCOPY NUMBER);
189 
190 
191 /*---------------------------------------------------------------------------
192 FX Option Pricing (Garman Kohlagen's Method)
193 Calculates the price and sensitivity of a currency option and its associated greek ratio's using Garman-Kohlhagen formula, which is the extension of Black-Scholes formula.
194 
195 Formula:
196 Taken from Currency Option Pricing Formula in Hull's Option, Future, and Other Derivatives, Third Edition p.272, p. 317.
197 (Defined in xtrprc2b.pls)
198 
199 Currently used in xtrrevlb.pld
200 
201 Call XTR_RATE_CONVERSION.rate_conversion to convert day counts and/or between compounded and simple interest rates.
202 
203 * l_days = time left to maturity in days(assuming 30/360 day count basis).
204 * l_base_int_rate = annual risk free interest rate for base currency.
205 * l_contra_int_rate = annual risk free interest rate for contra currency.
206 * l_spot_rate = the current market rate for the exchange.
207 * l_strike_price = the strike price agreed in the option.
208 * vol = volatility
209 * l_call_price = theoretical fair value of the call.
210 * l_put_price = theoretical fair value of the put
211 * l_fwd_price = the forward rate of the exchange calculated from the l_spot_rate
212 * l_delta_call/put = delta of the call/put
213 * l_theta_call/put = theta of the call/put
214 * l_rho_call/put = rho of the call/put (with respect to the change in base interest rate)
215 * l_gamma = gamma
216 * l_vega = vega
217 * l_nd1/2 = cumulative normal probability distribution value = N(x) in Black Formu
218 la
219 * l_nd1/2_a = N'(x) in Black Formula
220 
221 
222 gamma, theta, delta, vega are sensitivity measurements of the model relatives to its different variables and explained extensively in Hull's Option, Future, and Other Derivatives.
223 ----------------------------------------------------------------------------*/
224 -- modified fhu 6/13/01
225 PROCEDURE FX_GK_OPTION_PRICE(
226                              l_days         IN NUMBER,
227                              l_base_int_rate IN NUMBER,
228                              l_contra_int_rate IN NUMBER,
229                              l_spot_rate     IN NUMBER,
230                              l_strike_rate   IN NUMBER,
231                              vol IN NUMBER,
232                              l_call_price IN OUT NOCOPY NUMBER,
233                              l_put_price IN OUT NOCOPY NUMBER,
234                              l_fwd_rate IN OUT NOCOPY NUMBER,
235 			     l_nd1 IN OUT NOCOPY NUMBER,
236 			     l_nd2 IN OUT NOCOPY NUMBER,
237 			     l_nd1_a IN OUT NOCOPY NUMBER,
238 			     l_nd2_a IN OUT NOCOPY NUMBER  );
239 --added by sankim 9/10/01
240 /*
241 FX_SPOT_RATE_CV (FUNCTION)Cover routine that calculates the FX Spot Rate for
242 bid and ask side of different currencies exchange.In order to make the cover
243 routine easier to be called from Java (middle tier) directly, the record type
244 is not used to encapsulate the arguments. Moreover, function is used instead of
245  procedure since function can be called from SQL.
246 Parameters
247 * p_RATE_CONTRA/BASE_BID/ASK = FX rate of the contra/base currency against USD
248 for bid/ask side (p_RATE_ CONTRA = Rate vs. USD Contra, p_RATE_ BASE = Rate vs.
249  USD Base). If the currency is USD then use the default rate (=1).
250 * p_CURRENCY_CONTRA/BASE = the currency for contra/base.
251  p_QUOTATION_BASIS_CONTRA/BASE indicates the quotation basis against USD for
252 the CONTRA /BASE side, 'C' for Commodity Unit Quote (=USDGBP) and 'B' for Base
253 Unit Quote (= GBPUSD) (Definitions are in FX Calculator HLD)
254 * Returned: p_SPOT_RATE (BID/ASK) = fair exchange rate of two different
255 currencies of side bid/ask.
256 */
257 FUNCTION FX_SPOT_RATE_CV( p_currency_contra IN VARCHAR2,
258 			  p_currency_base IN VARCHAR2,
259 			  p_rate_contra_bid IN NUMBER DEFAULT 1,
260 			  p_rate_contra_ask IN NUMBER DEFAULT 1,
261 			  p_rate_base_bid IN NUMBER DEFAULT 1,
262 			  p_rate_base_ask IN NUMBER DEFAULT 1,
263 			  p_quotation_basis_contra IN VARCHAR2 DEFAULT 'C',
264 			  p_quotation_basis_base IN VARCHAR2 DEFAULT 'C')
265 	RETURN XTR_MD_NUM_TABLE;
266 --added by sankim 9/10/01
267 /*
268 FX_FORWARD_RATE_CV (FUNCTION)A cover routine that calculates the FX Forward
269 Rate for  exchange that has USD as the base.In order to make the cover routine
270 easier to be called from Java (middle tier) directly, the record type is not
271 used to encapsulate the arguments. Moreover, function is used instead of
272 procedure since function can be called from SQL.
273 Parameters
274 * p_SPOT_RATE_BASE_BID/ASK = fair exchange rate of between the base currency
275 against USD. If the base currency is USD, then the default value of 1 should be
276  used.
277 * p_SPOT_RATE_CONTRA_BID/ASK = fair exchange rate of between the contra
278 currency against USD. If the contra currency is USD, then the default value of
279  1 should be used.
280 * p_BASE_CURR_INT_RATE_BID/ASK = bid/ask risk free interest rate for the base
281 currency.  This parameter should be null if the base currency is USD.
282 * p_CONTRA_CURR_INT_RATE_BID/ASK = bid/ask risk free interest rate for the
283 contra currency.  This parameter should be null if the contra currency is USD.
284 * p_USD _CURR_INT_RATE = risk free interest rate for the USD.
285 * p_DAY_COUNT_BASE/CONTRA = number of days between the spot date and the
286 forward date. If the contra currency is USD, then p_DAY_COUNT_CONTRA should be
287 null, and vice versa in the case of base is USD.
288 * p_ANNUAL_BASIS_BASE/CONTRA = number of days in a year of which the
289 p_DAY_COUNT_BASE/CONTRA and the p_BASE/CONTRA_CURR_INT_RATE are based on. If
290 the contra currency is USD, then p_ANNUAL_BASIS_CONTRA should be null, and vice
291  versa in the case of base is USD.
292 * p_DAY_COUNT_USD = number of days between the spot date and the forward date.
293 = number of days in a year of which the p_DAY_COUNT_USD and the
294 p_USD _CURR_INT_RATE are based on.
295 * p_ANNUAL_BASIS_USD = number of days in a year of which the p_DAY_COUNT_USD
296 and the p_USD _CURR_INT_RATE are based on.
297 * p_CURRENCY_CONTRA/BASE = the currency for contra/base.
298 * p_QUOTATION_BASIS_CONTRA/BASE indicates the quotation basis against USD for
299 the CONTRA /BASE side, 'C' for Commodity Unit Quote (=USDGBP) and 'B' for Base
300 Unit Quote (= GBPUSD) (Definitions are in FX Calculator HLD). This parameter is
301  required if base/contra is non-USD accordingly.
302 * Returned: p_FORWARD_RATE (BID/ASK) indicates the bid/ask side of forward rate
303  results.
304 */
305 FUNCTION FX_FORWARD_RATE_CV( p_spot_rate_base_bid IN NUMBER DEFAULT 1,
306 			     p_spot_rate_base_ask IN NUMBER DEFAULT 1,
307 			     p_spot_rate_contra_bid IN NUMBER DEFAULT 1,
308 			     p_spot_rate_contra_ask IN NUMBER DEFAULT 1,
309       			     p_base_curr_int_rate_bid IN NUMBER,
310 			     p_base_curr_int_rate_ask IN NUMBER,
311 			     p_contra_curr_int_rate_bid IN NUMBER,
312 			     p_contra_curr_int_rate_ask IN NUMBER,
313  			     p_usd_curr_int_rate_bid IN NUMBER,
314 			     p_usd_curr_int_rate_ask IN NUMBER,
315  			     p_day_count_base IN NUMBER,
316 			     p_day_count_contra IN NUMBER,
317 			     p_day_count_usd IN NUMBER,
318 			     p_annual_basis_base IN NUMBER,
319 			     p_annual_basis_contra IN NUMBER,
320 			     p_annual_basis_usd IN NUMBER,
321 			     p_currency_base IN VARCHAR2,
322 			     p_currency_contra IN VARCHAR2,
323 			     p_quotation_basis_base IN VARCHAR2 DEFAULT 'C',
327 END XTR_FX_FORMULAS;
324 			     p_quotation_basis_contra IN VARCHAR2 DEFAULT 'C')
325 	RETURN XTR_MD_NUM_TABLE;
326