Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityapo.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 <ql/exercise.hpp>
20#include <ql/shared_ptr.hpp>
22
23namespace QuantExt {
24
25CommodityAveragePriceOption::CommodityAveragePriceOption(const QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow>& flow,
26 const ext::shared_ptr<Exercise>& exercise, const Real quantity,
27 const Real strikePrice, QuantLib::Option::Type type,
28 QuantLib::Settlement::Type delivery,
29 QuantLib::Settlement::Method settlementMethod,
30 const Real barrierLevel, Barrier::Type barrierType,
31 Exercise::Type barrierStyle,
32 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex)
33 : Option(ext::shared_ptr<Payoff>(), exercise), flow_(flow), quantity_(quantity), strikePrice_(strikePrice),
34 type_(type), settlementType_(delivery), settlementMethod_(settlementMethod), fxIndex_(fxIndex),
35 barrierLevel_(barrierLevel), barrierType_(barrierType), barrierStyle_(barrierStyle) {
36 flow_->alwaysForwardNotifications();
37 registerWith(flow_);
38 if (fxIndex_)
39 registerWith(fxIndex_);
40}
41
42bool CommodityAveragePriceOption::isExpired() const { return detail::simple_event(flow_->date()).hasOccurred(); }
43
45 return (strikePrice_ - flow_->spread()) / flow_->gearing();
46}
47
48Real CommodityAveragePriceOption::accrued(const Date& refDate) const {
49 Real tmp = 0.0;
50
51 // If all of the pricing dates are greater than today => no accrued
52 if (refDate >= flow_->indices().begin()->first) {
53 for (const auto& kv : flow_->indices()) {
54 // Break on the first pricing date that is greater than today
55 if (refDate < kv.first) {
56 break;
57 }
58 // Update accrued where pricing date is on or before today
59 Real fxRate = (fxIndex_)?fxIndex_->fixing(kv.first):1.;
60 tmp += fxRate*kv.second->fixing(kv.first);
61 }
62 // We should have pricing dates in the period but check.
63 auto n = flow_->indices().size();
64 QL_REQUIRE(n > 0, "APO coupon accrued calculation has a degenerate coupon.");
65 tmp /= n;
66 }
67
68 return tmp;
69}
70
71void CommodityAveragePriceOption::setupArguments(PricingEngine::arguments* args) const {
72 Option::setupArguments(args);
73
75
76 QL_REQUIRE(arguments != 0, "wrong argument type");
77 QL_REQUIRE(flow_->gearing() > 0.0, "The gearing on an APO must be positive");
78
79 Date today = Settings::instance().evaluationDate();
80
84 arguments->accrued = accrued(today);
91 arguments->exercise = exercise_;
94}
95
97 : quantity(0.0), strikePrice(0.0), effectiveStrike(0.0), type(Option::Call), fxIndex(nullptr),
98 settlementType(Settlement::Physical), settlementMethod(Settlement::PhysicalOTC), barrierLevel(Null<Real>()),
99 barrierType(Barrier::DownIn), barrierStyle(Exercise::American) {}
100
102 QL_REQUIRE(flow, "underlying not set");
103 QL_REQUIRE(exercise, "exercise not set");
104 QuantLib::Settlement::checkTypeAndMethodConsistency(settlementType, settlementMethod);
105}
106
107} // namespace QuantExt
Arguments for commodity APO calculation
QuantLib::ext::shared_ptr< FxIndex > fxIndex
QuantLib::ext::shared_ptr< CommodityIndexedAverageCashFlow > flow
Real accrued(const Date &refDate) const
QuantLib::Settlement::Type settlementType_
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
void setupArguments(PricingEngine::arguments *) const override
Settlement::Type settlementType() const
QuantLib::ext::shared_ptr< CommodityIndexedAverageCashFlow > flow_
QuantLib::Settlement::Method settlementMethod_
CommodityAveragePriceOption(const QuantLib::ext::shared_ptr< CommodityIndexedAverageCashFlow > &flow, const ext::shared_ptr< Exercise > &exercise, const Real quantity, const Real strikePrice, Option::Type type, Settlement::Type delivery=Settlement::Physical, Settlement::Method settlementMethod=Settlement::PhysicalOTC, const Real barrierLevel=Null< Real >(), Barrier::Type barrierType=Barrier::Type::DownIn, Exercise::Type barrierStyle=Exercise::American, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
Settlement::Method settlementMethod() const
Swaption class.