27 const QuantLib::ext::shared_ptr<YieldTermStructure>& discount,
28 Natural spotDays,
const Calendar& spotCalendar)
29 : priceCurve_(priceCurve), discount_(discount), spotDays_(spotDays), spotCalendar_(spotCalendar) {
32 priceCurve_->referenceDate() == discount_->referenceDate(),
33 "PriceTermStructureAdapter: The reference date of the discount curve and price curve should be the same");
35 registerWith(priceCurve_);
36 registerWith(discount_);
39PriceTermStructureAdapter::PriceTermStructureAdapter(
const QuantLib::ext::shared_ptr<PriceTermStructure>& priceCurve,
40 const QuantLib::ext::shared_ptr<YieldTermStructure>& discount,
41 const Handle<Quote>& spotQuote)
42 : priceCurve_(priceCurve), discount_(discount), spotDays_(0), spotQuote_(spotQuote) {
45 priceCurve_->referenceDate() == discount_->referenceDate(),
46 "PriceTermStructureAdapter: The reference date of the discount curve and price curve should be the same");
48 registerWith(priceCurve_);
49 registerWith(discount_);
50 registerWith(spotQuote_);
53Date PriceTermStructureAdapter::maxDate()
const {
56 return min(priceCurve_->maxDate(), discount_->maxDate());
59const Date& PriceTermStructureAdapter::referenceDate()
const {
61 priceCurve_->referenceDate() == discount_->referenceDate(),
62 "PriceTermStructureAdapter: The reference date of the discount curve and price curve should be the same");
63 return priceCurve_->referenceDate();
66DayCounter PriceTermStructureAdapter::dayCounter()
const {
return priceCurve_->dayCounter(); }
68const QuantLib::ext::shared_ptr<PriceTermStructure>& PriceTermStructureAdapter::priceCurve()
const {
return priceCurve_; }
70const QuantLib::ext::shared_ptr<YieldTermStructure>& PriceTermStructureAdapter::discount()
const {
return discount_; }
72Natural PriceTermStructureAdapter::spotDays()
const {
return spotDays_; }
74const Calendar& PriceTermStructureAdapter::spotCalendar()
const {
return spotCalendar_; }
76DiscountFactor PriceTermStructureAdapter::discountImpl(Time t)
const {
82 if (spotQuote_.empty()) {
83 Time spotTime = timeFromReference(spotCalendar_.advance(referenceDate(), spotDays_ * Days));
84 spotPrice = priceCurve_->price(spotTime,
true);
86 spotPrice = spotQuote_->value();
88 Real forwardPrice = priceCurve_->price(t,
true);
89 DiscountFactor discount = discount_->discount(t,
true);
90 return discount * forwardPrice / spotPrice;
PriceTermStructureAdapter(const QuantLib::ext::shared_ptr< PriceTermStructure > &priceCurve, const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > &discount, QuantLib::Natural spotDays=0, const QuantLib::Calendar &spotCalendar=QuantLib::NullCalendar())
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
PriceTermStructure adapter.