20#include <ql/experimental/credit/syntheticcdo.hpp>
22#ifndef QL_PATCH_SOLARIS
24#include <ql/cashflows/fixedratecoupon.hpp>
25#include <ql/event.hpp>
26#include <ql/math/solvers1d/brent.hpp>
27#include <ql/termstructures/yieldtermstructure.hpp>
28#include <ql/experimental/credit/gaussianlhplossmodel.hpp>
29#include <ql/experimental/credit/midpointcdoengine.hpp>
30#include <ql/optional.hpp>
43 ext::optional<Real> notional)
44 : basket_(basket), side_(side), upfrontRate_(upfrontRate), runningRate_(runningRate),
45 leverageFactor_(notional ? *notional / basket->trancheNotional() :
Real(1.)),
46 dayCounter_(dayCounter), paymentConvention_(paymentConvention) {
47 QL_REQUIRE(!
basket->names().empty(),
"basket is empty");
52 "Basket did not exist before contract start.");
65 for (
Size i = 0; i <
basket->names().size(); i++) {
78 defaultProbability(
basket->pool()->defaultKeys()[i]));
111 QL_REQUIRE(
premiumValue_ != 0,
"Attempted divide by zero while calculating syntheticCDO premium.");
145 QL_REQUIRE(
arguments !=
nullptr,
"wrong argument type");
161 QL_REQUIRE(
results !=
nullptr,
"wrong result type");
182 QL_REQUIRE(
basket && !
basket->names().empty(),
"no basket given");
204 class ObjectiveFunction {
206 ObjectiveFunction(
Real target,
210 : target_(target), quote_(quote),
214 quote_.setValue(guess);
216 return results_->value - target_;
221 PricingEngine& engine_;
222 const SyntheticCDO::results* results_;
234 ext::shared_ptr<SimpleQuote> correl(
new SimpleQuote(0.0));
236 ext::shared_ptr<GaussianLHPLossModel> lhp(
new
250 ObjectiveFunction f(targetNPV, *correl, engineIC,
results);
bool empty() const
Returns whether or not the day counter is initialized.
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
helper class building a sequence of fixed rate coupons
FixedRateLeg & withNotionals(Real)
FixedRateLeg & withPaymentAdjustment(BusinessDayConvention)
FixedRateLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
PricingEngine::arguments * getArguments() const override
const PricingEngine::results * getResults() const override
Shared handle to an observable.
void calculate() const override
virtual void fetchResults(const PricingEngine::results *) const
virtual void setupExpired() const
CDO base engine taking schedule steps.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
interface for pricing engines
const Date & startDate() const
market element returning a stored value
Real solve(const F &f, Real accuracy, Real guess, Real step) const
ext::shared_ptr< Basket > basket
void validate() const override
BusinessDayConvention paymentConvention
std::vector< Real > expectedTrancheLoss
Real upfrontPremiumValue_
Rate fairUpfrontPremium() const
ext::shared_ptr< Basket > basket_
void setupArguments(PricingEngine::arguments *) const override
const ext::shared_ptr< Basket > & basket() const
bool isExpired() const override
returns whether the instrument might have value greater than zero.
SyntheticCDO(const ext::shared_ptr< Basket > &basket, Protection::Side side, const Schedule &schedule, Rate upfrontRate, Rate runningRate, const DayCounter &dayCounter, BusinessDayConvention paymentConvention, ext::optional< Real > notional=ext::nullopt)
Real implicitCorrelation(const std::vector< Real > &recoveries, const Handle< YieldTermStructure > &discountCurve, Real targetNPV=0., Real accuracy=1.0e-3) const
Rate protectionValue() const
Real protectionLegNPV() const
BusinessDayConvention paymentConvention_
Real premiumLegNPV() const
void setupExpired() const override
const Real leverageFactor_
void fetchResults(const PricingEngine::results *) const override
std::vector< Real > expectedTrancheLoss() const
Rate premiumValue() const
std::vector< Real > expectedTrancheLoss_
Real remainingNotional() const
BusinessDayConvention
Business Day conventions.
std::size_t Size
size of a container