-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demos to PDF documentation of QMCPy.
- Loading branch information
Showing
20 changed files
with
5,311 additions
and
68,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
Demos | ||
===== | ||
|
||
QMCPy Intro | ||
------------ | ||
.. raw:: html | ||
:file: html_from_demos/qmcpy_intro.html | ||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
Integration Examples | ||
-------------------- | ||
.. raw:: html | ||
:file: html_from_demos/integration_examples.html | ||
rst_from_demos/qmcpy_intro.rst | ||
|
||
Sampling Points Visualization | ||
----------------------------- | ||
.. raw:: html | ||
:file: html_from_demos/sample_scatter_plots.html | ||
rst_from_demos/integration_examples.rst | ||
|
||
MC and QMC Comparison | ||
--------------------- | ||
.. raw:: html | ||
:file: html_from_demos/MC_vs_QMC.html | ||
rst_from_demos/sample_scatter_plots.rst | ||
|
||
Quasi-Random Sequence Generators | ||
-------------------------------- | ||
.. raw:: html | ||
:file: html_from_demos/quasirandom_generators.html | ||
rst_from_demos/MC_vs_QMC.rst | ||
|
||
rst_from_demos/quasirandom_generators.rst |
Large diffs are not rendered by default.
Oops, something went wrong.
194 changes: 194 additions & 0 deletions
194
docs/_sources/rst_from_demos/integration_examples.rst.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
Integration Examples using QMCPy package | ||
======================================== | ||
|
||
.. code:: ipython3 | ||
from qmcpy import * | ||
from numpy import arange | ||
Keister Example | ||
--------------- | ||
|
||
Keister Integrand: - :math:`y_i = \pi^{d/2} * \cos(||x_i||_2)` | ||
|
||
Gaussian True Measure: - :math:`\mathcal{N}(0,\frac{1}{2})` | ||
|
||
Sobol Discrete Distribution: - | ||
:math:`x_j \overset{lds}{\sim} \mathcal{U}(0,1)` | ||
|
||
.. code:: ipython3 | ||
dim = 3 | ||
integrand = Keister(dim) | ||
discrete_distrib = Sobol(rng_seed=7) | ||
true_measure = Gaussian(dim, variance=1 / 2) | ||
stopping_criterion = CLTRep(discrete_distrib, true_measure, abs_tol=.05) | ||
_, data = integrate(integrand, true_measure, discrete_distrib, stopping_criterion) | ||
print(data) | ||
.. parsed-literal:: | ||
Solution: 2.1716 | ||
Keister (Integrand Object) | ||
Sobol (Discrete Distribution Object) | ||
mimics StdUniform | ||
rng_seed 7 | ||
backend pytorch | ||
Gaussian (True Measure Object) | ||
dimension 3 | ||
mu 0 | ||
sigma 0.707 | ||
CLTRep (Stopping Criterion Object) | ||
abs_tol 0.050 | ||
rel_tol 0 | ||
n_max 1073741824 | ||
inflate 1.200 | ||
alpha 0.010 | ||
MeanVarDataRep (AccumData Object) | ||
n 128 | ||
n_total 128 | ||
confid_int [ 2.164 2.179] | ||
time_total 0.008 | ||
r 16 | ||
Asian Option Pricing Example | ||
---------------------------- | ||
|
||
Single Level | ||
~~~~~~~~~~~~ | ||
|
||
Asian Call Option Integrand - | ||
:math:`S_i(t_j)=S(0)e^{(r-\frac{\sigma^2}{2})t_j+\sigma\mathcal{B}(t_j)}` | ||
- discounted put payoff | ||
:math:`= max(K-\frac{1}{d}\sum_{j=0}^{d-1} S(jT/d))\;,\: 0)` | ||
|
||
Brownian Motion True Measure: - | ||
:math:`\:\: \mathcal{B}(t_j)=B(t_{j-1})+Z_j\sqrt{t_j-t_{j-1}} \;` for | ||
:math:`\;Z_j \sim \mathcal{N}(0,1)` | ||
|
||
Lattice Discrete Distribution: - | ||
:math:`\:\: x_j \overset{lds}{\sim} \mathcal{U}(0,1)` | ||
|
||
.. code:: ipython3 | ||
time_vec = [arange(1 / 64, 65 / 64, 1 / 64)] | ||
dim = [len(tv) for tv in time_vec] | ||
discrete_distrib = Lattice(rng_seed=7) | ||
true_measure = BrownianMotion(dim, time_vector=time_vec) | ||
integrand = AsianCall(true_measure, | ||
volatility = .5, | ||
start_price = 30, | ||
strike_price = 25, | ||
interest_rate = .01, | ||
mean_type = 'geometric') | ||
stopping_criterion = CLTRep(discrete_distrib, true_measure, abs_tol=.05) | ||
_, data = integrate(integrand, true_measure, discrete_distrib, stopping_criterion) | ||
print(data) | ||
.. parsed-literal:: | ||
Solution: 5.8356 | ||
AsianCall (Integrand Object) | ||
volatility 0.500 | ||
start_price 30 | ||
strike_price 25 | ||
interest_rate 0.010 | ||
mean_type geometric | ||
exercise_time 1 | ||
Lattice (Discrete Distribution Object) | ||
mimics StdUniform | ||
rng_seed 7 | ||
BrownianMotion (True Measure Object) | ||
dimension 64 | ||
time_vector [ 0.016 0.031 0.047 ... 0.969 0.984 1.000] | ||
CLTRep (Stopping Criterion Object) | ||
abs_tol 0.050 | ||
rel_tol 0 | ||
n_max 1073741824 | ||
inflate 1.200 | ||
alpha 0.010 | ||
MeanVarDataRep (AccumData Object) | ||
n 2048 | ||
n_total 2048 | ||
confid_int [ 5.833 5.838] | ||
time_total 0.434 | ||
r 16 | ||
Asian Option Pricing Example | ||
---------------------------- | ||
|
||
Multi-Level | ||
~~~~~~~~~~~ | ||
|
||
:math:`Y_0 = 0` | ||
|
||
:math:`Y_1` = Asian Option Monitored at | ||
:math:`t=[\frac{1}{4}, \frac{1}{2}, \frac{3}{4}, 1]` | ||
|
||
:math:`Y_2` = Asian Option Monitored at | ||
:math:`t=[\frac{1}{16}, \frac{1}{8}, ... , 1]` | ||
|
||
:math:`Y_3` = Asian Option Monitored at | ||
:math:`t=[\frac{1}{64}, \frac{1}{32}, ... , 1]` | ||
|
||
:math:`Z_1 = \mathbb{E}[Y_1-Y_0] + \mathbb{E}[Y_2-Y_1] + \mathbb{E}[Y_3-Y_2] = \mathbb{E}[Y_3]` | ||
|
||
.. code:: ipython3 | ||
time_vec = [arange(1 / 4, 5 / 4, 1 / 4), | ||
arange(1 / 16, 17 / 16, 1 / 16), | ||
arange(1 / 64, 65 / 64, 1 / 64)] | ||
dim = [len(tv) for tv in time_vec] | ||
discrete_distrib = IIDStdGaussian(rng_seed=7) | ||
true_measure = BrownianMotion(dim, time_vector=time_vec) | ||
integrand = AsianCall(true_measure, | ||
volatility = .5, | ||
start_price = 30, | ||
strike_price = 25, | ||
interest_rate = .01, | ||
mean_type = 'geometric') | ||
stopping_criterion = CLT(discrete_distrib, true_measure, abs_tol=.05, n_max = 1e10) | ||
_, data = integrate(integrand, true_measure, discrete_distrib, stopping_criterion) | ||
print(data) | ||
.. parsed-literal:: | ||
Solution: 5.8320 | ||
AsianCall (Integrand Object) | ||
volatility [ 0.500 0.500 0.500] | ||
start_price [30 30 30] | ||
strike_price [25 25 25] | ||
interest_rate [ 0.010 0.010 0.010] | ||
mean_type ['geometric' 'geometric' 'geometric'] | ||
exercise_time [ 1.000 1.000 1.000] | ||
IIDStdGaussian (Discrete Distribution Object) | ||
mimics StdGaussian | ||
BrownianMotion (True Measure Object) | ||
dimension [ 4 16 64] | ||
time_vector [array([ 0.250, 0.500, 0.750, 1.000]) | ||
array([ 0.062, 0.125, 0.188, ..., 0.875, 0.938, 1.000]) | ||
array([ 0.016, 0.031, 0.047, ..., 0.969, 0.984, 1.000])] | ||
CLT (Stopping Criterion Object) | ||
abs_tol 0.050 | ||
rel_tol 0 | ||
n_max 10000000000 | ||
inflate 1.200 | ||
alpha 0.010 | ||
MeanVarData (AccumData Object) | ||
n [ 249322.000 31697.000 5429.000] | ||
n_total 289520 | ||
confid_int [ 5.783 5.881] | ||
time_total 0.119 | ||
Oops, something went wrong.