creditDefaultSwapPricer
First introduced in version: 3.00.6
Syntax
creditDefaultSwapPricer(instrument, pricingDate, discountCurve, creditCurve,
[config])
Details
Prices an credit default swap (CDS) and returns its net present value (NPV).
Parameters
instrument is an INSTRUMENT scalar or vector specifying the credit default swap to be priced. See CreditDefaultSwap for details.
pricingDate is a DATE scalar or vector specifying the pricing date.
discountCurve is a MKTDATA scalar or vector specifying the discount curve (IrYieldCurve).
creditCurve is a MKTDATA scalar or vector specifying the credit curve.
config (optional)is a dictionary (<STRING, ANY>) specifying the static data. Supported keys:
| Key | Data Type | Description |
|---|---|---|
| "recoveryRate" | DOUBLE scalar | The recovery rate, defaults to 0.4. |
Returns
A DOUBLE scalar or vector representing the NPV of the CDS.
Examples
Prices a CDS and returns its NPV.
// =====================================================
// I. Construct the CNY FR007 discount zero-coupon yield curve
// =====================================================
def createCnyFr007CurveForCds(asOfDate){
pillarDates = asOfDate + [
2, 8, 93, 185, 276, 367,
732, 1099, 1463, 1828, 2558, 3654
]
pillarValues = [
0.0215993931630537,
0.0229075517972275,
0.0253020667393029,
0.0257564866303201,
0.0259751440992468,
0.0260355181479988,
0.0265336263144786,
0.0272721454114050,
0.0282024453631075,
0.0290231222075799,
0.0304665029488732,
0.0319855013976250
]
discountCurveDict = {
"mktDataType": "Curve",
"curveType": "IrYieldCurve",
"referenceDate": asOfDate,
"currency": "CNY",
"curveName": "CNY_FR_007",
"dayCountConvention": "Actual365",
"compounding": "Continuous",
"interpMethod": "Linear",
"extrapMethod": "Flat",
"frequency": "NoFrequency",
"dates": pillarDates,
"values": pillarValues
}
return parseMktData(discountCurveDict)
}
// =====================================================
// II. Construct the CDS credit curve
// =====================================================
def createCreditCurveForCds(asOfDate){
pillarDates = asOfDate + [
2, 8, 93, 185, 276, 367,
732, 1099, 1463
]
hazardRates = [
0.001577614619366,
0.001587614619366,
0.00217392030740149,
0.00327736067786984,
0.00687303437629905,
0.0141416564486811,
0.0219406380083359,
0.0292999285840119,
0.0342083758016553
]
creditCurveDict = {
"mktDataType": "Curve",
"curveType": "CreditCurve",
"referenceDate": asOfDate,
"currency": "CNY",
"curveName": "CFETS_SHCH_GTJA",
"interpMethod": "Linear",
"extrapMethod": "Flat",
"dayCountConvention": "Actual365",
"dates": pillarDates,
"values": hazardRates
}
return parseMktData(creditCurveDict)
}
// =====================================================
// III. Set the pricing date
// =====================================================
pricingDate = 2020.09.07
// =====================================================
// IV. Construct the CDS instrument
// =====================================================
instrumentDict = {
"productType": "Swap",
"swapType": "CreditDefaultSwap",
"instrumentId": "CFETS_SHCH_GTJA",
"notionalAmount": 1.0e7,
"notionalCurrency": "CNY",
"start": 2019.06.20,
"maturity": 2024.06.20,
"payReceive": "Pay",
"protectionLegRefPrice": 0.0,
"protectionLegLeverage": 1.0,
"protectionLegRecoveryRate": 0.4,
"creditProtectionType": "PayProtectionAtMaturity",
"creditPremiumType": "PayPremiumUptoCurrentPeriod",
"premiumRate": 0.01,
"dayCountConvention": "Actual360",
"frequency": "Quarterly",
"businessDayConvention": "ModifiedFollowing",
"calendar": "CFET",
"upfrontRate": 0.01,
"rebateAccrual": false
}
instrument = parseInstrument(instrumentDict)
// =====================================================
// V. Generate the discount curve and credit curve
// =====================================================
discountCurve = createCnyFr007CurveForCds(pricingDate)
creditCurve = createCreditCurveForCds(pricingDate)
// =====================================================
// VI. Set CDS pricing parameters
// =====================================================
config = {
"recoveryRate": 0.4
}
// =====================================================
// VII. Call the CDS pricer
// =====================================================
npv = creditDefaultSwapPricer(
instrument,
pricingDate,
discountCurve,
creditCurve,
config=config
)
// =====================================================
// VIII. Output the CDS pricing result
// =====================================================
print("CreditDefaultSwap NPV = " + string(npv))
CreditDefaultSwap
| Field Name | Data Type | Description | Required |
|---|---|---|---|
| productType | STRING | Must be "Swap". | Yes |
| swapType | STRING | Must be "CreditDefaultSwap". | Yes |
| notionalAmount | DOUBLE | Notional principal amount | Yes |
| notionalCurrency | STRING | Notional principal, defaults to "CNY" | No |
| instrumentId | STRING | Instrument ID | No |
| start | DATE | Effective date | Yes |
| maturity | DATE | Maturity date | Yes |
| payReceive | STRING | Pay/Receive indicator: "Pay" indicates paying; "Receive" indicates receiving. | Yes |
| frequency | STRING | Frequency of interest payment, defaults to "Quarterly" | No |
| protectionLegRefPrice | DOUBLE | Protection leg reference price | Yes |
| protectionLegLeverage | DOUBLE | Protection leg leverage ratio | Yes |
| protectionLegRecoveryRate | DOUBLE | Protection leg recovery rate | Yes |
| creditProtectionType | STRING |
Credit protection type. It can be:
|
Yes |
| creditPremiumType | STRING |
Credit premium type. It can be:
|
Yes |
| premiumRate | DOUBLE | Premium rate | Yes |
| calendar | STRING | Trading calendar | Yes |
| dayCountConvention | STRING | The day count convention. It can be: "ActualActualISDA", "ActualActualISMA"," Actual365", "Actual360" | Yes |
| businessDayConvention | STRING |
The business day convention. It can be:
|
|
| upfrontRate | DOUBLE | Upfront rate | Yes |
| rebateAccrual | BOOL | Whether to calculate rebate accruals | Yes |
CreditCurve
| Field Name | Type | Description | Required |
|---|---|---|---|
| mktDataType | STRING | Must be "Curve" | √ |
| referenceDate | DATE | Reference Date | √ |
| curveType | STRING | Must be "CreditCurve" | √ |
| curveName | STRING | Curve name | × |
| dayCountConvention | STRING |
The day count convention to use. It can be:
|
√ |
| interpMethod | STRING |
Interpolation method. It can be:
|
√ |
| extrapMethod | STRING |
Extrapolation method. It can be
|
√ |
| dates | DATE vector | Date of each data point | √ |
| values | DOUBLE vector | Hazard rates. Value of each data point, corresponding to the elements in dates | √ |
Releated links: creditCurveBuilder, parseInstrument, parseMktData
