合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 中国 Repo 7D 互换的例子 > 来源:https://uqer.io/community/share/55c177cbf9f06c915418c641 下面的例子给出在量化实验室中如何为一个Repo 7D互换定价的例子 + `swapType`:互换类型,`Payer`代表付固定端利息,收浮动端利息; + `nominal`:互换面值 + `startDate`:互换生效日 + `swapTenor`:互换期限 + `paymentTenor`:付息周期 + `fixedRate`:固定端利息 + `rateSpread`:浮动端息差 + `repoIndex`:浮动端指数 这里我们使用一条平坦的收益率曲线作为远期曲线: ```py forwardingCurve = FlatForward(Date(2015, 8, 4), 0.05, 'Actual/360') ``` ```py from CAL.PyCAL import * SetEvaluationDate = Date(2015, 8, 4) swapType = SwapLegType.Payer nominal = 100000000. startDate = Date(2015, 8, 7) swapTenor = Period('10Y') paymentTenor = Period('3M') fixedRate = 0.055 rateSpread = 0.0 forwardingCurve = FlatForward(Date(2015, 8, 4), 0.05, 'Actual/360') repoIndex = RepoChina('7D', yieldCurve) ``` 组装成我们需要的`RepoCompoundingSwap`: ```py swap = RepoCompoundingSwap(swapType=swapType, nominal=nominal, startDate=startDate, swapTenor=swapTenor, paymentTenor=paymentTenor, fixedRate=fixedRate, rateSpread=rateSpread, repoIndex=repoIndex) ``` 继续的,为了计算`swap`的现值,我们需要定义`DiscountingSwapEngine`对象,这里我们同样使用一条平坦的收益率曲线: ```py discountingCurve = FlatForward(Date(2015, 8, 4), 0.065, 'Actual/360') pricingEngine = DiscountingSwapEngine(discountingCurve) swap.setPricingEngine(pricingEngine) print("NPV: {0:.4f}".format(swap.NPV())) print("Fair rate: {0:.4f}".format(swap.fairRate())) NPV: -2282521.8872 Fair rate: 0.0519 ``` 下面的是`swap`每条`leg`的具体现金流分析:在`legAnalysis`接受的参数中,0代表固定端,1代表浮动端。 ```py swap.legAnalysis(0).tail() ``` | | AMOUNT | NOMINAL | ACCRUAL_START_DATE | ACCRUAL_END_DATE | ACCRUAL_DAYS | INDEX | FIXING_DAYS | FIXING_DATES | INDEX_FIXING | DAY_COUNTER | ACCRUAL_PERIOD | EFFECTIVE_RATE | | --- | --- | | PAYMENT_DATE | | | | | | | | | | | | | | 2024-08-07 | 1386301 | 1e+08 | 2024-05-07 | 2024-08-07 | 92 | #NA | #NA | #NA | #NA | Actual/365 (Fixed) | 0.2520548 | 0.055 | | 2024-11-07 | 1386301 | 1e+08 | 2024-08-07 | 2024-11-07 | 92 | #NA | #NA | #NA | #NA | Actual/365 (Fixed) | 0.2520548 | 0.055 | | 2025-02-07 | 1386301 | 1e+08 | 2024-11-07 | 2025-02-07 | 92 | #NA | #NA | #NA | #NA | Actual/365 (Fixed) | 0.2520548 | 0.055 | | 2025-05-07 | 1341096 | 1e+08 | 2025-02-07 | 2025-05-07 | 89 | #NA | #NA | #NA | #NA | Actual/365 (Fixed) | 0.2438356 | 0.055 | | 2025-08-07 | 1386301 | 1e+08 | 2025-05-07 | 2025-08-07 | 92 | #NA | #NA | #NA | #NA | Actual/365 (Fixed) | 0.2520548 | 0.055 | ```py swap.legAnalysis(1).tail() ``` | | AMOUNT | NOMINAL | ACCRUAL_START_DATE | ACCRUAL_END_DATE | ACCRUAL_DAYS | INDEX | FIXING_DAYS | FIXING_DATES | INDEX_FIXING | DAY_COUNTER | ACCRUAL_PERIOD | EFFECTIVE_RATE | | --- | --- | | PAYMENT_DATE | | | | | | | | | | | | | | 2024-08-07 | 1306927 | 1e+08 | 2024-05-07 | 2024-08-07 | 92 | repoChina1W Actual/365 (Fixed) | 1 | 2024-05-06 | 0.05072614 | Actual/360 | 0.2555556 | 0.05114062 | | 2024-11-07 | 1306927 | 1e+08 | 2024-08-07 | 2024-11-07 | 92 | repoChina1W Actual/365 (Fixed) | 1 | 2024-08-06 | 0.05072614 | Actual/360 | 0.2555556 | 0.05114062 | | 2025-02-07 | 1309570 | 1e+08 | 2024-11-07 | 2025-02-07 | 92 | repoChina1W Actual/365 (Fixed) | 1 | 2024-11-06 | 0.05073319 | Actual/360 | 0.2555556 | 0.05124405 | | 2025-05-07 | 1265808 | 1e+08 | 2025-02-07 | 2025-05-07 | 89 | repoChina1W Actual/365 (Fixed) | 1 | 2025-02-06 | 0.05073319 | Actual/360 | 0.2472222 | 0.05120122 | | 2025-08-07 | 1306927 | 1e+08 | 2025-05-07 | 2025-08-07 | 92 | repoChina1W Actual/365 (Fixed) | 1 | 2025-05-06 | 0.05072614 | Actual/360 | 0.2555556 | 0.05114062 |