📄 sobolrsg.cpp
字号:
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2003, 2004 Ferdinando Ametrano
Copyright (C) 2006 Richard Gould
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
<quantlib-dev@lists.sf.net>. 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 <ql/math/randomnumbers/sobolrsg.hpp>
#include <ql/math/randomnumbers/primitivepolynomials.h>
#include <ql/math/randomnumbers/mt19937uniformrng.hpp>
#include <ql/errors.hpp>
#include <cmath>
namespace QuantLib {
namespace {
/* Sobol' Levitan coefficients of the free direction integers as given
by Bratley, P., Fox, B.L. (1988)
*/
const unsigned long dim02SLinitializers[] = {
1UL, 0UL };
const unsigned long dim03SLinitializers[] = {
1UL, 1UL, 0UL };
const unsigned long dim04SLinitializers[] = {
1UL, 3UL, 7UL, 0UL };
const unsigned long dim05SLinitializers[] = {
1UL, 1UL, 5UL, 0UL };
const unsigned long dim06SLinitializers[] = {
1UL, 3UL, 1UL, 1UL, 0UL };
const unsigned long dim07SLinitializers[] = {
1UL, 1UL, 3UL, 7UL, 0UL };
const unsigned long dim08SLinitializers[] = {
1UL, 3UL, 3UL, 9UL, 9UL, 0UL };
const unsigned long dim09SLinitializers[] = {
1UL, 3UL, 7UL, 13UL, 3UL, 0UL };
const unsigned long dim10SLinitializers[] = {
1UL, 1UL, 5UL, 11UL, 27UL, 0UL };
const unsigned long dim11SLinitializers[] = {
1UL, 3UL, 5UL, 1UL, 15UL, 0UL };
const unsigned long dim12SLinitializers[] = {
1UL, 1UL, 7UL, 3UL, 29UL, 0UL };
const unsigned long dim13SLinitializers[] = {
1UL, 3UL, 7UL, 7UL, 21UL, 0UL };
const unsigned long dim14SLinitializers[] = {
1UL, 1UL, 1UL, 9UL, 23UL, 37UL, 0UL };
const unsigned long dim15SLinitializers[] = {
1UL, 3UL, 3UL, 5UL, 19UL, 33UL, 0UL };
const unsigned long dim16SLinitializers[] = {
1UL, 1UL, 3UL, 13UL, 11UL, 7UL, 0UL };
const unsigned long dim17SLinitializers[] = {
1UL, 1UL, 7UL, 13UL, 25UL, 5UL, 0UL };
const unsigned long dim18SLinitializers[] = {
1UL, 3UL, 5UL, 11UL, 7UL, 11UL, 0UL };
const unsigned long dim19SLinitializers[] = {
1UL, 1UL, 1UL, 3UL, 13UL, 39UL, 0UL };
const unsigned long dim20SLinitializers[] = {
1UL, 3UL, 1UL, 15UL, 17UL, 63UL, 13UL, 0UL };
const unsigned long dim21SLinitializers[] = {
1UL, 1UL, 5UL, 5UL, 1UL, 27UL, 33UL, 0UL };
const unsigned long dim22SLinitializers[] = {
1UL, 3UL, 3UL, 3UL, 25UL, 17UL, 115UL, 0UL };
const unsigned long dim23SLinitializers[] = {
1UL, 1UL, 3UL, 15UL, 29UL, 15UL, 41UL, 0UL };
const unsigned long dim24SLinitializers[] = {
1UL, 3UL, 1UL, 7UL, 3UL, 23UL, 79UL, 0UL };
const unsigned long dim25SLinitializers[] = {
1UL, 3UL, 7UL, 9UL, 31UL, 29UL, 17UL, 0UL };
const unsigned long dim26SLinitializers[] = {
1UL, 1UL, 5UL, 13UL, 11UL, 3UL, 29UL, 0UL };
const unsigned long dim27SLinitializers[] = {
1UL, 3UL, 1UL, 9UL, 5UL, 21UL, 119UL, 0UL };
const unsigned long dim28SLinitializers[] = {
1UL, 1UL, 3UL, 1UL, 23UL, 13UL, 75UL, 0UL };
const unsigned long dim29SLinitializers[] = {
1UL, 3UL, 3UL, 11UL, 27UL, 31UL, 73UL, 0UL };
const unsigned long dim30SLinitializers[] = {
1UL, 1UL, 7UL, 7UL, 19UL, 25UL, 105UL, 0UL };
const unsigned long dim31SLinitializers[] = {
1UL, 3UL, 5UL, 5UL, 21UL, 9UL, 7UL, 0UL };
const unsigned long dim32SLinitializers[] = {
1UL, 1UL, 1UL, 15UL, 5UL, 49UL, 59UL, 0UL };
const unsigned long dim33SLinitializers[] = {
1UL, 1UL, 1UL, 1UL, 1UL, 33UL, 65UL, 0UL };
const unsigned long dim34SLinitializers[] = {
1UL, 3UL, 5UL, 15UL, 17UL, 19UL, 21UL, 0UL };
const unsigned long dim35SLinitializers[] = {
1UL, 1UL, 7UL, 11UL, 13UL, 29UL, 3UL, 0UL };
const unsigned long dim36SLinitializers[] = {
1UL, 3UL, 7UL, 5UL, 7UL, 11UL, 113UL, 0UL };
const unsigned long dim37SLinitializers[] = {
1UL, 1UL, 5UL, 3UL, 15UL, 19UL, 61UL, 0UL };
const unsigned long dim38SLinitializers[] = {
1UL, 3UL, 1UL, 1UL, 9UL, 27UL, 89UL, 7UL, 0UL };
const unsigned long dim39SLinitializers[] = {
1UL, 1UL, 3UL, 7UL, 31UL, 15UL, 45UL, 23UL, 0UL };
const unsigned long dim40SLinitializers[] = {
1UL, 3UL, 3UL, 9UL, 9UL, 25UL, 107UL, 39UL, 0UL };
const unsigned long * const SLinitializers[39] = {
dim02SLinitializers,
dim03SLinitializers,
dim04SLinitializers,
dim05SLinitializers,
dim06SLinitializers,
dim07SLinitializers,
dim08SLinitializers,
dim09SLinitializers,
dim10SLinitializers,
dim11SLinitializers,
dim12SLinitializers,
dim13SLinitializers,
dim14SLinitializers,
dim15SLinitializers,
dim16SLinitializers,
dim17SLinitializers,
dim18SLinitializers,
dim19SLinitializers,
dim20SLinitializers,
dim21SLinitializers,
dim22SLinitializers,
dim23SLinitializers,
dim24SLinitializers,
dim25SLinitializers,
dim26SLinitializers,
dim27SLinitializers,
dim28SLinitializers,
dim29SLinitializers,
dim30SLinitializers,
dim31SLinitializers,
dim32SLinitializers,
dim33SLinitializers,
dim34SLinitializers,
dim35SLinitializers,
dim36SLinitializers,
dim37SLinitializers,
dim38SLinitializers,
dim39SLinitializers,
dim40SLinitializers
};
/* coefficients of the free direction integers as given in
"Monte Carlo Methods in Finance", by Peter J鋍kel, section 8.3
*/
const unsigned long dim09initializers[] = {
1UL, 3UL, 7UL, 7UL, 21UL, 0UL };
const unsigned long dim10initializers[] = {
1UL, 1UL, 5UL, 11UL, 27UL, 0UL };
const unsigned long dim11initializers[] = {
1UL, 1UL, 7UL, 3UL, 29UL, 0UL };
const unsigned long dim12initializers[] = {
1UL, 3UL, 7UL, 13UL, 3UL, 0UL };
const unsigned long dim13initializers[] = {
1UL, 3UL, 5UL, 1UL, 15UL, 0UL };
const unsigned long dim14initializers[] = {
1UL, 1UL, 1UL, 9UL, 23UL, 37UL, 0UL };
const unsigned long dim15initializers[] = {
1UL, 1UL, 3UL, 13UL, 11UL, 7UL, 0UL };
const unsigned long dim16initializers[] = {
1UL, 3UL, 3UL, 5UL, 19UL, 33UL, 0UL };
const unsigned long dim17initializers[] = {
1UL, 1UL, 7UL, 13UL, 25UL, 5UL, 0UL };
const unsigned long dim18initializers[] = {
1UL, 1UL, 1UL, 3UL, 13UL, 39UL, 0UL };
const unsigned long dim19initializers[] = {
1UL, 3UL, 5UL, 11UL, 7UL, 11UL, 0UL };
const unsigned long dim20initializers[] = {
1UL, 3UL, 1UL, 7UL, 3UL, 23UL, 79UL, 0UL };
const unsigned long dim21initializers[] = {
1UL, 3UL, 1UL, 15UL, 17UL, 63UL, 13UL, 0UL };
const unsigned long dim22initializers[] = {
1UL, 3UL, 3UL, 3UL, 25UL, 17UL, 115UL, 0UL };
const unsigned long dim23initializers[] = {
1UL, 3UL, 7UL, 9UL, 31UL, 29UL, 17UL, 0UL };
const unsigned long dim24initializers[] = {
1UL, 1UL, 3UL, 15UL, 29UL, 15UL, 41UL, 0UL };
const unsigned long dim25initializers[] = {
1UL, 3UL, 1UL, 9UL, 5UL, 21UL, 119UL, 0UL };
const unsigned long dim26initializers[] = {
1UL, 1UL, 5UL, 5UL, 1UL, 27UL, 33UL, 0UL };
const unsigned long dim27initializers[] = {
1UL, 1UL, 3UL, 1UL, 23UL, 13UL, 75UL, 0UL };
const unsigned long dim28initializers[] = {
1UL, 1UL, 7UL, 7UL, 19UL, 25UL, 105UL, 0UL };
const unsigned long dim29initializers[] = {
1UL, 3UL, 5UL, 5UL, 21UL, 9UL, 7UL, 0UL };
const unsigned long dim30initializers[] = {
1UL, 1UL, 1UL, 15UL, 5UL, 49UL, 59UL, 0UL };
const unsigned long dim31initializers[] = {
1UL, 3UL, 5UL, 15UL, 17UL, 19UL, 21UL, 0UL };
const unsigned long dim32initializers[] = {
1UL, 1UL, 7UL, 11UL, 13UL, 29UL, 3UL, 0UL };
const unsigned long * const initializers[31] = {
dim02SLinitializers,
dim03SLinitializers,
dim04SLinitializers,
dim05SLinitializers,
dim06SLinitializers,
dim07SLinitializers,
dim08SLinitializers,
dim09initializers,
dim10initializers,
dim11initializers,
dim12initializers,
dim13initializers,
dim14initializers,
dim15initializers,
dim16initializers,
dim17initializers,
dim18initializers,
dim19initializers,
dim20initializers,
dim21initializers,
dim22initializers,
dim23initializers,
dim24initializers,
dim25initializers,
dim26initializers,
dim27initializers,
dim28initializers,
dim29initializers,
dim30initializers,
dim31initializers,
dim32initializers
};
/* Lemieux coefficients of the free direction integers as given
in Christiane Lemieux, private communication, September 2004
*/
const unsigned long dim041Linitializers[] = {
1UL,1UL,3UL,13UL,7UL,35UL,61UL,91UL,0UL};
const unsigned long dim042Linitializers[] = {
1UL,1UL,7UL,11UL,5UL,35UL,55UL,75UL,0UL};
const unsigned long dim043Linitializers[] = {
1UL,3UL,5UL,5UL,11UL,23UL,29UL,139UL,0UL};
const unsigned long dim044Linitializers[] = {
1UL,1UL,1UL,7UL,11UL,15UL,17UL,81UL,0UL};
const unsigned long dim045Linitializers[] = {
1UL,1UL,7UL,9UL,5UL,57UL,79UL,103UL,0UL};
const unsigned long dim046Linitializers[] = {
1UL,1UL,7UL,13UL,19UL,5UL,5UL,185UL,0UL};
const unsigned long dim047Linitializers[] = {
1UL,3UL,1UL,3UL,13UL,57UL,97UL,131UL,0UL};
const unsigned long dim048Linitializers[] = {
1UL,1UL,5UL,5UL,21UL,25UL,125UL,197UL,0UL};
const unsigned long dim049Linitializers[] = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -