Skip to content

Commit

Permalink
fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
klausspanderen committed Nov 9, 2024
1 parent 313700a commit 22f4e82
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 102 deletions.
2 changes: 1 addition & 1 deletion ql/methods/finitedifferences/operators/fdmwienerop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/


/*! \file fdmndimwienerop.cpp
/*! \file fdmwienerop.cpp
*/

#include <ql/termstructures/yieldtermstructure.hpp>
Expand Down
1 change: 0 additions & 1 deletion ql/methods/finitedifferences/operators/fdmwienerop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace QuantLib {
const ext::shared_ptr<YieldTermStructure> rTS_;
std::vector<ext::shared_ptr<TripleBandLinearOp> > ops_;
Rate r_;

};
}
#endif
5 changes: 2 additions & 3 deletions ql/pricingengines/basket/choibasketengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace QuantLib {
Spread, Basket and Asian Options", Jaehyuk Choi, 2018
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2913048
Python implementation from the author of the paper is also available
A Python implementation from the author of the paper is also available
https://github.com/PyFE/PyFENG
\ingroup basketengines
Expand All @@ -45,8 +45,7 @@ namespace QuantLib {
*/
class ChoiBasketEngine : public BasketOption::engine {
public:
// lambda controls the precision,
// fast: 4, accurate: 8, high precision: 20
// lambda controls the integration order and the precision of the result.
ChoiBasketEngine(
std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > processes,
Matrix rho,
Expand Down
3 changes: 1 addition & 2 deletions ql/pricingengines/basket/denglizhoubasketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
FOR A PARTICULAR PURPOSE. See the license for more details.
*/

#include "denglizhoubasketengine.hpp"

#include <ql/exercise.hpp>
#include <ql/math/functional.hpp>
#include <ql/math/distributions/normaldistribution.hpp>
#include <ql/math/matrixutilities/pseudosqrt.hpp>
#include <ql/math/matrixutilities/choleskydecomposition.hpp>
#include <ql/pricingengines/basket/vectorbsmprocessextractor.hpp>
#include <ql/pricingengines/basket/denglizhoubasketengine.hpp>

namespace QuantLib {

Expand Down Expand Up @@ -62,7 +62,6 @@ namespace QuantLib {

QL_REQUIRE(avgPayoff, "average or spread basket payoff expected");

// sort assets by their weight
const Array weights = avgPayoff->weights();
QL_REQUIRE(n_ == weights.size() && n_ > 1,
"wrong number of weights arguments in payoff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace QuantLib {
const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Douglas());


// Auto-scaling of grids, larges eigenvalue gets xGrid size.
// Auto-scaling of grids, largest eigenvalue gets xGrid size.
FdndimBlackScholesVanillaEngine(
std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > processes,
Matrix rho,
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/basket/operatorsplittingspreadengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace QuantLib {
QL_REQUIRE(order_ == Second, "unknown approximation type");

/*
In the original paper the second order was calculated using numerical differentiation.
In the original paper, the second-order approximation was computed using numerical differentiation.
The following Mathematica scripts calculates the approximation to the n'th order.
vol2Hat[R2_] := vol2*(R2 - K)/R2
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/basket/operatorsplittingspreadengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace QuantLib {

//! Pricing engine for spread option on two futures
//! Pricing engine for spread options with two assets
/*! Chi-Fai Lo,
Pricing Spread Options by the Operator Splitting Method,
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2429696
Expand Down
1 change: 0 additions & 1 deletion ql/pricingengines/basket/singlefactorbsmbasketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ namespace QuantLib {
QL_REQUIRE(payoff, "non-plain vanilla payoff given");
const Real strike = payoff->strike();

// sort assets by their weight
const Array weights = avgPayoff->weights();
QL_REQUIRE(n_ == weights.size(),
"wrong number of weights arguments in payoff");
Expand Down
32 changes: 16 additions & 16 deletions ql/pricingengines/basket/singlefactorbsmbasketengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ namespace QuantLib {
\ingroup basketengines
*/

class SumExponentialsRootSolver {
public:
enum Strategy {Ridder, Newton, Brent, Halley};
class SumExponentialsRootSolver {
public:
enum Strategy {Ridder, Newton, Brent, Halley};

SumExponentialsRootSolver(Array a, Array sig, Real K);
SumExponentialsRootSolver(Array a, Array sig, Real K);

Real operator()(Real x) const;
Real derivative(Real x) const;
Real secondDerivative(Real x) const;
Real operator()(Real x) const;
Real derivative(Real x) const;
Real secondDerivative(Real x) const;

Real getRoot(Real xTol = 1e6*QL_EPSILON, Strategy strategy = Brent) const;
Real getRoot(Real xTol = 1e6*QL_EPSILON, Strategy strategy = Brent) const;

Size getFCtr() const;
Size getDerivativeCtr() const;
Size getSecondDerivativeCtr() const;
Size getFCtr() const;
Size getDerivativeCtr() const;
Size getSecondDerivativeCtr() const;

private:
const Array a_, sig_;
const Real K_;
mutable Size fCtr_, fPrimeCtr_, fDoublePrimeCtr_;
};
private:
const Array a_, sig_;
const Real K_;
mutable Size fCtr_, fPrimeCtr_, fDoublePrimeCtr_;
};

class SingleFactorBsmBasketEngine : public BasketOption::engine {
public:
Expand Down
84 changes: 42 additions & 42 deletions test-suite/basketoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,51 +1772,51 @@ BOOST_AUTO_TEST_CASE(testRootOfSumExponentials) {
MersenneTwisterUniformRng mt(42);

for (auto strategy: {
std::make_tuple("Brent", SumExponentialsRootSolver::Brent),
std::make_tuple("Newton", SumExponentialsRootSolver::Newton),
std::make_tuple("Ridder", SumExponentialsRootSolver::Ridder),
std::make_tuple("Halley", SumExponentialsRootSolver::Halley)
}) {

Size fCtr = 0;
const Size n = 10000;
const Real tol = 1e8*QL_EPSILON;
const Real acc = 1e-4*tol;
IncrementalStatistics stats;

for (Size i=0; i < n; ++i) {
const Size n = (mt.nextInt32() % 10)+1;
Array a(n), sig(n);
const Real offset = (mt.nextReal() < 0.3)? -1.0 : 0.0;
for (Size j=0; j < n; ++j) {
a[j] = mt.nextReal() + offset;
sig[j] = copysign(1.0, a[j])*mt.nextReal();
}
const Real kMin = SumExponentialsRootSolver(a, sig, 0.0)(-10.0);
const Real kMax = SumExponentialsRootSolver(a, sig, 0.0)( 10.0);
const Real K = (kMax - kMin)*mt.nextReal() + kMin;

const Real xValue = SumExponentialsRootSolver(a, sig, K)
.getRoot(acc, SumExponentialsRootSolver::Brent);
std::make_tuple("Brent", SumExponentialsRootSolver::Brent),
std::make_tuple("Newton", SumExponentialsRootSolver::Newton),
std::make_tuple("Ridder", SumExponentialsRootSolver::Ridder),
std::make_tuple("Halley", SumExponentialsRootSolver::Halley)
}) {

Size fCtr = 0;
const Size n = 10000;
const Real tol = 1e8*QL_EPSILON;
const Real acc = 1e-4*tol;
IncrementalStatistics stats;

for (Size i=0; i < n; ++i) {
const Size n = (mt.nextInt32() % 10)+1;
Array a(n), sig(n);
const Real offset = (mt.nextReal() < 0.3)? -1.0 : 0.0;
for (Size j=0; j < n; ++j) {
a[j] = mt.nextReal() + offset;
sig[j] = copysign(1.0, a[j])*mt.nextReal();
}
const Real kMin = SumExponentialsRootSolver(a, sig, 0.0)(-10.0);
const Real kMax = SumExponentialsRootSolver(a, sig, 0.0)( 10.0);
const Real K = (kMax - kMin)*mt.nextReal() + kMin;

const Real xValue = SumExponentialsRootSolver(a, sig, K)
.getRoot(acc, SumExponentialsRootSolver::Brent);

const SumExponentialsRootSolver solver(a, sig, K);
const Real xRoot = solver.getRoot(tol, std::get<1>(strategy));
const Real xRoot = solver.getRoot(tol, std::get<1>(strategy));

stats.add(xValue - xRoot);
fCtr += solver.getFCtr() + solver.getDerivativeCtr() + solver.getSecondDerivativeCtr();
}
stats.add(xValue - xRoot);
fCtr += solver.getFCtr() + solver.getDerivativeCtr() + solver.getSecondDerivativeCtr();
}

if (fCtr > 15*n) {
if (fCtr > 15*n) {
BOOST_FAIL("too many function calls needed for solver " << std::get<0>(strategy));
}
}

if (stats.standardDeviation() > 10*tol) {
if (stats.standardDeviation() > 10*tol) {
BOOST_FAIL("failed to find root of sum of exponentials"
<< "\n solver : " << std::get<0>(strategy)
<< std::fixed << std::setprecision(15)
<< "\n stdev : " << stats.standardDeviation()
<< "\n tolerance: " << tol);
}
}
}
}

Expand Down Expand Up @@ -1949,11 +1949,11 @@ BOOST_AUTO_TEST_CASE(testGoldenChoiBasketEngineExample) {
const ext::shared_ptr<SimpleQuote>& spot, Rate q, Volatility vol)
-> ext::shared_ptr<GeneralizedBlackScholesProcess> {
return ext::make_shared<GeneralizedBlackScholesProcess>(
Handle<Quote>(spot),
Handle<YieldTermStructure>(flatRate(today, q, dc)),
rTS,
Handle<BlackVolTermStructure>(flatVol(today, vol, dc))
);
Handle<Quote>(spot),
Handle<YieldTermStructure>(flatRate(today, q, dc)),
rTS,
Handle<BlackVolTermStructure>(flatVol(today, vol, dc))
);
};

const std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> >
Expand Down Expand Up @@ -2189,7 +2189,7 @@ BOOST_AUTO_TEST_CASE(testSpreadAndBasketBenchmarks) {
{11.5795246248372834, 8.11486124233140238, 5.36890684802773066,
3.35146299782513601, 1.97711593318812251}
},
// unknown
// new
{
{80, 120, 100, 100}, {0.3, 0.4, 0.2, 0.35}, {0.01, 0.03, 0.07, 0.04}, 0.03,
{{{1.0, 0.5, 0.35, 0.35},
Expand Down Expand Up @@ -2451,8 +2451,8 @@ BOOST_AUTO_TEST_CASE(testFdmAmericanBasketOptions) {
<< "\n tolerance: " << tol);
}

BOOST_AUTO_TEST_CASE(testPrecisionAmericanBasketOptions) {
BOOST_TEST_MESSAGE("Testing high precision American Options using multi-dim FDM...");
BOOST_AUTO_TEST_CASE(testAccurateAmericanBasketOptions) {
BOOST_TEST_MESSAGE("Testing high precision American Options Pricing using multi-dim FDM...");

const DayCounter dc = Actual365Fixed();
const Date today = Date(28, October, 2024);
Expand Down
66 changes: 33 additions & 33 deletions test-suite/matrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,13 +913,13 @@ BOOST_AUTO_TEST_CASE(testCholeskySolverForIncomplete) {
}

namespace {
void QL_CHECK_CLOSE_ARRAY_TOL(
const Array& actual, const Array& expected, Real tol) {
BOOST_REQUIRE(actual.size() == expected.size());
for (auto i = 0u; i < actual.size(); i++) {
BOOST_CHECK_SMALL(actual[i] - expected[i], tol);
}
}
void QL_CHECK_CLOSE_ARRAY_TOL(
const Array& actual, const Array& expected, Real tol) {
BOOST_REQUIRE(actual.size() == expected.size());
for (auto i = 0u; i < actual.size(); i++) {
BOOST_CHECK_SMALL(actual[i] - expected[i], tol);
}
}
}

BOOST_AUTO_TEST_CASE(testHouseholderTransformation) {
Expand All @@ -928,23 +928,23 @@ BOOST_AUTO_TEST_CASE(testHouseholderTransformation) {
MersenneTwisterUniformRng rng(1234);

const auto I = [](Size i) -> Matrix {
Matrix id(i, i, 0.0);
for (Size j=0; j < i; ++j)
id[j][j] = 1.0;
Matrix id(i, i, 0.0);
for (Size j=0; j < i; ++j)
id[j][j] = 1.0;

return id;
return id;
};

for (Size i=1; i < 10; ++i) {
Array v(i), x(i);
for (Size j=0; j < i; ++j) {
v[j] = rng.nextReal()-0.5;
x[j] = rng.nextReal()-0.5;
}

const Array expected = (I(i)- 2.0*outerProduct(v, v))*x;
const Array calculated = HouseholderTransformation(v)(x);
QL_CHECK_CLOSE_ARRAY_TOL(calculated, expected, 1e4*QL_EPSILON);
Array v(i), x(i);
for (Size j=0; j < i; ++j) {
v[j] = rng.nextReal()-0.5;
x[j] = rng.nextReal()-0.5;
}

const Array expected = (I(i)- 2.0*outerProduct(v, v))*x;
const Array calculated = HouseholderTransformation(v)(x);
QL_CHECK_CLOSE_ARRAY_TOL(calculated, expected, 1e4*QL_EPSILON);
}
}

Expand All @@ -954,24 +954,24 @@ BOOST_AUTO_TEST_CASE(testHouseholderReflection) {
const Real tol=1e4*QL_EPSILON;

const auto e = [](Size n, Size m=0) -> Array {
Array e(n, 0.0);
e[m] = 1.0;
return e;
Array e(n, 0.0);
e[m] = 1.0;
return e;
};

for (Size i=0; i < 5; ++i) {
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(e(5, i)), e(5), tol);
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(M_PI*e(5, i)), M_PI*e(5), tol);
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(
e(5, i) + e(5)),
((i==0)? 2.0 : M_SQRT2)*e(5), tol);
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(e(5, i)), e(5), tol);
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(M_PI*e(5, i)), M_PI*e(5), tol);
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(5))(
e(5, i) + e(5)),
((i==0)? 2.0 : M_SQRT2)*e(5), tol);
}

// limits
for (Real x=10; x > 1e-50; x*=0.1) {
for (Real x=10; x > 1e-50; x*=0.1) {
QL_CHECK_CLOSE_ARRAY_TOL(
HouseholderReflection(e(3))(
Array({10.0, x, 0})),
Expand All @@ -983,7 +983,7 @@ BOOST_AUTO_TEST_CASE(testHouseholderReflection) {
Array({10.0, x, 1e-3})),
std::sqrt(10.0*10.0+x*x+1e-3*1e-3)*e(3), tol
);
}
}

MersenneTwisterUniformRng rng(1234);

Expand Down

0 comments on commit 22f4e82

Please sign in to comment.