Coder Social home page Coder Social logo

Comments (5)

igitur avatar igitur commented on August 16, 2024

@kristofferpagels @amaggiulli Let me check this against upstream first, please.

from qlnet.

igitur avatar igitur commented on August 16, 2024

@kristofferpagels Help me out, please. What are the actual 3 values you get for the last 3 failing tests?

from qlnet.

kristofferpagels avatar kristofferpagels commented on August 16, 2024

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.

igitur avatar igitur commented on August 16, 2024

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.

amaggiulli avatar amaggiulli commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.