Skip to content

Commit ef51168

Browse files
committed
Merge branch 'feature/QPR-13728' into 'master'
Resolve QPR-13728 Add month counter for inflation Closes QPR-13728 See merge request qs/oreplus!3111
2 parents 00b29ab + 2fbb40d commit ef51168

6 files changed

Lines changed: 93 additions & 1 deletion

File tree

OREData/ored/utilities/parsers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <qle/instruments/cashflowresults.hpp>
3232
#include <qle/time/yearcounter.hpp>
33+
#include <qle/time/monthcounter.hpp>
3334

3435
#include <ql/errors.hpp>
3536
#include <ql/indexes/all.hpp>
@@ -283,7 +284,8 @@ DayCounter parseDayCounter(const string& s) {
283284
{"A364", QuantLib::Actual364()},
284285
{"Actual/364", Actual364()},
285286
{"Act/364", Actual364()},
286-
{"ACT/364", Actual364()}};
287+
{"ACT/364", Actual364()},
288+
{"Month", MonthCounter()}};
287289

288290
auto it = m.find(s);
289291
if (it != m.end()) {

QuantExt/qle/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ termstructures/yoyoptionletsolver.cpp
436436
termstructures/yoyoptionletsurfacestripper.cpp
437437
termstructures/yoypricesurfacefromvols.cpp
438438
time/dateutilities.cpp
439+
time/monthcounter.cpp
439440
time/yearcounter.cpp
440441
utilities/barrier.cpp
441442
utilities/cashflows.cpp
@@ -1066,6 +1067,7 @@ termstructures/zeroinflationcurveobservermoving.hpp
10661067
termstructures/zeroinflationcurveobserverstatic.hpp
10671068
time/dateutilities.hpp
10681069
time/futureexpirycalculator.hpp
1070+
time/monthcounter.hpp
10691071
time/yearcounter.hpp
10701072
utilities/barrier.hpp
10711073
utilities/cashflows.hpp

QuantExt/qle/quantext.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@
622622
#include <qle/termstructures/zeroinflationcurveobserverstatic.hpp>
623623
#include <qle/time/dateutilities.hpp>
624624
#include <qle/time/futureexpirycalculator.hpp>
625+
#include <qle/time/monthcounter.hpp>
625626
#include <qle/time/yearcounter.hpp>
626627
#include <qle/utilities/barrier.hpp>
627628
#include <qle/utilities/cashflows.hpp>

QuantExt/qle/time/monthcounter.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/*
4+
Copyright (C) 2025 Quaternion Risk Management Ltd
5+
All rights reserved.
6+
7+
This file is part of ORE, a free-software/open-source library
8+
for transparent pricing and risk analysis - http://opensourcerisk.org
9+
10+
ORE is free software: you can redistribute it and/or modify it
11+
under the terms of the Modified BSD License. You should have received a
12+
copy of the license along with this program.
13+
The license is also available online at <http://opensourcerisk.org>
14+
15+
This program is distributed on the basis that it will form a useful
16+
contribution to risk analytics and model standardisation, but WITHOUT
17+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
19+
*/
20+
21+
#include <qle/time/monthcounter.hpp>
22+
23+
using QuantLib::Date;
24+
using QuantLib::Time;
25+
26+
namespace QuantExt {
27+
28+
Time MonthCounter::Impl::yearFraction(const Date& d1, const Date& d2, const Date&, const Date&) const {
29+
int years =0;
30+
int months = 0;
31+
years = d2.year() - d1.year();
32+
months = d2.month() - d1.month();
33+
return static_cast<Time>(years * 12 + months) / 12.0;
34+
}
35+
36+
} // namespace QuantExt

QuantExt/qle/time/monthcounter.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

xsd/ore_types.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@
401401
<xs:enumeration value="Actual/364"/>
402402
<xs:enumeration value="Act/364"/>
403403
<xs:enumeration value="ACT/364"/>
404+
<xs:enumeration value="Month"/>
404405
</xs:restriction>
405406
</xs:simpleType>
406407

0 commit comments

Comments
 (0)