Comments (5)
@kristofferpagels @amaggiulli Let me check this against upstream first, please.
from qlnet.
@kristofferpagels Help me out, please. What are the actual 3 values you get for the last 3 failing tests?
from qlnet.
The actual and expected values for the three failing test cases can be seen here
TestCase | Expected YearFraction | Actual YearFraction |
---|---|---|
example d: short final calculation period | 152.0 / (182.0 * 2) = 0.41758 | 0.5 |
example e: long final calculation period - eom | (91.0 / (91.0 * 4)) + (61.0 / (92.0 * 4)) = 0.41576 | 0.5 |
example e: long final calculation period - not eom | (91.0 / (91.0 * 4)) + (61.0 / (90.0 * 4)) = 0.41944 | 0.5 |
from qlnet.
I get the same calculated values of 0.5
in upstream QuantLib. My suggestion would be to resolve this issue in QuantLib first and then we'll port it to QLNet. I think it would be quite dangerous to have a discrepancy in the day counters of the 2 projects. @amaggiulli, however, this is your decision to make.
I have prepared a C++ test case though.
void DayCounterTest::testActualActualSchedule()
{
BOOST_TEST_MESSAGE("Testing actual actual ISMA with odd first and last periods ...");
bool isEndOfMonth(false);
Frequency frequency(Semiannual);
Date interestAccrualDate(30, Jan, 1999);
Date maturityDate(30, Jun, 2000);
Date firstCouponDate(30, Jul, 1999);
Date penultimateCouponDate(30, Jan, 2000);
Date d1(30, Jan, 2000);
Date d2(30, Jun, 2000);
double expected(152. / (182. * 2));
Schedule schedule = MakeSchedule()
.from(interestAccrualDate)
.to(maturityDate)
.withFrequency(frequency)
.withFirstDate(firstCouponDate)
.withNextToLastDate(penultimateCouponDate)
.endOfMonth(isEndOfMonth);
DayCounter dayCounter = ActualActual(ActualActual::ISMA, schedule);
double calculated(dayCounter.yearFraction(d1, d2));
if (std::fabs(calculated - expected) > 1.0e-10) {
std::ostringstream period;
period << "period: " << d1 << " to " << d2;
BOOST_ERROR(dayCounter.name() << ":\n"
<< period.str() << "\n"
<< std::setprecision(10)
<< " calculated: " << calculated << "\n"
<< " expected: " << expected);
}
//////////////////////////////////
isEndOfMonth = true;
frequency = Quarterly;
interestAccrualDate = Date(31, May, 1999);
maturityDate = Date(30, Apr, 2000);
firstCouponDate = Date(31, Aug, 1999);
penultimateCouponDate = Date(30, Nov, 1999);
d1 = Date(30, Nov, 1999);
d2 = Date(30, Apr, 2000);
expected = 91.0 / (91.0 * 4) + 61.0 / (92.0 * 4);
schedule = MakeSchedule()
.from(interestAccrualDate)
.to(maturityDate)
.withFrequency(frequency)
.withFirstDate(firstCouponDate)
.withNextToLastDate(penultimateCouponDate)
.endOfMonth(isEndOfMonth);
dayCounter = ActualActual(ActualActual::ISMA, schedule);
calculated = dayCounter.yearFraction(d1, d2);
if (std::fabs(calculated - expected) > 1.0e-10) {
std::ostringstream period;
period << "period: " << d1 << " to " << d2;
BOOST_ERROR(dayCounter.name() << ":\n"
<< period.str() << "\n"
<< std::setprecision(10)
<< " calculated: " << calculated << "\n"
<< " expected: " << expected);
}
//////////////////////////////////
isEndOfMonth = false;
frequency = Quarterly;
interestAccrualDate = Date(31, May, 1999);
maturityDate = Date(30, Apr, 2000);
firstCouponDate = Date(31, Aug, 1999);
penultimateCouponDate = Date(30, Nov, 1999);
d1 = Date(30, Nov, 1999);
d2 = Date(30, Apr, 2000);
expected = 91.0 / (91.0 * 4) + 61.0 / (90.0 * 4);
schedule = MakeSchedule()
.from(interestAccrualDate)
.to(maturityDate)
.withFrequency(frequency)
.withFirstDate(firstCouponDate)
.withNextToLastDate(penultimateCouponDate)
.endOfMonth(isEndOfMonth);
dayCounter = ActualActual(ActualActual::ISMA, schedule);
calculated = dayCounter.yearFraction(d1, d2);
if (std::fabs(calculated - expected) > 1.0e-10) {
std::ostringstream period;
period << "period: " << d1 << " to " << d2;
BOOST_ERROR(dayCounter.name() << ":\n"
<< period.str() << "\n"
<< std::setprecision(10)
<< " calculated: " << calculated << "\n"
<< " expected: " << expected);
}
}
from qlnet.
Thanks @kristofferpagels for contribution, I'm going to fix the issue using the solution provided. @igitur our bug fixing is absolutely not dependent on Quantlib bug fixing , is a good practice tough to report back any issue we could find in code.
from qlnet.
Related Issues (20)
- [REFACTO] Generalized Leg
- [BUG] GetHashCode of Date class - absent implementation HOT 1
- [BUG] Optimization method based on line search may return function value that does not correspond to current value HOT 2
- [FEATURE] Cleanup Project solution HOT 5
- [BUG] Missing bank holidays in calendar for Denmark
- Question: is it possible to use QLNet for generic MC pricing? HOT 2
- Thread aware calculation of LazyObject HOT 5
- [BUG] False exception cause bootstrap failed because ts_.instruments_.Sort() does not work in Class:Iterativebootstrap, Method:initialize() HOT 1
- Use dotnet format instead of astyle HOT 1
- Question: Discrepancy between holidays in QLNet and QuantLib 1.21
- Net standard over net 6.0 HOT 10
- Fix .NET 7 compilation warnings
- [BUG] HOT 2
- Update Callable bonds with tests
- Add Bond Equivalent Yield calculation
- Add Compounded Then Simple calculation
- Determine early close date for US bond market calendar
- Update to .NET 8 HOT 3
- Update and refactor Asian engines
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qlnet.