Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
offpeakpowerindex.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
20#include <ql/time/calendars/nullcalendar.hpp>
21
22using QuantLib::Date;
23using QuantLib::Real;
24using QuantLib::Calendar;
25using QuantLib::NullCalendar;
26using std::string;
27
28namespace QuantExt {
29
30OffPeakPowerIndex::OffPeakPowerIndex(const string& underlyingName,
31 const Date& expiryDate,
32 const QuantLib::ext::shared_ptr<CommodityFuturesIndex>& offPeakIndex,
33 const QuantLib::ext::shared_ptr<CommodityFuturesIndex>& peakIndex,
34 Real offPeakHours,
35 const Calendar& peakCalendar,
36 const Handle<PriceTermStructure>& priceCurve)
37 : CommodityFuturesIndex(underlyingName, expiryDate, NullCalendar(), true, priceCurve),
38 offPeakIndex_(offPeakIndex), peakIndex_(peakIndex), offPeakHours_(offPeakHours),
39 peakCalendar_(peakCalendar) {
40 string msgPrefix = "Constructing " + underlyingName + ": ";
41 QL_REQUIRE(0.0 < offPeakHours_ && offPeakHours_ < 24.0, msgPrefix << "off-peak hours must be in (0, 24.0)");
42 QL_REQUIRE(expiryDate_ == offPeakIndex_->expiryDate(), msgPrefix << "the expiry date (" <<
43 io::iso_date(expiryDate_) << ") should equal the off-peak index expiry date (" <<
44 io::iso_date(offPeakIndex_->expiryDate()) << ").");
45 QL_REQUIRE(expiryDate_ == peakIndex_->expiryDate(), msgPrefix << "the expiry date (" <<
46 io::iso_date(expiryDate_) << ") should equal the peak index expiry date (" <<
47 io::iso_date(peakIndex_->expiryDate()) << ").");
48 QL_REQUIRE(offPeakIndex_, msgPrefix << "the off-peak index should not be null.");
49 QL_REQUIRE(peakIndex_, msgPrefix << "the peak index should not be null.");
50}
51
52const QuantLib::ext::shared_ptr<CommodityFuturesIndex>& OffPeakPowerIndex::offPeakIndex() const {
53 return offPeakIndex_;
54}
55
56const QuantLib::ext::shared_ptr<CommodityFuturesIndex>& OffPeakPowerIndex::peakIndex() const {
57 return peakIndex_;
58}
59
61 return offPeakHours_;
62}
63
64const Calendar& OffPeakPowerIndex::peakCalendar() const {
65 return peakCalendar_;
66}
67
68QuantLib::ext::shared_ptr<CommodityIndex> OffPeakPowerIndex::clone(const Date& expiry,
69 const boost::optional<Handle<PriceTermStructure>>& ts) const {
70 const auto& pts = ts ? *ts : priceCurve();
71 const auto& ed = expiry == Date() ? expiryDate() : expiry;
72 auto offPeakIndex = QuantLib::ext::dynamic_pointer_cast<CommodityFuturesIndex>(offPeakIndex_->clone(ed));
73 auto peakIndex = QuantLib::ext::dynamic_pointer_cast<CommodityFuturesIndex>(peakIndex_->clone(ed));
74 return QuantLib::ext::make_shared<OffPeakPowerIndex>(underlyingName(), ed, offPeakIndex,
76}
77
78Real OffPeakPowerIndex::pastFixing(const Date& fixingDate) const {
79 if (peakCalendar_.isBusinessDay(fixingDate))
80 return offPeakIndex_->fixing(fixingDate);
81 else
82 return (offPeakHours_ * offPeakIndex_->fixing(fixingDate) +
83 (24.0 - offPeakHours_) * peakIndex_->fixing(fixingDate)) / 24.0;
84}
85
86}
const QuantLib::Date & expiryDate() const
const Handle< QuantExt::PriceTermStructure > & priceCurve() const
std::string underlyingName() const
const QuantLib::ext::shared_ptr< CommodityFuturesIndex > & offPeakIndex() const
OffPeakPowerIndex(const std::string &underlyingName, const QuantLib::Date &expiryDate, const QuantLib::ext::shared_ptr< CommodityFuturesIndex > &offPeakIndex, const QuantLib::ext::shared_ptr< CommodityFuturesIndex > &peakIndex, QuantLib::Real offPeakHours, const QuantLib::Calendar &peakCalendar, const Handle< QuantExt::PriceTermStructure > &priceCurve=Handle< QuantExt::PriceTermStructure >())
Constructor.
QuantLib::Calendar peakCalendar_
const QuantLib::ext::shared_ptr< CommodityFuturesIndex > & peakIndex() const
QuantLib::ext::shared_ptr< CommodityFuturesIndex > peakIndex_
QuantLib::ext::shared_ptr< CommodityFuturesIndex > offPeakIndex_
QuantLib::ext::shared_ptr< CommodityIndex > clone(const QuantLib::Date &expiryDate, const boost::optional< QuantLib::Handle< PriceTermStructure > > &ts=boost::none) const override
Implement the base clone.
const QuantLib::Calendar & peakCalendar() const
Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
QuantLib::Real offPeakHours() const
commodity future index for off peak power prices.