Skip to content

Commit

Permalink
Fix Vanilla Swap Pricer - thanks OfirMarom
Browse files Browse the repository at this point in the history
  • Loading branch information
amaggiulli committed Aug 21, 2015
1 parent 9473da7 commit dcfe0fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions QLNet/Cashflows/Cashflowvectors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ public static List<CashFlow> FloatingLeg<InterestRateIndexType, FloatingCouponTy
} else {
if (Utils.noOption(caps, floors, i)) {
leg.Add(new FloatingCouponType().factory(Utils.Get(nominals, i),
paymentDate, start, end,
Utils.Get(fixingDays, i, 2),
paymentDate, start, end,
Utils.Get( fixingDays, i, index.fixingDays() ),
index,
Utils.Get(gearings, i, 1),
Utils.Get(spreads, i),
refStart, refEnd, paymentDayCounter,
isInArrears));
} else {
leg.Add(new CappedFlooredCouponType().factory(Utils.Get(nominals, i),
paymentDate, start, end,
Utils.Get(fixingDays, i, 2),
paymentDate, start, end,
Utils.Get( fixingDays, i, index.fixingDays() ),
index,
Utils.Get(gearings, i, 1),
Utils.Get(spreads, i),
Expand Down
50 changes: 50 additions & 0 deletions Test/T_Swaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,56 @@ public void testCachedValue()
+ " expected: " + cachedNPV);
}

[TestMethod()]
public void testFixing()
{
Date tradeDate = new Date( 17, Month.April, 2015 );
Calendar calendar = new UnitedKingdom();
Date settlementDate = calendar.advance( tradeDate, 2, TimeUnit.Days, BusinessDayConvention.Following );
Date maturityDate = calendar.advance( settlementDate, 5, TimeUnit.Years, BusinessDayConvention.Following );

Date valueDate = new Date( 20, Month.April, 2015 );
Settings.setEvaluationDate( valueDate );

List<Date> dates = new List<Date>();
dates.Add( valueDate );
dates.Add( valueDate + new Period( 1, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 2, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 5, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 10, TimeUnit.Years ) );
dates.Add( valueDate + new Period( 20, TimeUnit.Years ) );

List<double> rates = new List<double>();
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );
rates.Add( 0.01 );

var discountCurveHandle = new RelinkableHandle<YieldTermStructure>();
var forecastCurveHandle = new RelinkableHandle<YieldTermStructure>();
GBPLibor index = new GBPLibor( new Period( 6, TimeUnit.Months ), forecastCurveHandle );
InterpolatedZeroCurve<Linear> zeroCurve = new InterpolatedZeroCurve<Linear>( dates, rates, new Actual360(), new Linear() );
var fixedSchedule = new Schedule( settlementDate, maturityDate, new Period( 1, TimeUnit.Years ), calendar, BusinessDayConvention.Following, BusinessDayConvention.Following, DateGeneration.Rule.Forward, false );
var floatSchedule = new Schedule( settlementDate, maturityDate, index.tenor(), calendar, BusinessDayConvention.Following, BusinessDayConvention.Following, DateGeneration.Rule.Forward, false );
VanillaSwap swap = new VanillaSwap( VanillaSwap.Type.Payer, 1000000, fixedSchedule, 0.01, new Actual360(), floatSchedule, index, 0, new Actual360() );
discountCurveHandle.linkTo( zeroCurve );
forecastCurveHandle.linkTo( zeroCurve );
var swapEngine = new DiscountingSwapEngine( discountCurveHandle, false, null );
swap.setPricingEngine( swapEngine );

try
{
double npv = swap.NPV();
}
catch ( Exception ex )
{
Assert.Fail( ex.Message );
Console.WriteLine( ex );
}
}

public void suite()
{
testFairRate();
Expand Down

0 comments on commit dcfe0fa

Please sign in to comment.