Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
pnlanalytic.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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/*! \file orea/app/analytics/pnlanalytic.hpp
20 \brief ORE NPV Lagged Analytic
21*/
22#pragma once
23
27#include <orea/app/analytic.hpp>
28
29namespace ore {
30namespace analytics {
31
33public:
34 static constexpr const char* LABEL = "PNL";
35 static constexpr const char* mporLookupKey = "MPOR";
36
37 PnlAnalyticImpl(const QuantLib::ext::shared_ptr<InputParameters>& inputs)
38 : Analytic::Impl(inputs), useSpreadedTermStructures_(true) {
40 mporDate_ = inputs_->mporDate() != Date()
41 ? inputs_->mporDate()
42 : inputs_->mporCalendar().advance(inputs_->asof(), int(inputs_->mporDays()), QuantExt::Days);
43 LOG("ASOF date " << io::iso_date(inputs_->asof()));
44 LOG("MPOR date " << io::iso_date(mporDate_));
45
46 auto mporAnalytic = AnalyticFactory::instance().build("SCENARIO", inputs);
47 if (mporAnalytic.second) {
48 auto sai = static_cast<ScenarioAnalyticImpl*>(mporAnalytic.second->impl().get());
50 addDependentAnalytic(mporLookupKey, mporAnalytic.second);
51 }
52 }
53 void runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
54 const std::set<std::string>& runTypes = {}) override;
55 void setUpConfigurations() override;
56
58 const QuantLib::Date& mporDate() const { return mporDate_; }
59 std::vector<QuantLib::Date> additionalMarketDates() const override { return {mporDate_}; }
60
61 const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& t0Scenario() const { return t0Scenario_; }
62 const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& t1Scenario() const { return t1Scenario_; }
63 void setT0Scenario(const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& scenario) { t0Scenario_ = scenario; }
64 void setT1Scenario(const QuantLib::ext::shared_ptr<ore::analytics::Scenario>& scenario) { t1Scenario_ = scenario; }
65
66private:
68 QuantLib::Date mporDate_;
69 QuantLib::ext::shared_ptr<ore::analytics::Scenario> t0Scenario_, t1Scenario_;
70};
71
72/*!
73 The P&L Analytic generates a P&L report as main output with the following columns
74 - TradeId and
75 - Maturity and MaturityTime
76 - StartDate and EndDate of the P&L period, referred to as t0 and t1 below
77 - NPV(t0)
78 - NPV(asof=t0;mkt=t1)
79 - NPV(asof=t1;mkt=t0)
80 - NPV(t1)
81 - PeriodCashFlow: Aggregate of trade flows in the period, converted into the P&L currency below, compounding?
82 - Theta: NPV(asof=t1;mkt=t0) - NPV(t0), Cash Flows?
83 - HypotheticalCleanPnL: NPV(asof=t0;mkt=t1) - NPV(t0)
84 - CleanPnL: NPV(t1) - NPV(t0) + PeriodCashFlow
85 - DirtyPnL: NPV(t1) - NPV(t0)
86 - Currency
87
88 Moreover
89 - four corresponding NPV and additional results reports are generated
90 - market scenarios used for the two "lagged" NPV calculations are written as reports
91
92*/
93class PnlAnalytic : public Analytic {
94public:
95 PnlAnalytic(const QuantLib::ext::shared_ptr<InputParameters>& inputs)
96 : Analytic(std::make_unique<PnlAnalyticImpl>(inputs), {"PNL"}, inputs, false, false, false, false) {}
97
98};
99
100} // namespace analytics
101} // namespace ore
ORE Analytics Manager.
void setLabel(const string &label)
Definition: analytic.hpp:189
void addDependentAnalytic(const std::string &key, const QuantLib::ext::shared_ptr< Analytic > &analytic)
Definition: analytic.hpp:209
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: analytic.hpp:216
const QuantLib::ext::shared_ptr< InputParameters > & inputs() const
Definition: analytic.hpp:116
PnlAnalytic(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: pnlanalytic.hpp:95
void setUpConfigurations() override
Definition: pnlanalytic.cpp:34
const QuantLib::ext::shared_ptr< ore::analytics::Scenario > & t1Scenario() const
Definition: pnlanalytic.hpp:62
void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
Definition: pnlanalytic.cpp:43
void setT1Scenario(const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &scenario)
Definition: pnlanalytic.hpp:64
PnlAnalyticImpl(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: pnlanalytic.hpp:37
void setT0Scenario(const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &scenario)
Definition: pnlanalytic.hpp:63
QuantLib::ext::shared_ptr< ore::analytics::Scenario > t0Scenario_
Definition: pnlanalytic.hpp:69
std::vector< QuantLib::Date > additionalMarketDates() const override
Definition: pnlanalytic.hpp:59
QuantLib::ext::shared_ptr< ore::analytics::Scenario > t1Scenario_
Definition: pnlanalytic.hpp:69
static constexpr const char * mporLookupKey
Definition: pnlanalytic.hpp:35
const QuantLib::Date & mporDate() const
Definition: pnlanalytic.hpp:58
const QuantLib::ext::shared_ptr< ore::analytics::Scenario > & t0Scenario() const
Definition: pnlanalytic.hpp:61
static constexpr const char * LABEL
Definition: pnlanalytic.hpp:34
void setUseSpreadedTermStructures(const bool useSpreadedTermStructures)
#define LOG(text)
ORE Scenario Analytic.