本文整理汇总了C#中CommonVars.makeFixedLeg方法的典型用法代码示例。如果您正苦于以下问题:C# CommonVars.makeFixedLeg方法的具体用法?C# CommonVars.makeFixedLeg怎么用?C# CommonVars.makeFixedLeg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonVars
的用法示例。
在下文中一共展示了CommonVars.makeFixedLeg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testDecomposition
public void testDecomposition()
{
// Testing collared coupon against its decomposition...
CommonVars vars= new CommonVars();
double tolerance = 1e-10;
double npvVanilla,npvCappedLeg,npvFlooredLeg,npvCollaredLeg,npvCap,npvFloor,npvCollar;
double error;
double floorstrike = 0.05;
double capstrike = 0.10;
InitializedList<double> caps = new InitializedList<double>(vars.length,capstrike);
List<double> caps0 = new List<double>();
InitializedList<double> floors = new InitializedList<double>(vars.length,floorstrike);
List<double> floors0 = new List<double>();
double gearing_p = 0.5;
double spread_p = 0.002;
double gearing_n = -1.5;
double spread_n = 0.12;
// fixed leg with zero rate
List<CashFlow> fixedLeg = vars.makeFixedLeg(vars.startDate,vars.length);
// floating leg with gearing=1 and spread=0
List<CashFlow> floatLeg = vars.makeYoYLeg(vars.startDate,vars.length);
// floating leg with positive gearing (gearing_p) and spread<>0
List<CashFlow> floatLeg_p = vars.makeYoYLeg(vars.startDate,vars.length,gearing_p,spread_p);
// floating leg with negative gearing (gearing_n) and spread<>0
List<CashFlow> floatLeg_n = vars.makeYoYLeg(vars.startDate,vars.length,gearing_n,spread_n);
// Swap with null fixed leg and floating leg with gearing=1 and spread=0
Swap vanillaLeg = new Swap(fixedLeg,floatLeg);
// Swap with null fixed leg and floating leg with positive gearing and spread<>0
Swap vanillaLeg_p = new Swap(fixedLeg,floatLeg_p);
// Swap with null fixed leg and floating leg with negative gearing and spread<>0
Swap vanillaLeg_n = new Swap(fixedLeg,floatLeg_n);
IPricingEngine engine = new DiscountingSwapEngine(vars.nominalTS);
vanillaLeg.setPricingEngine(engine); // here use the autoset feature
vanillaLeg_p.setPricingEngine(engine);
vanillaLeg_n.setPricingEngine(engine);
// CAPPED coupon - Decomposition of payoff
// Payoff = Nom * Min(rate,strike) * accrualperiod =
// = Nom * [rate + Min(0,strike-rate)] * accrualperiod =
// = Nom * rate * accrualperiod - Nom * Max(rate-strike,0) * accrualperiod =
// = VanillaFloatingLeg - Call
//
int whichPricer = 0;
// Case gearing = 1 and spread = 0
List<CashFlow> cappedLeg = vars.makeYoYCapFlooredLeg(whichPricer,vars.startDate,vars.length,
caps,floors0,vars.volatility);
Swap capLeg = new Swap(fixedLeg,cappedLeg);
capLeg.setPricingEngine(engine);
YoYInflationCap cap = new YoYInflationCap(floatLeg, new List<double>(){capstrike});
cap.setPricingEngine(vars.makeEngine(vars.volatility,whichPricer));
npvVanilla = vanillaLeg.NPV();
npvCappedLeg = capLeg.NPV();
npvCap = cap.NPV();
error = Math.Abs(npvCappedLeg - (npvVanilla-npvCap));
if (error>tolerance)
{
Assert.Fail("\nYoY Capped Leg: gearing=1, spread=0%, strike=" + capstrike*100 +
"%\n" +
" Capped Floating Leg NPV: " + npvCappedLeg + "\n" +
" Floating Leg NPV - Cap NPV: " + (npvVanilla - npvCap) + "\n" +
" Diff: " + error );
}
// gearing = 1 and spread = 0
// FLOORED coupon - Decomposition of payoff
// Payoff = Nom * Max(rate,strike) * accrualperiod =
// = Nom * [rate + Max(0,strike-rate)] * accrualperiod =
// = Nom * rate * accrualperiod + Nom * Max(strike-rate,0) * accrualperiod =
// = VanillaFloatingLeg + Put
//
List<CashFlow> flooredLeg = vars.makeYoYCapFlooredLeg(whichPricer,vars.startDate,vars.length,
caps0,floors,vars.volatility);
Swap floorLeg = new Swap(fixedLeg,flooredLeg);
floorLeg.setPricingEngine(engine);
YoYInflationFloor floor= new YoYInflationFloor(floatLeg, new List<double>(){floorstrike});
floor.setPricingEngine(vars.makeEngine(vars.volatility,whichPricer));
npvFlooredLeg = floorLeg.NPV();
npvFloor = floor.NPV();
error = Math.Abs(npvFlooredLeg-(npvVanilla + npvFloor));
if (error>tolerance)
{
Assert.Fail("YoY Floored Leg: gearing=1, spread=0%, strike=" + floorstrike *100 +
"%\n" +
" Floored Floating Leg NPV: " + npvFlooredLeg + "\n" +
" Floating Leg NPV + Floor NPV: " + (npvVanilla + npvFloor) + "\n" +
" Diff: " + error );
}
// gearing = 1 and spread = 0
// COLLARED coupon - Decomposition of payoff
// Payoff = Nom * Min(strikem,Max(rate,strikeM)) * accrualperiod =
// = VanillaFloatingLeg - Collar
//
//.........这里部分代码省略.........