Skip to content

Commit 6223239

Browse files
Roland Lichtersjenkins
authored andcommitted
QPR-12455 clean notebook
1 parent 9d7bbd8 commit 6223239

1 file changed

Lines changed: 84 additions & 54 deletions

File tree

Examples/Example_62/ore.ipynb

Lines changed: 84 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
}
8787
},
8888
"source": [
89-
"## Run ORE \"Classic\", Bump Sensitivities, Single-Threaded"
89+
"## Run ORE, Bump & Reval Sensitivities, Single-Threaded"
9090
]
9191
},
9292
{
@@ -130,49 +130,6 @@
130130
"#utilities.writeList(ore.getReportNames())"
131131
]
132132
},
133-
{
134-
"cell_type": "markdown",
135-
"metadata": {},
136-
"source": [
137-
"## Run Again with ComputationGraph Enabled"
138-
]
139-
},
140-
{
141-
"cell_type": "code",
142-
"execution_count": null,
143-
"metadata": {},
144-
"outputs": [],
145-
"source": [
146-
"params_cg = Parameters()\n",
147-
"params_cg.fromFile(\"Input/ore_cg.xml\")\n",
148-
"ore_cg = OREApp(params_cg)\n",
149-
"ore_cg.run()\n",
150-
"utilities.checkErrorsAndRunTime(ore_cg)\n",
151-
"#utilities.writeList(ore_bump.getReportNames())"
152-
]
153-
},
154-
{
155-
"cell_type": "code",
156-
"execution_count": null,
157-
"metadata": {},
158-
"outputs": [],
159-
"source": [
160-
"# Compare Pricing Stats\n",
161-
"utilities.match_pricingstats_12(ore, ore_cg, \"Speedup\", True)"
162-
]
163-
},
164-
{
165-
"cell_type": "code",
166-
"execution_count": null,
167-
"metadata": {},
168-
"outputs": [],
169-
"source": [
170-
"# Compare Sensitivities\n",
171-
"# If we set pricing engine's ExternalDeviceCompatibilityMode to false, then get zero deviations from the reference run above\n",
172-
"# if we set ExternalDeviceCompatibilityMode to true, then we see differences below due to different ordering of random variates in both runs\n",
173-
"utilities.match_sensi_reports(ore, ore_cg, \"DeltaBump\", \"DeltaCG\", False)"
174-
]
175-
},
176133
{
177134
"cell_type": "markdown",
178135
"metadata": {
@@ -195,7 +152,13 @@
195152
}
196153
},
197154
"source": [
198-
"## Run Again using AAD"
155+
"## Run ORE using AAD\n",
156+
"\n",
157+
"Check the following is set in **pricingengine_ad.xml**\n",
158+
"- **UseAD** is set to true\n",
159+
"\n",
160+
"Check the following is set in **sensitivity.xml**\n",
161+
"- **ComputeGamma** is set to false: otherwise AD is deactivated, because it does not support gamma and cross gamma calculation so far\n"
199162
]
200163
},
201164
{
@@ -239,7 +202,7 @@
239202
"outputs": [],
240203
"source": [
241204
"# Compare Pricing Stats\n",
242-
"utilities.match_pricingstats_12(ore, ore_ad, \"Speedup\", False)"
205+
"utilities.match_pricingstats_12(ore, ore_ad, \"Speedup\", True)"
243206
]
244207
},
245208
{
@@ -271,34 +234,101 @@
271234
"cell_type": "markdown",
272235
"metadata": {},
273236
"source": [
274-
"## Discussion\n",
275-
"Impact of:\n",
237+
"### Discussion\n",
276238
"- Shift Scheme (EQ Spot)\n",
277239
"- Shift Size (Vega)\n",
278240
"- Lowering the BarrierLevel in EquityBarrierOption\n",
279241
"- Lowering the KnockOutLevel in EquityAccumulator\n",
280242
"- Lowering the KnockOutProfitAmount in FxTARF, introducing varying range strikes or leverages\n",
243+
"- Todo: Add CAM"
244+
]
245+
},
246+
{
247+
"cell_type": "markdown",
248+
"metadata": {},
249+
"source": [
250+
"# Sensitivities: CPU vs GPU"
251+
]
252+
},
253+
{
254+
"cell_type": "markdown",
255+
"metadata": {},
256+
"source": [
257+
"## Run with ComputationGraph Enabled\n",
258+
"\n",
259+
"Check the following is set in **pricingengine_cg.xml**.\n",
260+
"- **UseCG** is set to true\n",
261+
"- **ExternalDeviceCompatibilityMode** is set to true\n",
262+
"\n",
263+
"The latter ensures that we use the same ordering of random variables here and in the subsequent runs using external devices."
264+
]
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"metadata": {},
270+
"outputs": [],
271+
"source": [
272+
"params_cg = Parameters()\n",
273+
"params_cg.fromFile(\"Input/ore_cg.xml\")\n",
274+
"ore_cg = OREApp(params_cg)\n",
275+
"ore_cg.run()\n",
276+
"utilities.checkErrorsAndRunTime(ore_cg)\n",
277+
"#utilities.writeList(ore_bump.getReportNames())"
278+
]
279+
},
280+
{
281+
"cell_type": "code",
282+
"execution_count": null,
283+
"metadata": {},
284+
"outputs": [],
285+
"source": [
286+
"# Compare Pricing Stats\n",
287+
"utilities.match_pricingstats_12(ore, ore_cg, \"Speedup\", False)"
288+
]
289+
},
290+
{
291+
"cell_type": "markdown",
292+
"metadata": {},
293+
"source": [
294+
"### Compare Sensitivities\n",
281295
"\n",
282-
"Todo:\n",
283-
"- Add CAM"
296+
"If we set pricing engine's ExternalDeviceCompatibilityMode to false here, then we should see zero deviations from the reference run above\n",
297+
"\n",
298+
"If we set ExternalDeviceCompatibilityMode to true though, then we see differences below due to different ordering of random variates in both runs,\n",
299+
"However, this means we use the same ordering in the CG run as in the GPU run below.\n",
300+
"\n",
301+
"So if you want to check the former, the set ExternalDeviceCompatibilityMode=false first, rerun ore_cg and confirm perfect match of sensitivities."
302+
]
303+
},
304+
{
305+
"cell_type": "code",
306+
"execution_count": null,
307+
"metadata": {},
308+
"outputs": [],
309+
"source": [
310+
"# Compare Sensitivities: This run vs reference \n",
311+
"utilities.match_sensi_reports(ore, ore_cg, \"DeltaBump\", \"DeltaCG\", False)"
284312
]
285313
},
286314
{
287315
"cell_type": "markdown",
288316
"metadata": {},
289317
"source": [
290-
"# Run again using the external GPU device\n",
318+
"## Run again using the external GPU device\n",
291319
"\n",
292320
"Note that this functionality is work in progress.\n",
293321
"\n",
294-
"Using an external device requires another few changes in pricingengine.xml's EngineParameters section:\n",
322+
"Using an external device requires another few changes in **pricingengine_gpu.xml**'s EngineParameters section:\n",
295323
"- set **UseCG** to true\n",
296324
"- set **UseExternalComputeDevice** to true\n",
297-
"- set **ExternalComputeDevice** to the device name (**OpenCL/Apple/Apple M2 Max** on my machine, a **38 core GPU** device)\n",
325+
"- set **ExternalComputeDevice** to the device name, you can choose **BasicCpu/Default/Default** or (on my machine) **OpenCL/Apple/Apple M2 Max**\n",
298326
"\n",
299327
"Determine your available compute devices by running the QuantExt test suite with **quantext-test-suite --log_level=message --run_test=\"*/ComputeEnvironmentTest/testEnvironmentInit\"**\n",
300328
"\n",
301-
"You should also see the device name **BasicCpu/Default/Default** which is the CPU and can be used for testing."
329+
"**BasicCpu/Default/Default** refers to the CPU itself but treats it as an external device. This is useful for sanity checking the implementation - it should yield a perfect match in the sensitivity comparison below, but only moderate change in performance since we do not paralellize.\n",
330+
"\n",
331+
"**OpenCL/Apple/Apple M2 Max** is a **38 core GPU** device that should yield a noticeable performance improvement thanks to distributing the calculations across the GPU cores."
302332
]
303333
},
304334
{

0 commit comments

Comments
 (0)