Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crosscurrencypricetermstructure.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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#include <algorithm>
21
22using QuantLib::Date;
23using QuantLib::Handle;
24using QuantLib::Natural;
25using QuantLib::Quote;
26using QuantLib::Time;
27using QuantLib::YieldTermStructure;
28using std::max;
29using std::min;
30using std::vector;
31
32namespace QuantExt {
33
35 const QuantLib::Date& referenceDate, const QuantLib::Handle<PriceTermStructure>& basePriceTs,
36 const QuantLib::Handle<QuantLib::Quote>& fxSpot,
37 const QuantLib::Handle<QuantLib::YieldTermStructure>& baseCurrencyYts,
38 const QuantLib::Handle<QuantLib::YieldTermStructure>& yts, const QuantLib::Currency& currency)
39 : PriceTermStructure(referenceDate, basePriceTs->calendar(), basePriceTs->dayCounter()), basePriceTs_(basePriceTs),
40 fxSpot_(fxSpot), baseCurrencyYts_(baseCurrencyYts), yts_(yts), currency_(currency) {
42}
43
45 Natural settlementDays, const QuantLib::Handle<PriceTermStructure>& basePriceTs,
46 const QuantLib::Handle<QuantLib::Quote>& fxSpot,
47 const QuantLib::Handle<QuantLib::YieldTermStructure>& baseCurrencyYts,
48 const QuantLib::Handle<QuantLib::YieldTermStructure>& yts, const QuantLib::Currency& currency)
49 : PriceTermStructure(settlementDays, basePriceTs->calendar(), basePriceTs->dayCounter()), basePriceTs_(basePriceTs),
50 fxSpot_(fxSpot), baseCurrencyYts_(baseCurrencyYts), yts_(yts), currency_(currency) {
52}
53
55 return min(basePriceTs_->maxDate(), min(baseCurrencyYts_->maxDate(), yts_->maxDate()));
56}
57
59 return min(basePriceTs_->maxTime(), min(baseCurrencyYts_->maxTime(), yts_->maxTime()));
60}
61
62Time CrossCurrencyPriceTermStructure::minTime() const { return basePriceTs_->minTime(); }
63
64vector<Date> CrossCurrencyPriceTermStructure::pillarDates() const { return basePriceTs_->pillarDates(); }
65
66QuantLib::Real CrossCurrencyPriceTermStructure::priceImpl(QuantLib::Time t) const {
67 // Price in base currency times the FX forward, number of units of currency per unit of base currency.
68 return basePriceTs_->price(t, true) * fxSpot_->value() * baseCurrencyYts_->discount(t, true) /
69 yts_->discount(t, true);
70}
71
73 registerWith(basePriceTs_);
74 registerWith(fxSpot_);
75 registerWith(baseCurrencyYts_);
76 registerWith(yts_);
77}
78
79} // namespace QuantExt
CrossCurrencyPriceTermStructure(const QuantLib::Date &referenceDate, const QuantLib::Handle< PriceTermStructure > &basePriceTs, const QuantLib::Handle< QuantLib::Quote > &fxSpot, const QuantLib::Handle< QuantLib::YieldTermStructure > &baseCurrencyYts, const QuantLib::Handle< QuantLib::YieldTermStructure > &yts, const QuantLib::Currency &currency)
QuantLib::Time minTime() const override
The minimum time for which the curve can return values.
void registration()
Register with underlying market data.
QuantLib::Handle< QuantLib::YieldTermStructure > baseCurrencyYts_
std::vector< QuantLib::Date > pillarDates() const override
The pillar dates for the PriceTermStructure.
QuantLib::Handle< QuantLib::YieldTermStructure > yts_
QuantLib::Handle< PriceTermStructure > basePriceTs_
QuantLib::Real priceImpl(QuantLib::Time t) const override
Price calculation.
Price term structure in a given currency derived from a price term structure in another currency.
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)