Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ZigguratGaussianRng<RNG> #1981

Merged
merged 21 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
460a748
Removed workflows for the time being to reduce the amount of builds
ralfkonrad Apr 23, 2024
4adf430
Adding skeleton for ZigguratGaussianRng
ralfkonrad Apr 23, 2024
6796fda
Working on the implementation
ralfkonrad Apr 23, 2024
12a8c3f
Removed more workflow jobs to reduce workload
ralfkonrad Apr 23, 2024
17793a1
Removed ZigguratGaussianRngUtils and moved its functionality to Ziggu…
Apr 25, 2024
05ccdef
Removed nested Utils class
ralfkonrad May 2, 2024
bd19f1c
First working Gaussian RNG, still needs to be tested
ralfkonrad May 3, 2024
9b7f14b
Included <cstdint>
ralfkonrad May 4, 2024
84ee49e
nextReal() instead of nextInt64(), plus removed unused exp.(...) parts
ralfkonrad May 6, 2024
1cc5f9d
Calculating mean, variance, skewness and kurtosis via boost::accumula…
ralfkonrad May 7, 2024
11f5816
Merge remote-tracking branch 'origin/master' into feature/ZigguratGau…
ralfkonrad May 28, 2024
7976d34
Fixed bug std::fabs(u) < normX(i + 1) to std::fabs(x) < normX(i + 1) …
ralfkonrad May 28, 2024
a15b6d4
Fixed formatting in CMakeLists.txt
ralfkonrad May 28, 2024
c9ffd85
Re-enable all workflows
ralfkonrad May 28, 2024
301ab53
Added zigguratgaussianrng.hpp to Makefile build
ralfkonrad May 28, 2024
e0ed843
Added new files to VS projects
ralfkonrad May 28, 2024
41cf960
Added zigguratgaussian.cpp to testsuite/Makefile.am
ralfkonrad May 28, 2024
c1e5c0b
Using IncrementalStatistics instead of boost::accumulators
ralfkonrad May 28, 2024
49cefdf
Renaming to testStatisticsOfNextReal
ralfkonrad May 28, 2024
c9d895d
Merge branch 'master' of https://github.com/lballabio/QuantLib into f…
ralfkonrad May 28, 2024
a4d5392
Minor refactorings
ralfkonrad May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions QuantLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@
<ClInclude Include="ql\math\randomnumbers\sobolrsg.hpp" />
<ClInclude Include="ql\math\randomnumbers\stochasticcollocationinvcdf.hpp" />
<ClInclude Include="ql\math\randomnumbers\xoshiro256starstaruniformrng.hpp" />
<ClInclude Include="ql\math\randomnumbers\zigguratgaussianrng.hpp" />
<ClInclude Include="ql\math\richardsonextrapolation.hpp" />
<ClInclude Include="ql\math\rounding.hpp" />
<ClInclude Include="ql\math\sampledcurve.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions QuantLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,9 @@
<ClInclude Include="ql\math\randomnumbers\xoshiro256starstaruniformrng.hpp">
<Filter>math\randomnumbers</Filter>
</ClInclude>
<ClInclude Include="ql\math\randomnumbers\zigguratgaussianrng.hpp">
<Filter>math\randomnumbers</Filter>
</ClInclude>
<ClInclude Include="ql\math\solvers1d\all.hpp">
<Filter>math\solvers1D</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions ql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ set(QL_HEADERS
math/randomnumbers/sobolrsg.hpp
math/randomnumbers/stochasticcollocationinvcdf.hpp
math/randomnumbers/xoshiro256starstaruniformrng.hpp
math/randomnumbers/zigguratgaussianrng.hpp
math/richardsonextrapolation.hpp
math/rounding.hpp
math/sampledcurve.hpp
Expand Down
3 changes: 2 additions & 1 deletion ql/math/randomnumbers/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ this_include_HEADERS = \
sobolbrownianbridgersg.hpp \
sobolrsg.hpp \
stochasticcollocationinvcdf.hpp \
xoshiro256starstaruniformrng.hpp
xoshiro256starstaruniformrng.hpp \
zigguratgaussianrng.hpp

cpp_files = \
faurersg.cpp \
Expand Down
1 change: 1 addition & 0 deletions ql/math/randomnumbers/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
#include <ql/math/randomnumbers/sobolrsg.hpp>
#include <ql/math/randomnumbers/stochasticcollocationinvcdf.hpp>
#include <ql/math/randomnumbers/xoshiro256starstaruniformrng.hpp>
#include <ql/math/randomnumbers/zigguratgaussianrng.hpp>

277 changes: 277 additions & 0 deletions ql/math/randomnumbers/zigguratgaussianrng.hpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ set(QL_TEST_SOURCES
xoshiro256starstar.cpp
zabr.cpp
zerocouponswap.cpp
zigguratgaussian.cpp
)

set(QL_TEST_HEADERS
Expand Down
3 changes: 2 additions & 1 deletion test-suite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ QL_TEST_SRCS = \
vpp.cpp \
xoshiro256starstar.cpp \
zabr.cpp \
zerocouponswap.cpp
zerocouponswap.cpp \
zigguratgaussian.cpp


QL_TEST_HDRS = \
Expand Down
1 change: 1 addition & 0 deletions test-suite/testsuite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@
<ClCompile Include="xoshiro256starstar.cpp" />
<ClCompile Include="zabr.cpp" />
<ClCompile Include="zerocouponswap.cpp" />
<ClCompile Include="zigguratgaussian.cpp" />
<ClCompile Include="quantlibtestsuite.cpp">
<IncludeInUnityFile>false</IncludeInUnityFile>
</ClCompile>
Expand Down
3 changes: 3 additions & 0 deletions test-suite/testsuite.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@
<ClCompile Include="xoshiro256starstar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="zigguratgaussian.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="quantlibtestsuite.cpp" />
<ClCompile Include="binaryoption.cpp">
<Filter>Source Files</Filter>
Expand Down
69 changes: 69 additions & 0 deletions test-suite/zigguratgaussian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
Copyright (C) 2024 Ralf Konrad Eckel

This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/

QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<[email protected]>. The license is also available online at
<http://quantlib.org/license.shtml>.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

#include "toplevelfixture.hpp"
#include <ql/math/randomnumbers/xoshiro256starstaruniformrng.hpp>
#include <ql/math/randomnumbers/zigguratgaussianrng.hpp>
#include <ql/math/statistics/incrementalstatistics.hpp>
#include <iostream>
#include <numeric>

using namespace QuantLib;

BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(ZigguratGaussianTests)

BOOST_AUTO_TEST_CASE(testStatisticsOfNextReal) {
BOOST_TEST_MESSAGE("Testing ZigguratGaussianRng<Xoshiro256StarStarUniformRng>::nextReal() for "
"mean, variance, skewness and kurtosis...");
auto seed = 42UL;
auto uniformRandom = Xoshiro256StarStarUniformRng(seed);
auto random = ZigguratGaussianRng<Xoshiro256StarStarUniformRng>(uniformRandom);

auto randoms = IncrementalStatistics();

auto iterations = 10'000'000;
for (auto j = 0; j < iterations; ++j) {
Real next = random.next().value;
randoms.add(next);
}

auto mean = randoms.mean();
auto variance = randoms.variance();
auto skewness = randoms.skewness();
auto kurtosis = randoms.kurtosis();

if (std::abs(mean) > 0.001) {
BOOST_ERROR("Mean " << mean << " for seed " << seed << " is not close to 0.");
}
if (std::abs(1.0 - variance) > 0.005) {
BOOST_ERROR("Variance " << variance << " for seed " << seed << " is not close to 1.");
}
if (std::abs(skewness) > 0.001) {
BOOST_ERROR("Skewness " << skewness << " for seed " << seed << " is not close to 0.");
}
if (std::abs(kurtosis) > 0.03) {
BOOST_ERROR("Kurtosis " << kurtosis << " for seed " << seed << " is not close to 0.");
}
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
Loading