Skip to content

Commit

Permalink
Merge branch 'master' into fuzz_american_option
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Dec 13, 2023
2 parents 37db271 + 1cfefcf commit 9cfd2ab
Show file tree
Hide file tree
Showing 191 changed files with 41,787 additions and 45,372 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/devenv-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
description: 'Boost version'
required: true
env:
ROLLING: lunar
ROLLING: mantic
jobs:
docker-images:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
staleness-check:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.'
Expand Down
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.22.0)
cmake_minimum_required(VERSION 3.15.0)

# For MSVC RUNTIME LIBRARY, need CMP0091=NEW and cmake 3.15+
cmake_policy(SET CMP0091 NEW)

include(CMakeDependentOption)

# Version info
set(QUANTLIB_VERSION_MAJOR 1)
set(QUANTLIB_VERSION_MINOR 33)
Expand Down Expand Up @@ -44,7 +42,7 @@ set(QL_INSTALL_CMAKEDIR "lib/cmake/${PACKAGE_NAME}" CACHE STRING
option(QL_BUILD_BENCHMARK "Build benchmark" ON)
option(QL_BUILD_EXAMPLES "Build examples" ON)
option(QL_BUILD_TEST_SUITE "Build test suite" ON)
cmake_dependent_option(QL_BUILD_FUZZ_TEST_SUITE "Build fuzz test suite" OFF "'${CMAKE_CXX_COMPILER_ID}' MATCHES 'Clang'" OFF)
option(QL_BUILD_FUZZ_TEST_SUITE "Build fuzz test suite" OFF)
option(QL_ENABLE_OPENMP "Detect and use OpenMP" OFF)
option(QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER "Enable the parallel unit test runner" OFF)
option(QL_ENABLE_SESSIONS "Singletons return different instances for different sessions" OFF)
Expand Down Expand Up @@ -272,7 +270,7 @@ if (QL_BUILD_TEST_SUITE OR QL_BUILD_BENCHMARK)
add_subdirectory(test-suite)
endif()

if (QL_BUILD_FUZZ_TEST_SUITE)
if ('${CMAKE_CXX_COMPILER_ID}' MATCHES 'Clang' AND QL_BUILD_FUZZ_TEST_SUITE)
add_subdirectory(fuzz-test-suite)
endif()

Expand Down
8 changes: 7 additions & 1 deletion fuzz-test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ else()
set(FUZZING_LINK_FLAGS "-fsanitize=fuzzer")
endif()

# Define the fuzz target
add_executable(DateParserFuzzer dateparserfuzzer.cpp)
set_target_properties(DateParserFuzzer PROPERTIES
COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}"
Expand All @@ -22,3 +21,10 @@ set_target_properties(AmericanOptionFuzzer PROPERTIES
LINK_FLAGS "${FUZZING_LINK_FLAGS}"
)
target_link_libraries(AmericanOptionFuzzer ql_library ${QL_THREAD_LIBRARIES})

add_executable(AmortizedBondsFuzzer amortizedbondsfuzzer.cpp)
set_target_properties(AmortizedBondsFuzzer PROPERTIES
COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}"
LINK_FLAGS "${FUZZING_LINK_FLAGS}"
)
target_link_libraries(AmortizedBondsFuzzer ql_library ${QL_THREAD_LIBRARIES})
80 changes: 80 additions & 0 deletions fuzz-test-suite/amortizedbondsfuzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright (C) 2023 Nathaniel Brough
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 <ql/cashflows/fixedratecoupon.hpp>
#include <ql/instruments/bonds/amortizingfixedratebond.hpp>
#include <ql/settings.hpp>
#include <ql/time/calendars/brazil.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ql/time/daycounters/business252.hpp>
#include <cassert>
#include <fuzzer/FuzzedDataProvider.h>
#include <limits>
#define _unused(x) ((void)(x))

using namespace QuantLib;

std::vector<Real> fuzzedRates(FuzzedDataProvider& fdp, const size_t length) {
std::vector<Real> result;
for (size_t i = 0; i < length; i++) {
result.push_back(fdp.ConsumeProbability<Real>());
}
return result;
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
FuzzedDataProvider fdp(Data, Size);
// Ensure settings are reset each iteration of the fuzzing loop.
// NOTE: this class manages the settings singleton using default
// (con/des)tructors.
SavedSettings saved_settings;

constexpr size_t kMaxSize = 512;
auto length = fdp.ConsumeIntegralInRange<size_t>(0, kMaxSize);

Date refDate = Settings::instance().evaluationDate();

auto rates = fuzzedRates(fdp, length);
Frequency freq = Monthly;

for (size_t i = 0; i < length; ++i) {

auto schedule = sinkingSchedule(refDate, Period(30, Years), freq, NullCalendar());
auto notionals = sinkingNotionals(Period(30, Years), freq, rates[i], 100.0);

AmortizingFixedRateBond myBond(0, notionals, schedule, {rates[i]},
ActualActual(ActualActual::ISMA));

Leg cashflows = myBond.cashflows();

Real lastTotalAmount = 0.0;
for (size_t k = 0; k < cashflows.size() / 2; ++k) {
Real coupon = cashflows[2 * k]->amount();
Real principal = cashflows[2 * k + 1]->amount();
Real totalAmount = coupon + principal;
// Assert invariants, these should always be true.
assert(coupon > 0.0);
assert(principal > 0.0);
assert(totalAmout > lastTotalAmount);
lastTotalAmount = totalAmount;
_unused(lastTotalAmount);
}
}
return 0;
}
39 changes: 38 additions & 1 deletion ql/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ namespace QuantLib {
return out << "null currency";
}

QL_DEPRECATED_DISABLE_WARNING

Currency::Data::Data(std::string name,
std::string code,
Integer numericCode,
std::string symbol,
std::string fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
Currency triangulationCurrency,
std::set<std::string> minorUnitCodes)
: name(std::move(name)), code(std::move(code)), numeric(numericCode), symbol(std::move(symbol)),
fractionSymbol(std::move(fractionSymbol)), fractionsPerUnit(fractionsPerUnit),
rounding(rounding), triangulated(std::move(triangulationCurrency)),
minorUnitCodes(std::move(minorUnitCodes)) {}

Currency::Data::Data(std::string name,
std::string code,
Integer numericCode,
Expand All @@ -44,6 +60,25 @@ namespace QuantLib {
rounding(rounding), triangulated(std::move(triangulationCurrency)),
formatString(std::move(formatString)), minorUnitCodes(std::move(minorUnitCodes)) {}

Currency::Currency(const std::string& name,
const std::string& code,
Integer numericCode,
const std::string& symbol,
const std::string& fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
const Currency& triangulationCurrency,
const std::set<std::string>& minorUnitCodes)
: data_(ext::make_shared<Currency::Data>(name,
code,
numericCode,
symbol,
fractionSymbol,
fractionsPerUnit,
rounding,
triangulationCurrency,
minorUnitCodes)) {}

Currency::Currency(const std::string& name,
const std::string& code,
Integer numericCode,
Expand All @@ -64,5 +99,7 @@ namespace QuantLib {
formatString,
triangulationCurrency,
minorUnitCodes)) {}
}

QL_DEPRECATED_ENABLE_WARNING

}
40 changes: 40 additions & 0 deletions ql/currency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ namespace QuantLib {
used.
*/
Currency() = default;
Currency(const std::string& name,
const std::string& code,
Integer numericCode,
const std::string& symbol,
const std::string& fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
const Currency& triangulationCurrency = Currency(),
const std::set<std::string>& minorUnitCodes = {});
/*! \deprecated Use the constructor without formatString.
Deprecated in version 1.33.
*/
QL_DEPRECATED
Currency(const std::string& name,
const std::string& code,
Integer numericCode,
Expand Down Expand Up @@ -75,6 +88,10 @@ namespace QuantLib {
/*! The format will be fed three positional parameters,
namely, value, code, and symbol, in this order.
*/
/*! \deprecated Copy the formatting into your project if you need it.
Deprecated in version 1.33.
*/
[[deprecated("Copy the formatting into your project if you need it.")]]
std::string format() const;
//@}
//! \name Other information
Expand All @@ -93,16 +110,33 @@ namespace QuantLib {
void checkNonEmpty() const;
};

QL_DEPRECATED_DISABLE_WARNING

struct Currency::Data {
std::string name, code;
Integer numeric;
std::string symbol, fractionSymbol;
Integer fractionsPerUnit;
Rounding rounding;
Currency triangulated;
QL_DEPRECATED
std::string formatString;
std::set<std::string> minorUnitCodes;

/*! \deprecated Use the constructor without formatString.
Deprecated in version 1.33.
*/
QL_DEPRECATED
Data(std::string name,
std::string code,
Integer numericCode,
std::string symbol,
std::string fractionSymbol,
Integer fractionsPerUnit,
const Rounding& rounding,
Currency triangulationCurrency = Currency(),
std::set<std::string> minorUnitCodes = {});

Data(std::string name,
std::string code,
Integer numericCode,
Expand All @@ -115,6 +149,8 @@ namespace QuantLib {
std::set<std::string> minorUnitCodes = {});
};

QL_DEPRECATED_ENABLE_WARNING

/*! \relates Currency */
bool operator==(const Currency&,
const Currency&);
Expand Down Expand Up @@ -169,11 +205,15 @@ namespace QuantLib {
return data_->rounding;
}

QL_DEPRECATED_DISABLE_WARNING

inline std::string Currency::format() const {
checkNonEmpty();
return data_->formatString;
}

QL_DEPRECATED_ENABLE_WARNING

inline bool Currency::empty() const {
return !data_;
}
Expand Down
Loading

0 comments on commit 9cfd2ab

Please sign in to comment.