24#include <ql/exercise.hpp>
25#include <ql/instruments/payoffs.hpp>
34 const std::string& underlyingCcy,
35 const QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>& p,
36 const std::set<std::string>& tradeTypes, Size samples,
37 Size regressionOrder,
bool interactive,
38 bool scriptedLibraryOverride)
39 : underlying_(underlying), baseCcy_(baseCcy), underlyingCcy_(underlyingCcy), p_(p), samples_(samples),
40 regressionOrder_(regressionOrder),
interactive_(interactive) {
44 if (scriptedLibraryOverride) {
45 QL_REQUIRE(tradeTypes.size() == 1,
"");
46 string scriptName = *tradeTypes.begin();
48 QL_REQUIRE(ScriptLibraryStorage::instance().get().has(scriptName,
""),
49 "script '" << scriptName <<
"' not found in library");
53 scriptStr =
"NUMBER Payoff, d, premiumPayment;\n"
55 "premiumPayment = 0;\n"
56 "IF PremiumPaymentDate >= TODAY THEN"
57 " premiumPayment = PAY(LongShort * Notional * Premium, PremiumPaymentDate, PremiumPaymentDate, "
60 "FOR d IN (2, SIZE(ValuationDates), 1) DO"
61 " Payoff = Payoff + min( max( Type * ( (Underlying(ValuationDates[d]) / "
62 "Underlying(ValuationDates[d-1])) - Moneyness ), LocalFloor ), LocalCap );"
64 "Option = premiumPayment + PAY( LongShort * Notional * min( max( Payoff, GlobalFloor ), GlobalCap "
65 "), Expiry, PayDate, PayCcy );\n";
69 QL_REQUIRE(parser.
success(),
"could not initialise AST for McScriptEuropeanEngine: " << parser.
error());
78 QL_REQUIRE(
arguments_.exercise->type() == Exercise::European,
"not an European option");
79 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff = QuantLib::ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
80 QL_REQUIRE(payoff,
"non-striked payoff given");
85 auto builder = QuantLib::ext::make_shared<BlackScholesModelBuilder>(
p_->riskFreeRate(),
p_,
arguments_.valuationDates,
88 builder->model()->registerWith(
p_);
92 builder->model(), mcParams,
arguments_.valuationDates);
96 auto context = QuantLib::ext::make_shared<Context>();
97 context->scalars[
"TODAY"] =
EventVec{
samples_, Settings::instance().evaluationDate()};
99 std::vector<ValueType> tmp;
100 for (
auto const& d :
arguments_.valuationDates)
102 context->arrays[
"ValuationDates"] = tmp;
108 context->scalars[
"LongShort"] =
110 context->scalars[
"LocalCap"] =
112 context->scalars[
"LocalFloor"] =
114 context->scalars[
"GlobalCap"] =
116 context->scalars[
"GlobalFloor"] =
119 context->scalars[
"Premium"] =
129 results_.value =
expectation(QuantLib::ext::get<RandomVariable>(context->scalars.at(
"Option"))).
at(0);
black scholes model for n underlyings (fx, equity or commodity)
builder for an array of black scholes processes
const Instrument::results * results_
const Size regressionOrder_
const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > p_
const std::string underlyingCcy_
CliquetOptionMcScriptEngine(const std::string &underlying, const std::string &baseCcy, const std::string &underlyingCcy, const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > &p, const std::set< std::string > &tradeTypes, const Size samples, const Size regressionOrder, bool interactive, bool scriptedLibraryOverride)
void calculate() const override
const std::string baseCcy_
const std::string underlying_
void run(const std::string &script="", bool interactive=false, QuantLib::ext::shared_ptr< PayLog > paylog=nullptr, bool includePastCashflows=false)
const ParserError & error() const
RandomVariable expectation(const RandomVariable &r)
Serializable Credit Default Swap.
Real at(const Size i) const
Swap::arguments * arguments_