1 PACKAGE XTR_RATE_CONVERSION AS
2 /* $Header: xtrrtcvs.pls 120.1 2005/06/29 09:32:44 rjose ship $ */
3
4 /*----------------------------------------------------------------------------
5 addition by prafiuly 02/05/01
6
7 RATE_CONVERSION: converts between two rates that have different day count basis
8 or compounding types.
9
10 Note: this procedure does not cover DISCOUNT_TO_YIELD_RATE and
11 YIELD_TO_DISCOUNT_RATE conversions.
12
13 ******************************************************************************
14 IMPORTANT: the result of doing day count basis conversion first and then doing
15 rate type conversion second is different from the result of doing the rate
16 type conversion first and then doing the day count basis conversion second.
17 This causes some inconsistencies in the result. For example: the result of
18 converting from a simple rate to a compounded rate with different day count
19 basis and then converting it back to a simple rate type with its original
20 day count basis will not be the same as the original value of the simple rate.
21 The problem is not caused by the implementation/coding, but is caused by
22 methodologies used as described in the Rate Conversions HLD.
23 ******************************************************************************
24
25 Assumption: the effective period for the rates is one year.
26
27 p_START_DATE = the start date when the rates becomes effective.
28 p_END_DATE = the end date of the rates.
29 p_DAY_COUNT_BASIS_IN/OUT = the day count basis for the input rate and the
30 output rate. This are only necessary if the rates day count basis are different.
31 p_RATE_TYPE_IN/OUT = the input/output rates type. 'S' for Simple Rate, 'C' for
32 Continuous Rate, and 'P' for Compounding Rate. This is only necessary if the
33 conversion involve different rate types.
34 p_COMPOUND_FREQ_IN/OUT = frequencies of discretely compounded input/output rate.
35 This is only necessary if either p_RATE_TYPE_IN or p_RATE_TYPE_OUT is 'P'.
36 p_RATE_IN/OUT = the input/output rates.
37 -----------------------------------------------------------------------------*/
38
39 TYPE rate_conv_in_rec_type is RECORD (p_START_DATE DATE,
40 p_END_DATE DATE,
41 p_DAY_COUNT_BASIS_IN VARCHAR2(20),
42 p_DAY_COUNT_BASIS_OUT VARCHAR2(20),
43 p_RATE_TYPE_IN CHAR,
44 p_RATE_TYPE_OUT CHAR,
45 p_COMPOUND_FREQ_IN NUMBER,
46 p_COMPOUND_FREQ_OUT NUMBER,
47 p_RATE_IN NUMBER);
48
49 TYPE rate_conv_out_rec_type is RECORD ( p_RATE_OUT NUMBER);
50
51
52 /*---------------------------------------------------------------------------
53 DISCOUNT_FACTOR_CONV
54 Converts an annualized yield rate to a discount factor and vice versa
55
56 Assumption:
57 If p_RATE_TYPE, p_COMPOUND_FREQ(if p_RATE_TYPE='P'), p_FUTURE_DATE,
58 p_SPOT_DATE, and p_DAY_COUNT_BASIS are not null then use them to calculate the
59 discount factor, else use p_DAY_COUNT and p_ANNUAL_BASIS, if they are not null.
60 If p_DAY_COUNT is null then p_FUTURE_DATE, p_SPOT_DATE, and p_DAY_COUNT_BASIS
61 are used to calculate the day count and the annual basis.
62 The first method should be used to avoid errors due to inconsistent rate type
63 and problem in determining a period less than or greater than a year
64 (please refer to Bug 2295869 and related Bug 2354567).
65
66 p_INDICATOR = an indicator that tells whether the conversion is from yield
67 rate to discount factor ('T') or from discount factor to yield rate ('F').
68 p_RATE = the annualized yield rate or the discount factor depending on the
69 value of the p_INDICATOR.
70 p_DAY_COUNT = the number of days for which the p_GROWTH_FACTOR is calculated
71 p_ANNUAL_BASIS = number of days in a year where the p_RATE and the p_DAY_COUNT
72 are based on.
73 p_RESULT = the discount factor or the annualized yield rate depending on the
74 value of the p_INDICATOR.
75 p_SPOT_DATE = the start date of the p_RATE.
76 p_FUTURE_DATE = the end date of the p_RATE.
77 p_RATE_TYPE = the p_RATE rate's type. 'S' for Simple Rate. 'C' for
78 Continuous Rate, and 'P' for Compounding Rate.
79 p_COMPOUND_FREQ = frequencies of discretely compounded input rate.
80 p_DAY_COUNT_BASIS = the day count basis of p_RATE.
81 ---------------------------------------------------------------------------*/
82 TYPE df_in_rec_type IS RECORD (p_indicator VARCHAR2(1),
83 --'T' to convert from yield rate to disc. factor
84 --'F' to convert from disc. factor to yield rate
85 p_rate NUMBER,
86 p_day_count NUMBER DEFAULT NULL,
87 p_annual_basis NUMBER DEFAULT NULL,
88 p_spot_date DATE,
89 p_future_date DATE,
90 p_day_count_basis VARCHAR2(20),
91 p_rate_type VARCHAR2(1),
92 p_compound_freq NUMBER);
93 TYPE df_out_rec_type IS RECORD (p_result NUMBER);
94
95
96 --
97 -- Converts a discount rate to a yield rate.
98 --
99 -- * P_DISCOUNT_RATE = the return in discounted security as an annualized
100 -- percentage of the future amount.
101 -- * P_DAY_COUNT = number of days between the start deal date and maturity
102 -- deal date.
103 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
104 -- P_DAY_COUNT are based on.
105 -- * P_YIELD_RATE = the return in discounted security as an annualized
106 -- percentage of the current amount.
107 --
108 -- The formula is
109 -- 100 * annual basis * discount rate
110 -- p_discount_rate = ------------------------------------------------
111 -- 100 * annual basis - day count * discount rate
112 --
113 PROCEDURE discount_to_yield_rate(p_discount_rate IN NUMBER,
114 p_day_count IN NUMBER,
115 p_annual_basis IN NUMBER,
116 p_yield_rate IN OUT NOCOPY NUMBER);
117
118
119
120 --
121 -- Converts a discount rate to a yield rate.
122 --
123 -- * P_YIELD_RATE = the return in discounted security as an annualized
124 -- percentage of the current amount.
125 -- * P_DAY_COUNT = number of days between the deal start date and deal
126 -- maturity date.
127 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
128 -- P_DAY_COUNT are based on.
129 -- * P_DISCOUNT_RATE = the return in discounted security as an annualized
130 -- percentage of the future amount.
131 --
132 -- The formula is
133 -- 100 * annual basis * yield rate
134 -- p_discount_rate = ---------------------------------------------
135 -- 100 * annual basis + day count * yield rate
136 --
137 PROCEDURE yield_to_discount_rate(p_yield_rate IN NUMBER,
138 p_day_count IN NUMBER,
139 p_annual_basis IN NUMBER,
140 p_discount_rate IN OUT NOCOPY NUMBER);
141
142 --
143 -- Converts between rates of different day count basis.
144 --
145 -- * P_RATE_IN/OUT= annualized return/rate for the input/output rate.
146 -- * P_DAY_COUNT_IN/OUT = number of days between the deal start date and
147 -- deal maturity date for the input rate/output rate.
148 -- * P_ANNUAL_BASIS_IN/OUT = number of days in a year where the RATE and
149 -- the P_DAY_COUNT are based on.
150 --
151 PROCEDURE day_count_basis_conv(p_day_count_in IN NUMBER,
152 p_day_count_out IN NUMBER,
153 p_annual_basis_in IN NUMBER,
154 p_annual_basis_out IN NUMBER,
155 p_rate_in IN NUMBER,
156 p_rate_out IN OUT NOCOPY NUMBER);
157
158
159 --
160 -- Converts a simple rate to a continuously compounded rate with
161 -- the same day count basis.
162 --
163 -- * P_SIMPLE_RATE = interest rate per annum that does not compound over time.
164 -- * P_NUM_YEARS = number of years in the period for which the rate is
165 -- effective.
166 -- * P_CONTINUOUS_RATE = compounded rate that has infinitesimal accrual time.
167 --
168 PROCEDURE simple_to_continuous_rate(p_simple_rate IN NUMBER,
169 p_num_years IN NUMBER,
170 p_continuous_rate IN OUT NOCOPY NUMBER);
171
172
173
174 --
175 -- Converts continuously compounded rate to a simple rate with
176 -- the same day count basis.
177 --
178 -- * P_SIMPLE_RATE = interest rate per annum that does not compound over time.
179 -- * P_NUM_YEARS = number of years in the period for which the rate is
180 -- effective.
181 -- * P_CONTINUOUS_RATE = compounded rate that has infinitesimal accrual time.
182 --
183 PROCEDURE continuous_to_simple_rate(p_continuous_rate IN NUMBER,
184 p_num_years IN NUMBER,
185 p_simple_rate IN OUT NOCOPY NUMBER);
186
187
188
189 --
190 -- Converts a simple rate to a discretely compounded rate with the same
191 -- day count basis.
192 --
193 -- * P_SIMPLE_RATE = interest rate per annum that does not compound overtime.
194 -- * P_NUM_YEARS = number of years in the period for which the rate is
195 -- effective.
196 -- * P_COMPOUNDTIMES = accrual frequency in a year for the P_COMPOUNDRATE.
197 -- * P_COMPOUNDRATE = a discretely compounded rate.
198 --
199 PROCEDURE simple_to_compound_rate(p_simple_rate IN NUMBER,
200 p_compound_times IN NUMBER,
201 p_num_years IN NUMBER,
202 p_compound_rate IN OUT NOCOPY NUMBER);
203
204
205
206 --
207 -- Converts a discretely compounded rate to a simple rate with the same
208 -- day count basis.
209 --
210 -- * P_SIMPLE_RATE = interest rate per annum that does not compound overtime.
211 -- * P_NUM_YEARS = number of years in the period for which the rate is
212 -- effective.
213 -- * P_COMPOUNDTIMES = accrual frequency in a year for the P_COMPOUNDRATE.
214 -- * P_COMPOUNDRATE = a discretely compounded rate.
215 --
216 PROCEDURE compound_to_simple_rate(p_compound_rate IN NUMBER,
217 p_compound_times IN NUMBER,
218 p_num_years IN NUMBER,
219 p_simple_rate IN OUT NOCOPY NUMBER);
220
221
222
223 --
224 -- Converts a continuously compounded rate to a discretely compounded rate
225 -- with the same day count basis.
226 --
227 -- * P_CONTINUOUS_RATE = compounded rate that has infinitesimal accrual time.
228 -- * P_COMPOUNDRATE = a discretely compounded rate.
229 -- * P_COMPOUNDTIMES = accrual frequency in a year for the P_COMPOUNDRATE.
230 --
231 PROCEDURE continuous_to_compound_rate(p_continuous_rate IN NUMBER,
232 p_compound_times IN NUMBER,
233 p_compound_rate IN OUT NOCOPY NUMBER);
234
235
236
237 --
238 -- Converts a discretely compounded rate to a continuously compounded
239 -- rate with the same day count basis.
240 --
241 -- * P_CONTINUOUS_RATE = compounded rate that has infinitesimal accrual time.
242 -- * P_COMPOUNDRATE = a discretely compounded rate.
243 -- * P_COMPOUNDTIMES = accrual frequency in a year for the P_COMPOUNDRATE.
244 --
245 PROCEDURE compound_to_continuous_rate(p_compound_rate IN NUMBER,
246 p_compound_times IN NUMBER,
247 p_continuous_rate IN OUT NOCOPY NUMBER);
248
249
250
251 --
252 -- Converts between two different discretely compounded interest rates with
253 -- different compounding frequency (with the same day count basis).
254 --
255 -- * P_COMPOUNDRATE_IN= a discretely compounded rate that is to be converted.
256 -- * P_COMPOUNDTIMES_IN/OUT = accrual frequency in a year for the
257 -- P_COMPOUNDRATE_IN/OUT.
258 -- * P_COMPOUNDRATE_OUT = a discretely compounded rate that is to be
259 -- calculated.
260 --
261 PROCEDURE compound_to_compound_rate(p_compound_rate_in IN NUMBER,
262 p_compound_times_in IN NUMBER,
263 p_compound_times_out IN NUMBER,
264 p_compound_rate_out IN OUT NOCOPY NUMBER);
265
266
267
268 /*----------------------------------------------------------------------------
269 addition by prafiuly 02/05/01
270
271 RATE_CONVERSION: converts between two rates that have different day count basis
272 or compounding types.
273
274 Note: this procedure does not cover DISCOUNT_TO_YIELD_RATE and
275 YIELD_TO_DISCOUNT_RATE conversions.
276
277 ******************************************************************************
278 IMPORTANT: the result of doing day count basis conversion first and then doing
279 rate type conversion second is different from the result of doing the rate
280 type conversion first and then doing the day count basis conversion second.
281 This causes some inconsistencies in the result. For example: the result of
282 converting from a simple rate to a compounded rate with different day count
283 basis and then converting it back to a simple rate type with its original
284 day count basis will not be the same as the original value of the simple rate.
285 The problem is not caused by the implementation/coding, but is caused by
286 methodologies used as described in the Rate Conversions HLD.
287 ******************************************************************************
288
289 RATE_CONV_IN_REC_TYPE:
290 p_START_DATE date
291 p_END_DATE date
292 p_DAY_COUNT_BASIS_IN varchar2
293 p_DAY_COUNT_BASIS_OUT varchar2
294 p_RATE_TYPE_IN char
295 p_RATE_TYPE _OUT char
296 p_COMPOUND_FREQ_IN num
297 p_COMPOUND_FREQ_OUT num
298 p_RATE_IN num
299 RATE_CONV_OUT_REC_TYPE:
300 p_ RATE_OUT num
301
302 Formula:
303 Call XTR_CALC_P.DAYS_CALC_RUN_C(...);
304 IF p_DAY_COUNT_BASIS_IN?OUT is NOT NULL THEN
305 Call DAY_COUNT_BASIS_CONV(...)
306 IF p_RATE_TYPE_IN/OUT is NOT NULL THEN
307 Calculate v_Num_Years
308 Depending on p_RATE_TYPE_IN/OUT, call the appropriate Rate Types Conversion
309 procedure (from above).
310
311 Assumption: the effective period for the rates is one year.
312
313 p_START_DATE = the start date when the rates becomes effective.
314 p_END_DATE = the end date of the rates.
315 p_DAY_COUNT_BASIS_IN/OUT = the day count basis for the input rate and the
316 output rate. This are only necessary if the rates day count basis are
317 different.
318 p_RATE_TYPE_IN/OUT = the input/output rates type. 'S' for Simple Rate, 'C' for
319 Continuous Rate, and 'P' for Compounding Rate. This is only necessary if the
320 conversion involve different rate types.
321 p_COMPOUND_FREQ_IN/OUT = frequencies of discretely compounded input/output
322 rate.
323 This is only necessary if either p_RATE_TYPE_IN or p_RATE_TYPE_OUT is 'P'.
324 p_RATE_IN/OUT = the input/output rates.
325 -----------------------------------------------------------------------------*/
326 PROCEDURE rate_conversion (p_in_rec IN rate_conv_in_rec_type,
327 p_out_rec IN OUT NOCOPY rate_conv_out_rec_type);
328
332 --Converts an annualized yield rate to a discount factor, assuming the number
329
330 --
331 --YIELD_TO_DISCOUNT_FACTOR_SHORT
333 --of days between spot date and maturity date is less than or equal to a year.
334 --
335 -- * P_RATE = the annualized yield rate.
336 -- * P_DAY_COUNT = the number of days for which the GROWTH_FACTOR
337 -- is calculated
338 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
339 -- DAY_COUNT are based on
340 -- * P_DISCOUNT_FACTOR = the value of the consideration/present value
341 -- in order to have $1 in the maturity date (after DAY_COUNT period)
342 --
343 PROCEDURE yield_to_discount_factor_short(p_rate IN NUMBER,
344 p_day_count IN NUMBER,
345 p_annual_basis IN NUMBER,
346 p_discount_factor IN OUT NOCOPY NUMBER);
347
348
349 --
350 --YIELD_TO_DISCOUNT_FACTOR_LONG
351 --Converts an annualized yield rate to a discount factor, assuming the number
352 --of days between spot date and maturity date is less than or equal to a year.
353 --
354 -- Calculates the value of the consideration/present value
355 -- in order to have $1 in the maturity date (after DAY_COUNT period),
356 -- assuming more than a year DAY_COUNT period.
357 --
358 -- * P_RATE = the annualized yield rate.
359 -- * P_DAY_COUNT = the number of days for which the GROWTH_FACTOR
360 -- is calculated
361 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
362 -- DAY_COUNT are based on
363 -- * P_DISCOUNT_FACTOR = the value of the consideration/present value
364 -- in order to have $1 in the maturity date (after DAY_COUNT period)
365 --
366 PROCEDURE yield_to_discount_factor_long(p_rate IN NUMBER,
367 p_day_count IN NUMBER,
368 p_annual_basis IN NUMBER,
369 p_discount_factor IN OUT NOCOPY NUMBER);
370
371 --
372 --DISCOUNT_FACTOR_TO_YIELD_SHORT
373 --Converts a discount factor to an annualized yield rate, assuming the number
374 --of days between spot date and maturity date is less than or equal to a year.
375 --
376 -- * P_RATE = the annualized yield rate.
377 -- * P_DAY_COUNT = the number of days for which the GROWTH_FACTOR
378 -- is calculated
379 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
380 -- DAY_COUNT are based on
381 -- * P_DISCOUNT_FACTOR = the value of the consideration/present value
382 -- in order to have $1 in the maturity date (after DAY_COUNT period)
383 --
384 PROCEDURE discount_factor_to_yield_short(p_discount_factor IN NUMBER,
385 p_day_count IN NUMBER,
386 p_annual_basis IN NUMBER,
387 p_rate IN OUT NOCOPY NUMBER);
388
389
390 --
391 --DISCOUNT_FACTOR_TO_YIELD_LONG
392 --Converts an annualized yield rate to a discount factor, assuming the number
393 --of days between spot date and maturity date is more than a year.
394 --
395 -- * P_RATE = the annualized yield rate.
396 -- * P_DAY_COUNT = the number of days for which the GROWTH_FACTOR
397 -- is calculated
398 -- * P_ANNUAL_BASIS = number of days in a year where the RATE and the
399 -- DAY_COUNT are based on
400 -- * P_DISCOUNT_FACTOR = the value of the consideration/present value
401 -- in order to have $1 in the maturity date (after DAY_COUNT period)
402 --
403 PROCEDURE discount_factor_to_yield_long(p_discount_factor IN NUMBER,
404 p_day_count IN NUMBER,
405 p_annual_basis IN NUMBER,
406 p_rate IN OUT NOCOPY NUMBER);
407
408
409 /*---------------------------------------------------------------------------
410 DISCOUNT_FACTOR_CONV
411 Converts an annualized yield rate to a discount factor and vice versa
412
413 Assumption:
414 If p_RATE_TYPE, p_COMPOUND_FREQ(if p_RATE_TYPE='P'), p_FUTURE_DATE,
415 p_SPOT_DATE, and p_DAY_COUNT_BASIS are not null then use them to calculate the
416 discount factor, else use p_DAY_COUNT and p_ANNUAL_BASIS, if they are not null.
417 If p_DAY_COUNT is null then p_FUTURE_DATE, p_SPOT_DATE, and p_DAY_COUNT_BASIS
418 are used to calculate the day count and the annual basis.
419 The first method should be used to avoid errors due to inconsistent rate type
420 and problem in determining a period less than or greater than a year
421 (please refer to Bug 2295869 and related Bug 2354567).
422
423 p_INDICATOR = an indicator that tells whether the conversion is from yield
424 rate to discount factor ('T') or from discount factor to yield rate ('F').
425 p_RATE = the annualized yield rate or the discount factor depending on the
426 value of the p_INDICATOR.
427 p_DAY_COUNT = the number of days for which the p_GROWTH_FACTOR is calculated
428 p_ANNUAL_BASIS = number of days in a year where the p_RATE and the p_DAY_COUNT
429 are based on.
430 p_RESULT = the discount factor or the annualized yield rate depending on the
431 value of the p_INDICATOR.
432 p_SPOT_DATE = the start date of the p_RATE.
433 p_FUTURE_DATE = the end date of the p_RATE.
434 p_RATE_TYPE = the p_RATE rate's type. 'S' for Simple Rate. 'C' for
435 Continuous Rate, and 'P' for Compounding Rate.
436 p_COMPOUND_FREQ = frequencies of discretely compounded input rate.
437 ---------------------------------------------------------------------------*/
438 PROCEDURE discount_factor_conv(p_in_rec IN df_in_rec_type,
442 /*----------------------------------------------------------------------------
439 p_out_rec IN OUT NOCOPY df_out_rec_type);
440
441
443 RATE_CONV_SIMPLE_ANNUALIZED: converts the given rate to a simple rate
444 if the period between p_START_DATE and p_END_DATE is less than or equal
445 to a year or
446 to an annually compounded rate if the period between p_START_DATE and
447 p_END_DATE is greater than a year.
448
449 ******************************************************************************
450 IMPORTANT: The above is currently the assumption for the System Rates, and
451 what is expected for some of the cover routine API.
452 ******************************************************************************
453
454 Moreover, if p_DAY_COUNT_BASIS_OUT is NULL, this procedure will keep the
455 day count basis of p_RATE_IN, otherwise it will convert to whatever defined
456 in p_DAY_COUNT_BASIS_OUT.
457
458 Note: this procedure does not cover DISCOUNT_TO_YIELD_RATE and
459 YIELD_TO_DISCOUNT_RATE conversions.
460
461 RATE_CONV_IN_REC_TYPE:
462 p_START_DATE date
463 p_END_DATE date
464 p_DAY_COUNT_BASIS_IN varchar2
465 p_DAY_COUNT_BASIS_OUT varchar2
466 p_RATE_TYPE_IN char
467 p_COMPOUND_FREQ_IN num
468 p_RATE_IN num
469 RATE_CONV_OUT_REC_TYPE:
470 p_RATE_OUT num
471
472 Assumption: the effective period for the rates is one year.
473
474 p_START_DATE = the start date when the rates becomes effective.
475 p_END_DATE = the end date of the rates.
476 p_DAY_COUNT_BASIS_IN/OUT = the day count basis for the input rate and the
477 output rate. This are only necessary if the rates day count basis are
478 different.
479 p_RATE_TYPE_IN = the input rates type. 'S' for Simple Rate, 'C' for
480 Continuous Rate, and 'P' for Compounding Rate. This is only necessary if the
481 conversion involve different rate types.
482 p_COMPOUND_FREQ_IN = frequencies of discretely compounded input
483 rate.
484 This is only necessary if either p_RATE_TYPE_IN or p_RATE_TYPE_OUT is 'P'.
485 p_RATE_IN/OUT = the input/output rates.
486 -----------------------------------------------------------------------------*/
487 PROCEDURE rate_conv_simple_annualized (p_in_rec IN rate_conv_in_rec_type,
488 p_out_rec IN OUT NOCOPY rate_conv_out_rec_type);
489
490
491 END;
492