Skip to content

Commit

Permalink
Simplified testDurations
Browse files Browse the repository at this point in the history
  • Loading branch information
amaggiulli committed Aug 3, 2018
1 parent 2503f49 commit c74a5ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion format_code.bat
@@ -1 +1,2 @@
tools\AStyle.exe --options=qlnet.astyle --recursive src/*.cs tests/*.cs
tools\AStyle.exe --options=qlnet.astyle --recursive src/*.cs tests/*.cs
pause
2 changes: 1 addition & 1 deletion tests/QLNet.Tests/T_AmericanOption.cs
Expand Up @@ -650,7 +650,7 @@ public void testFDDividendAmericanEngine()
Strike: 2800
Volatility: 20 %
Interest rate: 0 %
Dividend(paid one day before expiry)
Date: 16 Aug 2018
Value: 40
Expand Down
16 changes: 7 additions & 9 deletions tests/QLNet.Tests/T_Bonds.cs
Expand Up @@ -1811,8 +1811,6 @@ public void testThirty360BondWithSettlementOn31st()

// Divide number by 100
Coupon = Coupon / 100;
//ExpectedModifiedDuration = ExpectedModifiedDuration / 100;


Calendar calendar = new TARGET();

Expand All @@ -1824,21 +1822,21 @@ public void testThirty360BondWithSettlementOn31st()
Compounding comp = Compounding.Compounded;
Frequency freq = Frequency.Semiannual;
DayCounter dc = new Thirty360(Thirty360.Thirty360Convention.USA);
Schedule sch = new Schedule(null, maturityDate, tenor,
new NullCalendar(), BusinessDayConvention.Unadjusted,
BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);

FixedRateBond bond = new FixedRateBond(settlementDays, 100.0,
new Schedule(null, maturityDate, tenor, new NullCalendar(), BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward,
false), new InitializedList<double>(1, Coupon), dc, BusinessDayConvention.Unadjusted, 100.0, null, calendar, exCouponPeriod, calendar);

List<CashFlow> leg = bond.cashflows();
FixedRateBond bond = new FixedRateBond(settlementDays, 100.0, sch,
new InitializedList<double>(1, Coupon), dc, BusinessDayConvention.Unadjusted,
100.0, null, calendar, exCouponPeriod, calendar);

double yield = bond.yield(Price, dc, comp, freq, settlementDate);
double duration = CashFlows.duration(leg, yield, dc, comp, freq, Duration.Type.Modified, false, settlementDate);
double duration = BondFunctions.duration(bond, yield, dc, comp, freq, Duration.Type.Modified, settlementDate);

if (Math.Abs(duration - ExpectedModifiedDuration) > 1e-3)
QAssert.Fail("Failed to reproduce modified duration for cusip " + Cusip + " at " + SettlementDate
+ "\n calculated: " + duration
+ "\n expected: " + ExpectedModifiedDuration);
}
}

}

0 comments on commit c74a5ab

Please sign in to comment.