|
| 1 | +/* |
| 2 | + Copyright (C) 2025 Quaternion Risk Management Ltd |
| 3 | + All rights reserved. |
| 4 | +
|
| 5 | + This file is part of ORE, a free-software/open-source library |
| 6 | + for transparent pricing and risk analysis - http://opensourcerisk.org |
| 7 | +
|
| 8 | + ORE is free software: you can redistribute it and/or modify it |
| 9 | + under the terms of the Modified BSD License. You should have received a |
| 10 | + copy of the license along with this program. |
| 11 | + The license is also available online at <http://opensourcerisk.org> |
| 12 | +
|
| 13 | + This program is distributed on the basis that it will form a useful |
| 14 | + contribution to risk analytics and model standardisation, but WITHOUT |
| 15 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | + FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. |
| 17 | +*/ |
| 18 | + |
| 19 | +/*! \file monthcounter.hpp |
| 20 | + \brief day counter that returns the nearest integer month fraction |
| 21 | +*/ |
| 22 | + |
| 23 | +#ifndef quantext_month_counter_hpp |
| 24 | +#define quantext_month_counter_hpp |
| 25 | +#include <ql/time/daycounter.hpp> |
| 26 | + |
| 27 | +namespace QuantExt { |
| 28 | + |
| 29 | +//! Month counter for when we want a whole number month fraction. |
| 30 | +/*! This day counter computers the number of months between two dates as an integer, |
| 31 | + and divides by 12 to get the year fraction. |
| 32 | +
|
| 33 | + \ingroup daycounters |
| 34 | +*/ |
| 35 | +class MonthCounter : public QuantLib::DayCounter { |
| 36 | +public: |
| 37 | + MonthCounter() : QuantLib::DayCounter(QuantLib::ext::shared_ptr<DayCounter::Impl>(new MonthCounter::Impl())) {} |
| 38 | +private: |
| 39 | + class Impl : public DayCounter::Impl { |
| 40 | + public: |
| 41 | + std::string name() const override { return "Month"; } |
| 42 | + //! number of months between d1 and d2 divided by 12 |
| 43 | + QuantLib::Time yearFraction(const QuantLib::Date& d1, const QuantLib::Date& d2, const QuantLib::Date&, |
| 44 | + const QuantLib::Date&) const override; |
| 45 | + }; |
| 46 | +}; |
| 47 | + |
| 48 | +} // namespace QuantExt |
| 49 | + |
| 50 | +#endif |
0 commit comments