Skip to content

Commit

Permalink
Update copyright info, add library notices, and enhance documentation
Browse files Browse the repository at this point in the history
Updated the copyright owner's name in the LICENSE file and added the license notice for the externally sourced library. Introduced detailed explanations for the `black` and `implied_black_volatility` functions in src/lets_be_rational.rs. Lastly, improved the introductory content in the README.md file to give a better overview of the project and its purpose.
  • Loading branch information
nakashima-hikaru committed Jan 14, 2024
1 parent 141d0f1 commit ac41678
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
18 changes: 17 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 hnakashima
Copyright (c) 2024 Hikaru Nakashima

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +19,19 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The externally maintained library from which parts of the Software is derived is:

- LetsBeRational, licensed as follows:

=========================================================================================
Copyright © 2013 - 2023 Peter Jäckel.

Permission to use, copy, modify, and distribute this software is freely granted,
provided that this notice is preserved.

WARRANTY DISCLAIMER
The Software is provided "as is" without warranty of any kind, either express or implied,
including without limitation any implied warranties of condition, uninterrupted use,
merchantability, fitness for a particular purpose, or non-infringement.
==========================================================================================
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# implied-vol
A pure rust implementation of Peter Jäckel's implied volatility calculation
# Implied Vol

Welcome to `implied-vol`, a lightning-fast, pure Rust implementation of Peter Jäckel's renowned implied volatility
calculations.

Originally found at [Peter Jäckel's homepage](http://www.jaeckel.org/), this library is a robust Rust reimplementation
of the pioneering work laid out in Jäckel's article, [Let's Be Rational](http://www.jaeckel.org/LetsBeRational.pdf).

Our aim is to offer a tool that provides blazingly fast and precise calculations of implied Black volatility.
With `implied-vol`, speed and accuracy in your quantitative finance projects need not be mutually exclusive.
26 changes: 26 additions & 0 deletions src/lets_be_rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ fn normalised_black(x: f64, s: f64, theta: f64) -> f64 {
normalised_black_call(if theta < 0f64 { -x } else { x }, s)
}

/// Calculates the price of a European option using the Black-Scholes formula.
///
/// # Arguments
///
/// * `f` - The current value of the underlying asset.
/// * `k` - The strike price of the option.
/// * `sigma` - The volatility of the underlying asset.
/// * `t` - The time to expiration of the option.
/// * `q` - Positive if call else put.
///
/// # Returns
///
/// The price of the European option.
pub fn black(f: f64, k: f64, sigma: f64, t: f64, q: f64) -> f64 {
let intrinsic = if q < 0f64 { k - f } else { f - k }.max(0f64).abs();
if q * (f - k) > 0f64 {
Expand Down Expand Up @@ -452,6 +465,19 @@ fn implied_volatility_from_a_transformed_rational_guess_with_limited_iterations(
// return unchecked_normalised_implied_volatility_from_a_transformed_rational_guess_with_limited_iterations(beta, x, q, n);
// }

/// Calculates the implied black volatility using a transformed rational guess with limited iterations.
///
/// # Arguments
///
/// * `price` - The current price of the option.
/// * `f` - The current forward price of the underlying asset.
/// * `k` - The strike price of the option.
/// * `t` - The time to expiration in years.
/// * `q` - Positive if call else put.
///
/// # Returns
///
/// The implied black volatility.
pub fn implied_black_volatility(price: f64, f: f64, k: f64, t: f64, q: f64) -> f64 {
implied_volatility_from_a_transformed_rational_guess_with_limited_iterations(price, f, k, t, q, 2)
}
Expand Down

0 comments on commit ac41678

Please sign in to comment.