Skip to content

Commit 8b5e78a

Browse files
pcaspersjenkins
authored andcommitted
QPR-12370 migrate ORE+ to ORE
1 parent dd74a3f commit 8b5e78a

96 files changed

Lines changed: 14143 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Docs/UserGuide/userguide.tex

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ \section{Examples}\label{sec:examples}
12431243
\hline
12441244
43 & Credit Portfolio Model \\
12451245
\hline
1246-
44 & ISDA SIMM Model \\
1246+
44 & Initial Margin: ISDA SIMM and IM Schedule \\
12471247
\hline
12481248
45 & Collateralized Bond Obligation \\
12491249
\hline
@@ -3241,12 +3241,14 @@ \subsection{Credit Portfolio Model}% Example 43
32413241
The last demo case in this table can be activated by uncommenting the corresponding section at the end of the {\tt run.py} script.
32423242

32433243
%--------------------------------------------------------------------
3244-
\subsection{ISDA SIMM Model}% Example 44
3244+
\subsection{Initial Margin: ISDA SIMM and IM Schedule}% Example 44
32453245
\label{example:44}
32463246
%--------------------------------------------------------------------
32473247

32483248
This example demonstrates the calculation of initial margin using ISDA's Standard Initial Margin Model (SIMM) based on a provided
3249-
sensitivity file in ISDA's Common Risk Interchange Format (CRIF).
3249+
sensitivity file in ISDA's Common Risk Interchange Format (CRIF). In addition, we show how to use the standard "IM Schdule" method to compute
3250+
initial margin.
3251+
32503252
ORE covers all SIMM versions since inception to date, i.e.\ 1.0, 1.1, 1.2, 1.3, 1.3.38, 2.0, 2.1, 2.2, 2.3, 2.4 (=2.3.8), 2.5, 2.5A, 2.6 (=2.5.6).
32513253
All versions have been tested against the respective ISDA SIMM model unit test suites and pass these tests.
32523254
Any new SIMM versions will be added with each ORE release.
@@ -3274,7 +3276,7 @@ \subsection{ISDA SIMM Model}% Example 44
32743276
\end{itemize}
32753277

32763278
\medskip
3277-
There are four input files -- {\tt ore\_SIMM2.4\_1D.xml}, {\tt ore\_SIMM2.4\_10D.xml}, {\tt ore\_SIMM2.6\_1D.xml}, {\tt ore\_SIMM2.6\_10D.xml} -- with corresponding folders in the {\tt Output/} directory.
3279+
There are four SIMM-related input files -- {\tt ore\_SIMM2.4\_1D.xml}, {\tt ore\_SIMM2.4\_10D.xml}, {\tt ore\_SIMM2.6\_1D.xml}, {\tt ore\_SIMM2.6\_10D.xml} -- with corresponding folders in the {\tt Output/} directory.
32783280
The relevant inputs in the files are:
32793281

32803282
\begin{itemize}
@@ -3293,6 +3295,34 @@ \subsection{ISDA SIMM Model}% Example 44
32933295
\medskip
32943296
\centerline{\tt python ore.py}
32953297

3298+
\subsubsection*{IM Schedule}
3299+
3300+
As an additonal case in this example we demonstrate how to use the IM Schedule method to compute initial margin.
3301+
The related input file is {\tt Input/ore\_schedule.xml}. It is also run when calling {\tt python run.py}, and results are written to folder
3302+
{\tt Output/IM\_SCHEDULE}.
3303+
The basic input is provided in CRIF file format where ORE expects two lines per trade, one with RiskClass = PV and one with RiskClass = Notional,
3304+
so that the amounts in these CRIF lines are interpeted as NPV respectively notional.
3305+
Further required columns are product class and end date, as shown in the example {\tt Input/crif\_schedule.csv}. Note that the product class has to be in
3306+
\begin{itemize}
3307+
\item Rates
3308+
\item FX
3309+
\item Equity
3310+
\item Credit
3311+
\item Commodity
3312+
\end{itemize}
3313+
in contrast to SIMM where we use the combined RatesFX.
3314+
3315+
To run the IM Schedule analytic, the following minimal addition to {\tt Input/ore\_schedule.xml} is required.
3316+
\begin{minted}[fontsize=\scriptsize]{xml}
3317+
<Analytics>
3318+
<Analytic type="imschedule">
3319+
<Parameter name="active">Y</Parameter>
3320+
<Parameter name="crif">crif_schedule.csv</Parameter>
3321+
<Parameter name="calculationCurrency">USD</Parameter>
3322+
</Analytic>
3323+
</Analytics>
3324+
\end{minted}
3325+
32963326
%--------------------------------------------------------
32973327
\subsection{Collateralized Bond Obligation}% Example 45
32983328
%--------------------------------------------------------
@@ -3904,6 +3934,7 @@ \subsubsection{Analytics}\label{sec:analytics}
39043934
\item stress
39053935
\item parametricVar
39063936
\item simm
3937+
\item imschedule
39073938
\end{itemize}
39083939

39093940
Each {\tt Analytic} section contains a list of key/value pairs to parameterise the analysis of the form {\tt <Parameter
@@ -4464,6 +4495,39 @@ \subsubsection{Analytics}\label{sec:analytics}
44644495

44654496
The SIMM analytic requires minimal market data input and today's market configuration - FX rates for conversions calculation currency, USD and result currency.
44664497

4498+
\medskip The {\tt imschedule} 'analytic' provides initial margin calculation using the standard "IM Schedule" method that is based on
4499+
trade NPV, notional, end date and product class. ORE expects the inputs in the form of a CRIF file.
4500+
Listing \ref{lst:ore_simm} shows a configuration example.
4501+
4502+
\begin{listing}[H]
4503+
\begin{minted}[fontsize=\footnotesize]{xml}
4504+
<Analytics>
4505+
<Analytic type="imschedule">
4506+
<Parameter name="active">Y</Parameter>
4507+
<Parameter name="crif">schedule_crif.csv</Parameter>
4508+
<Parameter name="calculationCurrency">USD</Parameter>
4509+
</Analytic>
4510+
<Analytics>
4511+
\end{minted}
4512+
\caption{ORE analytic: IM Schedule}
4513+
\label{lst:ore_schedule}
4514+
\end{listing}
4515+
4516+
The input CRIF file here has two lines per trade, for RiskClass = PV respectively RiskClass Notional.
4517+
Additonally required columns are product class and end date, see example 44.
4518+
The idea is that the inputs can be externally provided. Therefore the IM Schedule analytic does not require a portfolio.
4519+
The alternative -- ORE uses a portfolio to compute NPV, imply product class and end date -- has not been implemented yet.
4520+
4521+
Note that the IM Schedule product class has to be in
4522+
\begin{itemize}
4523+
\item Rates
4524+
\item FX
4525+
\item Equity
4526+
\item Credit
4527+
\item Commodity
4528+
\end{itemize}
4529+
in contrast to SIMM where we use the combined RatesFX product class.
4530+
44674531
%--------------------------------------------------------
44684532
\subsection{Market: {\tt todaysmarket.xml}}\label{sec:market}
44694533
%--------------------------------------------------------
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Portfolio,ProductClass,GrossIM,GrossCurrentRC,NetCurrentRC,NetToGrossRatio,Side,Regulation,ScheduleIM,Currency
2+
nettingSetId_1,Rates,989.66,#N/A,#N/A,#N/A,Call,Unspecified,989.66,USD
3+
nettingSetId_1,All,989.66,4804.86,501.06,0.104282,Call,Unspecified,457.79,USD
4+
All,All,#N/A,#N/A,#N/A,#N/A,Call,Unspecified,457.79,USD
5+
nettingSetId_1,Rates,989.66,#N/A,#N/A,#N/A,Post,Unspecified,989.66,USD
6+
nettingSetId_1,All,989.66,-4303.80,0.00,0.000000,Post,Unspecified,395.86,USD
7+
All,All,#N/A,#N/A,#N/A,#N/A,Post,Unspecified,395.86,USD
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#TradeId,Portfolio,ProductClass,EndDate,Maturity,Label,Multiplier,Notional,NotionalCurrency,PV,PVCurrency,Notional(Base),PV(Base),BaseCurrency,GrossIM(Base),CollectRegulations,PostRegulations
2+
IM_Schedule_1,nettingSetId_1,Rates,2021-08-24,1.64932,Interest Rate 0-2 years,0.01,6027.63,EUR,1014.05,EUR,7074.63,1190.19,USD,70.75,Unspecified,Unspecified
3+
IM_Schedule_2,nettingSetId_1,Rates,2021-08-24,1.64932,Interest Rate 0-2 years,0.01,1.14,GBP,874.35,GBP,1.51,1154.14,USD,0.02,Unspecified,Unspecified
4+
IM_Schedule_3,nettingSetId_1,Rates,2021-08-24,1.64932,Interest Rate 0-2 years,0.01,5496.62,USD,-1166.76,USD,5496.62,-1166.76,USD,54.97,Unspecified,Unspecified
5+
IM_Schedule_4,nettingSetId_1,Rates,2022-08-24,2.64932,Interest Rate 2-5 years,0.02,2909.05,EUR,1038.63,EUR,3414.35,1219.04,USD,68.29,Unspecified,Unspecified
6+
IM_Schedule_5,nettingSetId_1,Rates,2022-08-24,2.64932,Interest Rate 2-5 years,0.02,9726.84,GBP,-699.44,GBP,12839.43,-923.26,USD,256.79,Unspecified,Unspecified
7+
IM_Schedule_6,nettingSetId_1,Rates,2022-08-24,2.64932,Interest Rate 2-5 years,0.02,2067.19,USD,-308.77,USD,2067.19,-308.77,USD,41.34,Unspecified,Unspecified
8+
IM_Schedule_7,nettingSetId_1,Rates,2023-08-24,3.64932,Interest Rate 2-5 years,0.02,8212.29,EUR,-1061.78,EUR,9638.77,-1246.22,USD,192.78,Unspecified,Unspecified
9+
IM_Schedule_8,nettingSetId_1,Rates,2023-08-24,3.64932,Interest Rate 2-5 years,0.02,9779.90,GBP,940.53,GBP,12909.46,1241.49,USD,258.19,Unspecified,Unspecified
10+
IM_Schedule_9,nettingSetId_1,Rates,2023-08-24,3.64932,Interest Rate 2-5 years,0.02,2327.28,USD,-658.80,USD,2327.28,-658.80,USD,46.55,Unspecified,Unspecified
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
TradeID,PortfolioID,ProductClass,RiskType,Qualifier,Bucket,Label1,Label2,AmountCurrency,Amount,AmountUSD,end_date,im_model
2+
IM_Schedule_1,nettingSetId_1,Rates,PV,,,,,EUR,1014.052346,1190.193238,24/08/2021,Schedule
3+
IM_Schedule_1,nettingSetId_1,Rates,Notional,,,,,EUR,6027.633761,7074.633745,24/08/2021,Schedule
4+
IM_Schedule_2,nettingSetId_1,Rates,PV,,,,,GBP,874.3453637,1154.13588,24/08/2021,Schedule
5+
IM_Schedule_2,nettingSetId_1,Rates,Notional,,,,,GBP,1.143748173,1.509747589,24/08/2021,Schedule
6+
IM_Schedule_3,nettingSetId_1,Rates,PV,,,,,USD,-1166.757847,-1166.757847,24/08/2021,Schedule
7+
IM_Schedule_3,nettingSetId_1,Rates,Notional,,,,,USD,5496.624779,5496.624779,24/08/2021,Schedule
8+
IM_Schedule_4,nettingSetId_1,Rates,PV,,,,,EUR,1038.628473,1219.038239,24/08/2022,Schedule
9+
IM_Schedule_4,nettingSetId_1,Rates,Notional,,,,,EUR,2909.047389,3414.348921,24/08/2022,Schedule
10+
IM_Schedule_5,nettingSetId_1,Rates,PV,,,,,GBP,-699.4382929,-923.2585466,24/08/2022,Schedule
11+
IM_Schedule_5,nettingSetId_1,Rates,Notional,,,,,GBP,9726.8436,12839.43355,24/08/2022,Schedule
12+
IM_Schedule_6,nettingSetId_1,Rates,PV,,,,,USD,-308.7725131,-308.7725131,24/08/2022,Schedule
13+
IM_Schedule_6,nettingSetId_1,Rates,Notional,,,,,USD,2067.191553,2067.191553,24/08/2022,Schedule
14+
IM_Schedule_7,nettingSetId_1,Rates,PV,,,,,EUR,-1061.783673,-1246.215498,24/08/2023,Schedule
15+
IM_Schedule_7,nettingSetId_1,Rates,Notional,,,,,EUR,8212.291231,9638.766217,24/08/2023,Schedule
16+
IM_Schedule_8,nettingSetId_1,Rates,PV,,,,,GBP,940.5257038,1241.493929,24/08/2023,Schedule
17+
IM_Schedule_8,nettingSetId_1,Rates,Notional,,,,,GBP,9779.89512,12909.46156,24/08/2023,Schedule
18+
IM_Schedule_9,nettingSetId_1,Rates,PV,,,,,USD,-658.7952834,-658.7952834,24/08/2023,Schedule
19+
IM_Schedule_9,nettingSetId_1,Rates,Notional,,,,,USD,2327.28328,2327.28328,24/08/2023,Schedule
20+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<ORE>
3+
<Setup>
4+
<Parameter name="asofDate">2019-12-30</Parameter>
5+
<Parameter name="inputPath">Input</Parameter>
6+
<Parameter name="outputPath">Output/IM_SCHEDULE</Parameter>
7+
<Parameter name="logFile">log.txt</Parameter>
8+
<Parameter name="logMask">255</Parameter>
9+
<Parameter name="marketDataFile">market.txt</Parameter>
10+
<Parameter name="fixingDataFile"></Parameter>
11+
<Parameter name="implyTodaysFixings">N</Parameter>
12+
<Parameter name="curveConfigFile">../../Input/curveconfig.xml</Parameter>
13+
<Parameter name="conventionsFile">../../Input/conventions.xml</Parameter>
14+
<Parameter name="marketConfigFile">todaysmarket.xml</Parameter>
15+
<Parameter name="pricingEnginesFile">../../Input/pricingengine.xml</Parameter>
16+
<Parameter name="portfolioFile"></Parameter>
17+
<Parameter name="observationModel">None</Parameter>
18+
</Setup>
19+
<Markets>
20+
<Parameter name="lgmcalibration">default</Parameter>
21+
<Parameter name="fxcalibration">default</Parameter>
22+
<Parameter name="pricing">default</Parameter>
23+
<Parameter name="simulation">default</Parameter>
24+
</Markets>
25+
<Analytics>
26+
<Analytic type="imschedule">
27+
<Parameter name="active">Y</Parameter>
28+
<Parameter name="crif">crif_schedule.csv</Parameter>
29+
<Parameter name="calculationCurrency">USD</Parameter>
30+
</Analytic>
31+
</Analytics>
32+
</ORE>

Examples/Example_44/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
for orexml in orexmls:
1818
oreex.print_headline(f"Run ORE SIMM; version={orexml[1]}; MPOR days={orexml[2]}")
1919
oreex.run(orexml[0])
20+
21+
oreex.print_headline(f"Run ORE for IM Schedule")
22+
oreex.run("Input/ore_schedule.xml")

OREAnalytics/orea/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ aggregation/postprocess.cpp
1717
aggregation/staticcreditxvacalculator.cpp
1818
aggregation/xvacalculator.cpp
1919
app/analytic.cpp
20+
app/analytics/imscheduleanalytic.cpp
2021
app/analytics/parconversionanalytic.cpp
2122
app/analytics/pricinganalytic.cpp
2223
app/analytics/scenarioanalytic.cpp
@@ -52,6 +53,7 @@ engine/filteredsensitivitystream.cpp
5253
engine/historicalpnlgenerator.cpp
5354
engine/historicalsensipnlcalculator.cpp
5455
engine/historicalsimulationvar.cpp
56+
engine/marketriskbacktest.cpp
5557
engine/marketriskreport.cpp
5658
engine/mporcalculator.cpp
5759
engine/multistatenpvcalculator.cpp
@@ -71,6 +73,7 @@ engine/sensitivityreportstream.cpp
7173
engine/stresstest.cpp
7274
engine/valuationcalculator.cpp
7375
engine/valuationengine.cpp
76+
engine/varbacktest.cpp
7477
engine/varcalculator.cpp
7578
engine/xvaenginecg.cpp
7679
engine/zerotoparcube.cpp
@@ -101,6 +104,8 @@ scenario/stressscenariogenerator.cpp
101104
simm/crif.cpp
102105
simm/crifloader.cpp
103106
simm/crifrecord.cpp
107+
simm/imschedulecalculator.cpp
108+
simm/imscheduleresults.cpp
104109
simm/simmbasicnamemapper.cpp
105110
simm/simmbucketmapperbase.cpp
106111
simm/simmcalculator.cpp
@@ -155,6 +160,7 @@ aggregation/postprocess.hpp
155160
aggregation/staticcreditxvacalculator.hpp
156161
aggregation/xvacalculator.hpp
157162
app/analytic.hpp
163+
app/analytics/imscheduleanalytic.hpp
158164
app/analytics/parconversionanalytic.hpp
159165
app/analytics/pricinganalytic.hpp
160166
app/analytics/scenarioanalytic.hpp
@@ -198,6 +204,7 @@ engine/filteredsensitivitystream.hpp
198204
engine/historicalpnlgenerator.hpp
199205
engine/historicalsensipnlcalculator.hpp
200206
engine/historicalsimulationvar.hpp
207+
engine/marketriskbacktest.hpp
201208
engine/marketriskreport.hpp
202209
engine/mporcalculator.hpp
203210
engine/multistatenpvcalculator.hpp
@@ -219,6 +226,7 @@ engine/sensitivitystream.hpp
219226
engine/stresstest.hpp
220227
engine/valuationcalculator.hpp
221228
engine/valuationengine.hpp
229+
engine/varbacktest.hpp
222230
engine/varcalculator.hpp
223231
engine/xvaenginecg.hpp
224232
engine/zerotoparcube.hpp
@@ -255,6 +263,8 @@ scenario/stressscenariogenerator.hpp
255263
simm/crif.hpp
256264
simm/crifloader.hpp
257265
simm/crifrecord.hpp
266+
simm/imschedulecalculator.hpp
267+
simm/imscheduleresults.hpp
258268
simm/simmbasicnamemapper.hpp
259269
simm/simmbucketmapper.hpp
260270
simm/simmbucketmapperbase.hpp

OREAnalytics/orea/app/analytic.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <orea/aggregation/dimregressioncalculator.hpp>
3131

3232
#include <ored/marketdata/todaysmarket.hpp>
33+
#include <ored/marketdata/bondspreadimply.hpp>
3334
#include <ored/portfolio/builders/currencyswap.hpp>
3435
#include <ored/portfolio/builders/fxoption.hpp>
3536
#include <ored/portfolio/builders/multilegoption.hpp>
@@ -242,5 +243,28 @@ void MarketDataAnalyticImpl::runAnalytic(
242243
CONSOLE("OK");
243244
}
244245

246+
boost::shared_ptr<Loader> implyBondSpreads(const Date& asof,
247+
const boost::shared_ptr<ore::analytics::InputParameters>& params,
248+
const boost::shared_ptr<TodaysMarketParameters>& todaysMarketParams,
249+
const boost::shared_ptr<Loader>& loader,
250+
const boost::shared_ptr<CurveConfigurations>& curveConfigs,
251+
const std::string& excludeRegex) {
252+
253+
auto securities = BondSpreadImply::requiredSecurities(asof, todaysMarketParams, curveConfigs, *loader,
254+
true, excludeRegex);
255+
256+
if (!securities.empty()) {
257+
// always continue on error and always use lazy market building
258+
boost::shared_ptr<Market> market =
259+
boost::make_shared<TodaysMarket>(asof, todaysMarketParams, loader, curveConfigs, true, true, true,
260+
params->refDataManager(), false, *params->iborFallbackConfig());
261+
return BondSpreadImply::implyBondSpreads(securities, params->refDataManager(), market, params->pricingEngine(),
262+
Market::defaultConfiguration, *params->iborFallbackConfig());
263+
} else {
264+
// no bonds that require a spread imply => return null ptr
265+
return boost::shared_ptr<Loader>();
266+
}
267+
}
268+
245269
} // namespace analytics
246270
} // namespace ore

OREAnalytics/orea/app/analytic.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,12 @@ template <class T> inline QuantLib::ext::shared_ptr<T> Analytic::dependentAnalyt
241241
return analytic;
242242
}
243243

244+
boost::shared_ptr<ore::data::Loader> implyBondSpreads(const Date& asof,
245+
const boost::shared_ptr<InputParameters>& params,
246+
const boost::shared_ptr<ore::data::TodaysMarketParameters>& todaysMarketParams,
247+
const boost::shared_ptr<ore::data::Loader>& loader,
248+
const boost::shared_ptr<ore::data::CurveConfigurations>& curveConfigs,
249+
const std::string& excludeRegex);
250+
244251
} // namespace analytics
245252
} // namespace oreplus

0 commit comments

Comments
 (0)