#include "cgeneral.h"
#include "bastypes.h"
#include "badday.h"
#include "tcurve.h"
#include "interp.h"
Data Structures | |
struct | ZCurve |
struct | TStubData |
struct | TInterpData |
Functions | |
TCurve * | JpmcdsZCToTCurve (ZCurve *zc) |
Constructs a TCurve from a ZCurve. | |
ZCurve * | JpmcdsZCFromTCurve (TCurve *tc) |
Constructs a ZCurve from a TCurve. | |
ZCurve * | JpmcdsZCMake (TDate valueDate, int n, long basis, long dayCountConv) |
Constructs a ZCurve. | |
void | JpmcdsZCFree (ZCurve *zc) |
Frees memory associated with a zero curve. | |
int | JpmcdsZCAddPrefixCurve (ZCurve *zc1, ZCurve *zc2) |
Adds points to a zero curve from another zero curve, but only those dates before first date of the other curve. | |
int | JpmcdsZCAddSuffixCurve (ZCurve *zc1, ZCurve *zc2) |
Adds points to a zero curve from another zero curve, but only those dates after last date of the other curve. | |
int | JpmcdsZCAddSwap (ZCurve *zc, TCurve *discZC, double price, TDate matDate, TBoolean onCycle, double rate, int fixedSwapFreq, int floatSwapFreq, long fixDayCountConv, long floatDayCountConv, long interpType, TInterpData *interpData, TBadDayList *badDayList, TBadDayAndStubPos badDayAndStubPos, char *holidayFile) |
Adds a single swap instrument to a ZCurve. | |
int | JpmcdsZCAddSwaps (ZCurve *zc, TCurve *discZC, TDate *inDates, double *inRates, int numSwaps, int fixedSwapFreq, int floatSwapFreq, long fixDayCountConv, long floatDayCountConv, long interpType, TInterpData *interpData, TBadDayList *badDayList, TBadDayAndStubPos badDayAndStubPos, char *holidayFile) |
Adds a strip of swap instruments to a ZCurve. | |
TDateList * | JpmcdsZCGetSwapCouponDL (TDate valueDate, TDate matDate, TBoolean stubAtEnd, TDateInterval *interval, TBadDayList *badDayList, long badDayConv, char *holidayFile) |
Makes a date list for all coupons associated w/ a swap instrument. | |
TCashFlowList * | JpmcdsZCGetSwapCFL (TDate valueDate, TDate matDate, TBoolean stubAtEnd, double rate, TDateInterval *interval, long dayCountConv, TBadDayList *badDayList, long badDayConv, char *holidayFile) |
Makes a cash flow list for a swap instrument. | |
int | JpmcdsZCAddMoneyMarket (ZCurve *zc, TDate dates[], double rates[], int n, long dayCountConv) |
Adds simple-interest money market bond to ZCurve. | |
int | JpmcdsZCAddCFLPoints (ZCurve *zc, TCashFlowList *cfl, TDate lastDate, long interpType, TInterpData *interpData) |
Adds points into a zero curve to match all points in a cashflow list after a certain date. | |
int | JpmcdsZCAddCashFlowList (ZCurve *zc, TCashFlowList *cfl, double price, TDate date, long interpType, TInterpData *interpData) |
Adds information represented by a list-of-cash-flows to a zero curve. | |
int | JpmcdsZCAddGenRate (ZCurve *zc, TDate date, double rate, long basis, long dayCountConv) |
Adds a general zero rate to a ZCurve. | |
int | JpmcdsZCAddDiscountFactor (ZCurve *zc, TDate date, double disc) |
Adds a discount factor (at a specified date) to a ZCurve. | |
int | JpmcdsZCAddRate (ZCurve *zc, TDate date, double rate) |
Adds a zero rate to a ZCurve. | |
int | JpmcdsZCAddRateAndDiscount (ZCurve *zc, TDate date, double rate, double disc) |
Adds a zero rate and discount to a ZCurv. | |
int | JpmcdsZCMoneyMarketRate (ZCurve *zc, TDate date, long dayCountConv, long interpType, TInterpData *interpData, double *rate) |
Calculates a simple interest money market rate from a zero curve. | |
int | JpmcdsZCForwardRate (ZCurve *zc, TDate date1, TDate date2, long basis, long dayCountConv, long interpType, TInterpData *interpData, double *rate) |
Calculates a forward rate from a zero curve. | |
int | JpmcdsZCFwdDiscountFactor (ZCurve *zc, TDate date1, TDate date2, long interpType, TInterpData *interpData, double *discount) |
Calculates a discount factor for a forward between two dates. | |
int | JpmcdsJpmcdsZCPresentValueCFL (ZCurve *zc, TCashFlowList *cfl, int iLo, int iHi, long interpType, TInterpData *interpData, double *pv) |
Calculates net-present-value of a cash-flow list. | |
int | JpmcdsZCPresentValue (ZCurve *zc, double price, TDate date, long interpType, TInterpData *interpData, double *pv) |
Calculates net-present-value of a cash-flow (a payment at a given date in the future). | |
int | JpmcdsZCDiscountFactor (ZCurve *zc, TDate date, long interpType, TInterpData *interpData, double *discount) |
Calculates discount factor for a date. | |
int | JpmcdsZCComputeDiscount (ZCurve *zc, TDate date, double rate, double *discount) |
Converts zc-style rate into a discount factor. | |
int | JpmcdsZCInterpolate (ZCurve *zc, TDate date, long interpType, TInterpData *interpData, double *rate) |
Calculates an interpolated rate for a date. | |
int | JpmcdsZCFindDateExact (ZCurve *zc, TDate date) |
Finds an exact date in a ZC. | |
int | JpmcdsZCFindDateClosest (ZCurve *zc, TDate date) |
Finds index of entry closest to an input date. | |
int | JpmcdsZCValueFixFltSwap (ZCurve *zc, TCurve *discZC, double price, TDate matDate, double rate, int fixedSwapFreq, int floatSwapFreq, long fixDayCountConv, long floatDayCountConv, long interpType, TInterpData *interpData, TBadDayAndStubPos badDayAndStubPos, char *holidayFile) |
Models the swap points which are to be added to the zero curve using the more detailed swap structures. |
int JpmcdsZCAddCashFlowList | ( | ZCurve * | zc, | |
TCashFlowList * | cfl, | |||
double | price, | |||
TDate | date, | |||
long | interpType, | |||
TInterpData * | interpData | |||
) |
Adds information represented by a list-of-cash-flows to a zero curve.
Any cash flows which are already covered by the zero curve are discounted at rates derived from the zero curve. Cash flows beyond the zero curve imply discount factors, which are added to the zero curve. If there is more than one such cash flow, several points are added to the curve, which are calculated by using an interative root-finding secant method, where the discount factor for the last cash flow is guessed (and the other discount factors are implied by interpolation) where the current price = net present value of all the cash flows.
The zero curve is updated to reflect the cash flows. A point is added for every cash flow, if not already in ZCurve list. For linear forwards, all interpolated points are returned, e.g. for 1 month forwards in an annual market, monthly points will be returned, not just yearly.
Notes: date may be set for non-linear-forward interpolation methods to a date to be added to the zero curve. This allows production of a curve with "nice" dates.
int JpmcdsZCAddCFLPoints | ( | ZCurve * | zc, | |
TCashFlowList * | cfl, | |||
TDate | lastDate, | |||
long | interpType, | |||
TInterpData * | interpData | |||
) |
Adds points into a zero curve to match all points in a cashflow list after a certain date.
Note that only the *dates* in the cashflow list are used.
Zero curve is modified.
Adds points to a zero curve from another zero curve, but only those dates before first date of the other curve.
ZCurve is updated to include the new points.
Note:curve value dates MUST be the same, basis and dayCounts may differ.
zc1 | (M) zCurve to added to | |
zc2 | (I) zCurve to add from |
Adds points to a zero curve from another zero curve, but only those dates after last date of the other curve.
ZCurve is updated to include the new points.
Note: curve value dates MUST be the same, basis and dayCounts may differ.
int JpmcdsZCAddSwap | ( | ZCurve * | zc, | |
TCurve * | discZC, | |||
double | price, | |||
TDate | matDate, | |||
TBoolean | onCycle, | |||
double | rate, | |||
int | fixedSwapFreq, | |||
int | floatSwapFreq, | |||
long | fixDayCountConv, | |||
long | floatDayCountConv, | |||
long | interpType, | |||
TInterpData * | interpData, | |||
TBadDayList * | badDayList, | |||
TBadDayAndStubPos | badDayAndStubPos, | |||
char * | holidayFile | |||
) |
int JpmcdsZCAddSwaps | ( | ZCurve * | zc, | |
TCurve * | discZC, | |||
TDate * | inDates, | |||
double * | inRates, | |||
int | numSwaps, | |||
int | fixedSwapFreq, | |||
int | floatSwapFreq, | |||
long | fixDayCountConv, | |||
long | floatDayCountConv, | |||
long | interpType, | |||
TInterpData * | interpData, | |||
TBadDayList * | badDayList, | |||
TBadDayAndStubPos | badDayAndStubPos, | |||
char * | holidayFile | |||
) |
Adds a strip of swap instruments to a ZCurve.
The zero interpolation kicks in whenever a point is calculated to determine the discount factor for a cash flow, deep inside the objective function called by the root finder, which calls JpmcdsZCInterpolate() to determine the appropriate discount factor.
In this routine, there are two mutually exclusive ways to specify bad days: badDayList, and badDayConv/holidayFile. If badDayList is used, bad business day lists can be used to make sure swap dates near to canonical dates (i.e. integral number of years from start date) are properly used for coupon dates of later instruments. Say the 2-year point has been adjusted because of holidays to be 3 days later. The coupon at 2-years for the 3 (and subsequent) swap instruments must be adjusted to that date. To do this, the badDayList contains a list of <good,bad> day pairs, which are used to adjust dates to/from bad business days.
INPUTS: ZCurve to add swaps to, maturity dates and rates for them, how many there are, coupon frequency: annual or semi-annual, dayCountConvention, interpolation method and data, bad business day list. WARNING: In this routine, there are two mutually exclusive ways to specify bad days: badDayList, and badDayConv/holidayFile. If badDayList is non-NULL, the maturity dates passed in must be adjusted. If the badDayConv is not JPMCDS_BAD_DAY_NONE, the maturity dates passed in must be UN-adjusted.
OUTPUTS: Extended zero curve.
Converts zc-style rate into a discount factor.
Note: As a special optimization, the normal ZCurve case is hard coded for speed (since this routine is critical to performance of building zero-curves). That is, annually-compounded rates w/ 360 or 365-fixed year are calculated directly.
Finds index of entry closest to an input date.
Returns index closest to date.
Finds an exact date in a ZC.
Returns index of matching date if found, -1 if not.
void JpmcdsZCFree | ( | ZCurve * | zc | ) |
Frees memory associated with a zero curve.
zc | zero curve to free |
TCashFlowList* JpmcdsZCGetSwapCFL | ( | TDate | valueDate, | |
TDate | matDate, | |||
TBoolean | stubAtEnd, | |||
double | rate, | |||
TDateInterval * | interval, | |||
long | dayCountConv, | |||
TBadDayList * | badDayList, | |||
long | badDayConv, | |||
char * | holidayFile | |||
) |
Makes a cash flow list for a swap instrument.
returns cash flow list associated with the swap, NULL if an error found.
TDateList* JpmcdsZCGetSwapCouponDL | ( | TDate | valueDate, | |
TDate | matDate, | |||
TBoolean | stubAtEnd, | |||
TDateInterval * | interval, | |||
TBadDayList * | badDayList, | |||
long | badDayConv, | |||
char * | holidayFile | |||
) |
Makes a date list for all coupons associated w/ a swap instrument.
Only glitch is possible inclusion of a stub date, which is necessary if the maturity date isn't an integral number of frequency intervals away, e.g. a swap date 5 years and 1 month from the value date, which would have a stub date 1 month from now, followed by coupons every year from then.
Returns date list associated with the swap's coupons, NULL if error found.
int JpmcdsZCInterpolate | ( | ZCurve * | zc, | |
TDate | date, | |||
long | interpType, | |||
TInterpData * | interpData, | |||
double * | rate | |||
) |
Calculates an interpolated rate for a date.
Note: Piece wise interpolation allows different areas of the zero curve to be interpolated using different methods. Basically an array of <date,interpolationStuff> is given, where the interpolationStuff is used for any date before the given date. The code allows the interpolationStuff to be another pieceWise interpolation type, although the utility of this is unknown.
Constructs a ZCurve.
Constructs a ZCurve, which is basically an array of <rate,date> pairs, where the rates are all zero-coupons with the same compounding and day count convention. This allows a bunch of different types of interest rate instruments to be combined into one yield curve in the same terms.
valueDate | (I) base date for rates | |
n | (I) expected number of rates | |
basis | (I) compounding period | |
dayCountConv | (I) day count convention |