zcprvt.h File Reference

#include "cgeneral.h"
#include "bastypes.h"
#include "badday.h"
#include "tcurve.h"
#include "interp.h"

Data Structures

struct  ZCurve
struct  TStubData
struct  TInterpData

Functions

TCurveJpmcdsZCToTCurve (ZCurve *zc)
 Constructs a TCurve from a ZCurve.
ZCurveJpmcdsZCFromTCurve (TCurve *tc)
 Constructs a ZCurve from a TCurve.
ZCurveJpmcdsZCMake (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.
TDateListJpmcdsZCGetSwapCouponDL (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.
TCashFlowListJpmcdsZCGetSwapCFL (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.

Detailed Description


Function Documentation

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.

int JpmcdsZCAddDiscountFactor ( ZCurve zc,
TDate  date,
double  disc 
)

Adds a discount factor (at a specified date) to a ZCurve.

Modified ZCurve, and error indicator.

int JpmcdsZCAddGenRate ( ZCurve zc,
TDate  date,
double  rate,
long  basis,
long  dayCountConv 
)

Adds a general zero rate to a ZCurve.

ZCurve is updated to include the rate.

int JpmcdsZCAddMoneyMarket ( ZCurve zc,
TDate  dates[],
double  rates[],
int  n,
long  dayCountConv 
)

Adds simple-interest money market bond to ZCurve.

ZCurve is updated to include information from money market instruments

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.

ZCurve is updated to include the new points.

Note:curve value dates MUST be the same, basis and dayCounts may differ.

Parameters:
zc1 (M) zCurve to added to
zc2 (I) zCurve to add from

int JpmcdsZCAddRate ( ZCurve zc,
TDate  date,
double  rate 
)

Adds a zero rate to a ZCurve.

The input rate must be in the proper ZCurve terms (zc->basis and zc->dayCountConv).

ZCurve is updated to include the rate.

int JpmcdsZCAddRateAndDiscount ( ZCurve zc,
TDate  date,
double  rate,
double  disc 
)

Adds a zero rate and discount to a ZCurv.

The input rate must be in the proper ZCurve terms (zc->basis and zc->dayCountConv).

ZCurve is updated to include the rate.

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.

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 
)

Adds a single swap instrument to a ZCurve.

ZCurve is updated to contain swap information (with points at each of the coupon dates, as well as the maturity date).

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.

int JpmcdsZCComputeDiscount ( ZCurve zc,
TDate  date,
double  rate,
double *  discount 
)

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.

int JpmcdsZCFindDateClosest ( ZCurve zc,
TDate  date 
)

Finds index of entry closest to an input date.

Returns index closest to date.

int JpmcdsZCFindDateExact ( ZCurve zc,
TDate  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.

Parameters:
zc zero curve to free

ZCurve* JpmcdsZCFromTCurve ( TCurve tc  ) 

Constructs a ZCurve from a TCurve.

Parameters:
tc (I) TCurve to copy

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.

ZCurve* JpmcdsZCMake ( TDate  valueDate,
int  n,
long  basis,
long  dayCountConv 
)

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.

Parameters:
valueDate (I) base date for rates
n (I) expected number of rates
basis (I) compounding period
dayCountConv (I) day count convention

TCurve* JpmcdsZCToTCurve ( ZCurve zc  ) 

Constructs a TCurve from a ZCurve.

Parameters:
zc (I) ZCurve to copy


Distributed by BN Algorithms Ltd -- consulting in quantitative finance, mathematical algorithms and software implementations. CDS Home Page. For enquires contact webs@bnikolic.co.uk.
This documentation is derived from ISDA CDS Standard Model version 1.7. You can get a copy of the original ISDA code at www.bnikolic.co.uk. This is a derivative work under the terms of the ISDA CDS Standard Model Public License. BN Algorithms Ltd licenses this work to you solely for on-screen viewing on your own computer. Making copies and further distribution of this work is prohibited.
This documentation is provided "as-is", without warranty of any kind, either expressed or implied, including, without limitation, warranties that the documentation is free of defects, merchantable, fit for a particular purpose or non-infringing. the entire risk as to the quality of the documentation is with you. Should this documentation prove defective in any respect, you (not the licensor) assume the cost of any necessary correction. This disclaimer of warranty constitutes an essential part of this license.