Skip to content

Commit 1fe8315

Browse files
rolandlichtersjenkins
authored andcommitted
add example 42
1 parent 4cb3f88 commit 1fe8315

10 files changed

Lines changed: 757 additions & 2 deletions

File tree

Docs/UserGuide/userguide.tex

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ \subsection{Building ORE-SWIG}\label{sec:oreswig}
929929

930930
\end{enumerate}
931931

932-
\subsection{How to build ORE Python Wheels on Windows}
932+
\subsection{How to build ORE Python Wheels on Windows}\label{sec:win_wheel}
933933

934934
This section is a stand-alone HOWTO for building ore and oreswig, including Python wrappers and wheels, at the DOS command line using cmake and VS 2022.
935935

@@ -1028,7 +1028,7 @@ \subsubsection*{Build ORE-SWIG Wrapper and Wheel}
10281028
{\tt deactivate} \\
10291029
{\tt rmdir /s /q env1} \\
10301030

1031-
\subsection{How to build ORE Python Wheels on Linux and macOS}
1031+
\subsection{How to build ORE Python Wheels on Linux and macOS}\label{sec:nix_wheel}
10321032

10331033
This section is a stand-alone HOWTO for building and using a python wheel for OREAnalytics on Linux or macOS.
10341034

@@ -1240,6 +1240,8 @@ \section{Examples}\label{sec:examples}
12401240
40 & Par Sensitivity Analysis \\
12411241
\hline
12421242
41 & Multi-threaded Exposure Simulation \\
1243+
\hline
1244+
42 & ORE Python Module \\
12431245
\end{tabular}
12441246
\caption{ORE examples.}
12451247
\label{tab_0}
@@ -3123,6 +3125,40 @@ \subsection{Multi-threaded Exposure Simultion}% Example 41
31233125
The example in folder {\tt Examples/Example\_41} demonstrates the multithreaded valuation engine to generate the exposure for a
31243126
portfolio of 8 copies of the vanilla swap in {\tt Example\_1}.
31253127

3128+
%--------------------------------------------------------------------
3129+
\subsection{ORE Python Module}% Example 42
3130+
\label{example:42}
3131+
%--------------------------------------------------------------------
3132+
3133+
Since release 9 (March 2023) we provide easy access to ORE via a pre-compiled Python module. Some example scripts using this ORE module are provided in this example, so change to this directory first
3134+
3135+
\medskip
3136+
{\tt cd Example\_42}
3137+
3138+
\medskip
3139+
The examples require Python 3, the actual ORE Python module is then installed with a one-liner, see below. However, to separate ORE from any other Python environments on your machine, we recommend creating a virtual environment first. In that case the steps are as follows:
3140+
3141+
\begin{itemize}
3142+
\item To create a virtual environment: {\tt python -m venv env1}
3143+
\item To activate this environment on Windows: {\tt .{\bs}env1{\bs}Scripts{\bs}activate.bat} \\
3144+
or on macOS/Linux: {\tt ./env1/bin/activate }
3145+
\item Then install ORE:\\
3146+
{\tt pip install open-source-risk-engine }
3147+
\item And try examples:\\
3148+
\begin{itemize}
3149+
\item {\tt python ore.py} \\
3150+
This demonstrates the Python-wrapped version of the ORE application that is also used in the command line application {\tt ore.exe}. We use it here to re-run the Swap exposure of {\tt Example\_1}.
3151+
\item {\tt python commodityforward.py} \\
3152+
The ORE Python module also allows lower-level access to the QuantLib and QuantExt libraries, demonstrated here for a CommodityForward instrument defined QuantExt.
3153+
\end{itemize}
3154+
More use cases of the ORE Python module, including Jupyter notebooks, can be found in the ORE SWIG repository, in particular in folder OREAnalytics-SWIG/Python/Examples.
3155+
\item Finally you can deactivate the environment:
3156+
{\tt deactivate} \\
3157+
or even fully remove the environment again by removing the {\tt env1} folder.
3158+
\end{itemize}
3159+
3160+
You can build the Python module and installable packages yourself following the instructions in sections \ref{sec:oreswig}, \ref{sec:win_wheel}, \ref{sec:nix_wheel}
3161+
based on your local ORE code. {\tt pip install open-source-risk-engine } will always provide the latest release.
31263162

31273163
\clearpage
31283164
%========================================================
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<CurrencyConfig>
2+
<!-- PGK -->
3+
<Currency>
4+
<Name>Papua New Guinean kina</Name>
5+
<ISOCode>PGK</ISOCode>
6+
<NumericCode>598</NumericCode>
7+
<Symbol>K</Symbol>
8+
<FractionSymbol></FractionSymbol>
9+
<!-- 1 kina = 100 toea -->
10+
<FractionsPerUnit>100</FractionsPerUnit>
11+
<RoundingType>Closest</RoundingType>
12+
<RoundingPrecision>2</RoundingPrecision>
13+
<Format>%3% %1$.2f</Format>
14+
</Currency>
15+
<!-- SOS -->
16+
<Currency>
17+
<Name>Somali shilling</Name>
18+
<ISOCode>SOS</ISOCode>
19+
<NumericCode>706</NumericCode>
20+
<Symbol>K</Symbol>
21+
<FractionSymbol></FractionSymbol>
22+
<!-- 1 shilling = 100 senti -->
23+
<FractionsPerUnit>100</FractionsPerUnit>
24+
<RoundingType>Closest</RoundingType>
25+
<RoundingPrecision>2</RoundingPrecision>
26+
<Format>%3% %1$.2f</Format>
27+
</Currency>
28+
</CurrencyConfig>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<NettingSetDefinitions>
3+
<NettingSet>
4+
<NettingSetId>CPTY_A</NettingSetId>
5+
<ActiveCSAFlag>false</ActiveCSAFlag>
6+
<CSADetails>
7+
<Bilateral>Bilateral</Bilateral>
8+
<CSACurrency>EUR</CSACurrency>
9+
<Index>EUR-EONIA</Index>
10+
<ThresholdPay>100000</ThresholdPay>
11+
<ThresholdReceive>100000</ThresholdReceive>
12+
<MinimumTransferAmountPay>0</MinimumTransferAmountPay>
13+
<MinimumTransferAmountReceive>0</MinimumTransferAmountReceive>
14+
<IndependentAmount>
15+
<IndependentAmountHeld>0</IndependentAmountHeld>
16+
<IndependentAmountType>FIXED</IndependentAmountType>
17+
</IndependentAmount>
18+
<MarginingFrequency>
19+
<CallFrequency>1D</CallFrequency>
20+
<PostFrequency>1D</PostFrequency>
21+
</MarginingFrequency>
22+
<MarginPeriodOfRisk>0W</MarginPeriodOfRisk>
23+
<CollateralCompoundingSpreadReceive>0.00</CollateralCompoundingSpreadReceive>
24+
<CollateralCompoundingSpreadPay>0.00</CollateralCompoundingSpreadPay>
25+
<EligibleCollaterals>
26+
<Currencies>
27+
<Currency>EUR</Currency>
28+
</Currencies>
29+
</EligibleCollaterals>
30+
</CSADetails>
31+
</NettingSet>
32+
</NettingSetDefinitions>

Examples/Example_42/Input/ore.xml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0"?>
2+
<ORE>
3+
<Setup>
4+
<Parameter name="asofDate">2016-02-05</Parameter>
5+
<Parameter name="inputPath">Input</Parameter>
6+
<Parameter name="outputPath">Output</Parameter>
7+
<Parameter name="logFile">log.txt</Parameter>
8+
<Parameter name="logMask">31</Parameter>
9+
<Parameter name="marketDataFile">../../Input/market_20160205_flat.txt</Parameter>
10+
<Parameter name="fixingDataFile">../../Input/fixings_20160205.txt</Parameter>
11+
<Parameter name="implyTodaysFixings">Y</Parameter>
12+
<Parameter name="curveConfigFile">../../Input/curveconfig.xml</Parameter>
13+
<Parameter name="conventionsFile">../../Input/conventions.xml</Parameter>
14+
<Parameter name="marketConfigFile">../../Input/todaysmarket.xml</Parameter>
15+
<Parameter name="pricingEnginesFile">../../Input/pricingengine.xml</Parameter>
16+
<Parameter name="portfolioFile">portfolio_swap.xml</Parameter>
17+
<Parameter name="observationModel">None</Parameter>
18+
<Parameter name="continueOnError">false</Parameter>
19+
<Parameter name="calendarAdjustment">../../Input/calendaradjustment.xml</Parameter>
20+
<Parameter name="currencyConfiguration">../../Input/currencies.xml</Parameter>
21+
</Setup>
22+
<Markets>
23+
<Parameter name="lgmcalibration">libor</Parameter>
24+
<Parameter name="fxcalibration">libor</Parameter>
25+
<Parameter name="eqcalibration">libor</Parameter>
26+
<Parameter name="pricing">libor</Parameter>
27+
<Parameter name="simulation">libor</Parameter>
28+
</Markets>
29+
<Analytics>
30+
<Analytic type="npv">
31+
<Parameter name="active">Y</Parameter>
32+
<Parameter name="baseCurrency">EUR</Parameter>
33+
<Parameter name="outputFileName">npv.csv</Parameter>
34+
<Parameter name="additionalResults">Y</Parameter>
35+
</Analytic>
36+
<Analytic type="cashflow">
37+
<Parameter name="active">Y</Parameter>
38+
<Parameter name="outputFileName">flows.csv</Parameter>
39+
</Analytic>
40+
<Analytic type="curves">
41+
<Parameter name="active">Y</Parameter>
42+
<Parameter name="configuration">default</Parameter>
43+
<Parameter name="grid">240,1M</Parameter>
44+
<Parameter name="outputFileName">curves.csv</Parameter>
45+
<Parameter name="outputTodaysMarketCalibration">Y</Parameter>
46+
</Analytic>
47+
<Analytic type="simulation">
48+
<Parameter name="active">Y</Parameter>
49+
<Parameter name="simulationConfigFile">simulation.xml</Parameter>
50+
<Parameter name="pricingEnginesFile">../../Input/pricingengine.xml</Parameter>
51+
<Parameter name="baseCurrency">EUR</Parameter>
52+
<Parameter name="observationModel">Disable</Parameter>
53+
<!-- Parameter name="scenariodump">scenariodump.csv</Parameter> -->
54+
<Parameter name="cubeFile">cube.csv.gz</Parameter>
55+
<Parameter name="aggregationScenarioDataFileName">scenariodata.csv.gz</Parameter>
56+
</Analytic>
57+
<Analytic type="xva">
58+
<Parameter name="active">Y</Parameter>
59+
<Parameter name="useXvaRunner">N</Parameter>
60+
<Parameter name="csaFile">netting.xml</Parameter>
61+
<Parameter name="cubeFile">cube.csv.gz</Parameter>
62+
<Parameter name="scenarioFile">scenariodata.csv.gz</Parameter>
63+
<Parameter name="baseCurrency">EUR</Parameter>
64+
<Parameter name="exposureProfiles">Y</Parameter>
65+
<Parameter name="exposureProfilesByTrade">Y</Parameter>
66+
<Parameter name="quantile">0.95</Parameter>
67+
<Parameter name="calculationType">Symmetric</Parameter>
68+
<Parameter name="allocationMethod">None</Parameter>
69+
<Parameter name="marginalAllocationLimit">1.0</Parameter>
70+
<Parameter name="exerciseNextBreak">N</Parameter>
71+
<Parameter name="cva">Y</Parameter>
72+
<Parameter name="dva">N</Parameter>
73+
<Parameter name="dvaName">BANK</Parameter>
74+
<Parameter name="fva">N</Parameter>
75+
<Parameter name="fvaBorrowingCurve">BANK_EUR_BORROW</Parameter>
76+
<Parameter name="fvaLendingCurve">BANK_EUR_LEND</Parameter>
77+
<Parameter name="colva">N</Parameter>
78+
<Parameter name="collateralFloor">N</Parameter>
79+
<Parameter name="rawCubeOutputFile">rawcube.csv</Parameter>
80+
<Parameter name="netCubeOutputFile">netcube.csv</Parameter>
81+
</Analytic>
82+
<Analytic type="initialMargin">
83+
<Parameter name="active">N</Parameter>
84+
<Parameter name="method"/>
85+
</Analytic>
86+
</Analytics>
87+
</ORE>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0"?>
2+
<Portfolio>
3+
<Trade id="Swap_20y">
4+
<TradeType>Swap</TradeType>
5+
<Envelope>
6+
<CounterParty>CPTY_A</CounterParty>
7+
<NettingSetId>CPTY_A</NettingSetId>
8+
<AdditionalFields/>
9+
</Envelope>
10+
<SwapData>
11+
<LegData>
12+
<LegType>Fixed</LegType>
13+
<Payer>false</Payer>
14+
<Currency>EUR</Currency>
15+
<Notionals>
16+
<Notional>10000000.000000</Notional>
17+
</Notionals>
18+
<DayCounter>30/360</DayCounter>
19+
<PaymentConvention>F</PaymentConvention>
20+
<FixedLegData>
21+
<Rates>
22+
<Rate>0.02</Rate>
23+
</Rates>
24+
</FixedLegData>
25+
<ScheduleData>
26+
<Rules>
27+
<StartDate>20160301</StartDate>
28+
<EndDate>20360301</EndDate>
29+
<Tenor>1Y</Tenor>
30+
<Calendar>TARGET</Calendar>
31+
<Convention>F</Convention>
32+
<TermConvention>F</TermConvention>
33+
<Rule>Forward</Rule>
34+
<EndOfMonth/>
35+
<FirstDate/>
36+
<LastDate/>
37+
</Rules>
38+
</ScheduleData>
39+
</LegData>
40+
<LegData>
41+
<LegType>Floating</LegType>
42+
<Payer>true</Payer>
43+
<Currency>EUR</Currency>
44+
<Notionals>
45+
<Notional>10000000.000000</Notional>
46+
</Notionals>
47+
<DayCounter>A360</DayCounter>
48+
<PaymentConvention>MF</PaymentConvention>
49+
<FloatingLegData>
50+
<Index>EUR-EURIBOR-6M</Index>
51+
<Spreads>
52+
<Spread>0.000000</Spread>
53+
</Spreads>
54+
<IsInArrears>false</IsInArrears>
55+
<FixingDays>2</FixingDays>
56+
</FloatingLegData>
57+
<ScheduleData>
58+
<Rules>
59+
<StartDate>20160301</StartDate>
60+
<EndDate>20360301</EndDate>
61+
<Tenor>6M</Tenor>
62+
<Calendar>TARGET</Calendar>
63+
<Convention>MF</Convention>
64+
<TermConvention>MF</TermConvention>
65+
<Rule>Forward</Rule>
66+
<EndOfMonth/>
67+
<FirstDate/>
68+
<LastDate/>
69+
</Rules>
70+
</ScheduleData>
71+
</LegData>
72+
</SwapData>
73+
</Trade>
74+
</Portfolio>

0 commit comments

Comments
 (0)