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

Benchmark #4

Merged
merged 2 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 31 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
language: rust

sudo: required

rust:
- stable
- beta
- nightly

env:
- secure: smQ1nBQ8pM12u6LWc+elM5bSyj4Hgd61h3HcStqtLF88KZBbGlqgZCxewfrWQg7eAk1SPTtiaqc6c6XpZEEWMTYqfa2tkBChnlnatJTwWCGaPjrpBxRyvDhQp/xzTbWfbCNMYtSrA6DnTu2TssBh7HGTt9nffFRRqlX4aBbDePWWxK/1V99fHNYN6kz1g2N/GVxawQ0naUDyzG3bIvQqi1S+ERHNS3gkJo4g7zaeJOhPOQeCfztrqWKC9Bmh8uzOQjumlPj5t0WIrFYYkQpHNZ+uy/uwuZbSopAehIjShrhT9zoFCJQTW4dSKVbJQleKc6QKhw03FNzUHQOLH5ztULttKrcXmVm0e/CetMruhkLwMaVZVoWu/UR2t+Om4LfGWMFnNtf98LkUTkFewzQ9EsU7mqEK9AoNSWhMtAV8BJtFOEdczkO67FDeAFJWf/fpPBjfFjtC49L0wNIH8+9JyEv1Np7FCMV/epO4PXu5na3rUkMYZQAc4mmwptNiHupnsyW4bN5sEwb/Z/Kgy7+sRU++/dISH3v8bs6sZp2z5hJ4tgu1YFmYJTiYy//KUTfSPo3HTx6+/qKE/c/AQDsRZqcIYNP2iSOkVpmVU1VpgLMG5XuC/crMlRacw7PPautXaQf9gmcOkEhgL5Jmku/fiCKM8MiNBKkpOWTtq4P8Cbc=
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- binutils-dev
- libiberty-dev

- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- binutils-dev
- libiberty-dev
- gnuplot
before_cache: |
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin
fi

after_success: |
if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then
cargo tarpaulin --out Xml
bash <(curl -s https://codecov.io/bash)
fi
if [ "$TRAVIS_RUST_VERSION" = stable ]; then
cargo bench
cargo doc
cargo publish --token "$CARGO_API" --allow-dirty
fi
fi

matrix:
include:
- rust: stable
env:
- secure: smQ1nBQ8pM12u6LWc+elM5bSyj4Hgd61h3HcStqtLF88KZBbGlqgZCxewfrWQg7eAk1SPTtiaqc6c6XpZEEWMTYqfa2tkBChnlnatJTwWCGaPjrpBxRyvDhQp/xzTbWfbCNMYtSrA6DnTu2TssBh7HGTt9nffFRRqlX4aBbDePWWxK/1V99fHNYN6kz1g2N/GVxawQ0naUDyzG3bIvQqi1S+ERHNS3gkJo4g7zaeJOhPOQeCfztrqWKC9Bmh8uzOQjumlPj5t0WIrFYYkQpHNZ+uy/uwuZbSopAehIjShrhT9zoFCJQTW4dSKVbJQleKc6QKhw03FNzUHQOLH5ztULttKrcXmVm0e/CetMruhkLwMaVZVoWu/UR2t+Om4LfGWMFnNtf98LkUTkFewzQ9EsU7mqEK9AoNSWhMtAV8BJtFOEdczkO67FDeAFJWf/fpPBjfFjtC49L0wNIH8+9JyEv1Np7FCMV/epO4PXu5na3rUkMYZQAc4mmwptNiHupnsyW4bN5sEwb/Z/Kgy7+sRU++/dISH3v8bs6sZp2z5hJ4tgu1YFmYJTiYy//KUTfSPo3HTx6+/qKE/c/AQDsRZqcIYNP2iSOkVpmVU1VpgLMG5XuC/crMlRacw7PPautXaQf9gmcOkEhgL5Jmku/fiCKM8MiNBKkpOWTtq4P8Cbc=
- secure: UmC6OeG38X+XDaJJnKzjoQ+V4uIqB3tc4pB5qvm2U8tJmpyzQkiPn8v7rcxg+lFnHfashWLfmVJZxE+XHSOIJDMBmxNzRbG0mcxu2nU5uQ87frqLb9e4RqTNChmnI5oBiRaI/zOd6h1EGRgJrTb6RJGgYlr2924y10y5KylgXUsj/nzqQDONDTyO9eiOia6sMDcp+GGMqsO8F+7TPZikFOpe6yGDBhczWc5JaA5FPiKDI3v5JTud00XbW2UALzYtqDszgbSL3NfQG9t7tGzwq6NWkzWTjJpobQfaY5Dnf6/fgO+AEbOuzMJqyKxpseYk+qEOhBXobOULBH7R1o8FAlh6lAw1ZHZW5WZXn36R52NAk0WJg+SS41LBbtPLQalZWm5gYQtJrSmzMCZOu0nwxlpUHODAtoeEAU6Bua3F5T/bZuzwaDt8HXhzEySAbQGyD0vI2R82FFc/UkJzP4uwuuf4guJlJa3SymxcjHufhyfo/M68VeJIU7JrC7FNhtEG8h1aqS2EAzfV2dU6qZKZOis2bHyqRGyMQOnqg7XYXUthmPVPqGuZ2/BAw/6zJvwjg9GLN5OdoAvUb5YNTjXVtW7GMpVJb5oUGnbWkydY5fcf5PNeHoMLIWcyCMsakVP5CpzabcZR8KjyQZHh7PDsRt+gSb2ckpwrMNdGh5izz04=
- rust: nightly
- rust: beta

deploy:
provider: pages
skip_cleanup: true
github_token: "$GITHUB_TOKEN"
keep_history: true
local_dir: target/criterion
on:
branch: master
rust: stable
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ num-complex = "0.2"
[dev-dependencies]
approx = "0.2.0"
statrs = "0.7.0"
criterion = "0.2"

[[bench]]
name = "fang_oost_bench"
harness = false

[badges]
travis-ci = { repository = "phillyfan1138/fang_oost_rust" }
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

# Fang-Oosterlee Library for Rust

Implements [Fang-Oosterlee](https://mpra.ub.uni-muenchen.de/8914/4/MPRA_paper_8914.pdf) algorithm in Rust. While the algorithm originally was used for option pricing, it can be used for a variety of use cases. For example, it can be used to compute the Value at Risk of a distribution, the density of a distribution, and the partial expectation.
Implements [Fang-Oosterlee](https://mpra.ub.uni-muenchen.de/8914/4/MPRA_paper_8914.pdf) algorithm in Rust. While the algorithm originally was used for option pricing, it can be used for a variety of use cases. For example, it can be used to compute the Value at Risk of a distribution, the density of a distribution, and the partial expectation.

It requires a characteristic function computed at various specific intervals. A utility function is provided which converts an analytical characteristic function into a vector.
It requires a characteristic function computed at various specific intervals. A utility function is provided which converts an analytical characteristic function into a vector.

Documentation is at [docs.rs](https://docs.rs/fang_oost/0.13.7/fang_oost/)

Expand All @@ -32,7 +32,7 @@ extern crate fang_oost;
extern crate rayon;
use rayon::prelude::*;
use num_complex::Complex;

let num_x = 1024;
let num_u = 256;
let x_min = -20.0;
Expand All @@ -51,4 +51,8 @@ let density:Vec<f64> = fang_oost::get_density(
## Related Crates

* [Option Pricing with Fang Oost](https://crates.io/crates/fang_oost_option)
* [Distribution Utilities (including CDF, VaR, and Expected Shortfall)](https://crates.io/crates/cf_dist_utils)
* [Distribution Utilities (including CDF, VaR, and Expected Shortfall)](https://crates.io/crates/cf_dist_utils)

## Benchmarks

View benchmarks at https://phillyfan1138.github.io/fang_oost_rust/report.
31 changes: 31 additions & 0 deletions benches/fang_oost_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#[macro_use]
extern crate criterion;
extern crate fang_oost;
extern crate num_complex;
use rayon::prelude::*;
use criterion::Criterion;
use num_complex::Complex;

fn bench_fang_oost_normal_density(c: &mut Criterion) {
let mu=2.0;
let sigma=1.0;
let num_x=5;
let num_u=256;
let x_min=-3.0;
let x_max=7.0;
let norm_cf=move |u:&Complex<f64>|(u*mu+0.5*u*u*sigma*sigma).exp();
c.bench_function("normal density", move |b| {
b.iter(move || {
let my_x_domain=fang_oost::get_x_domain(num_x, x_min, x_max);
let discrete_cf=fang_oost::get_discrete_cf(num_u, x_min, x_max, &norm_cf);
let _my_inverse:Vec<f64>=fang_oost::get_density(
x_min, x_max,
my_x_domain, &discrete_cf
).collect();
})
});
}


criterion_group!(benches, bench_fang_oost_normal_density);
criterion_main!(benches);