Skip to content
Closed
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
5 changes: 3 additions & 2 deletions crates/openquant/src/util/volatility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ pub fn get_daily_vol(close: &[(NaiveDateTime, f64)], lookback: usize) -> Vec<(Na
}

/// Parkinson volatility estimator.
/// Mirrors mlfinlab.util.volatility.get_parksinson_vol.
pub fn get_parksinson_vol(high: &[f64], low: &[f64], window: usize) -> Vec<f64> {
/// Mirrors mlfinlab's `get_parksinson_vol` — note that upstream misspells
/// "Parkinson"; this crate spells it correctly.
pub fn get_parkinson_vol(high: &[f64], low: &[f64], window: usize) -> Vec<f64> {
assert_eq!(high.len(), low.len(), "high/low length mismatch");
let estimator: Vec<f64> = high
.iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/openquant/tests/volatility_features.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use csv::ReaderBuilder;
use openquant::util::volatility::{get_garman_class_vol, get_parksinson_vol, get_yang_zhang_vol};
use openquant::util::volatility::{get_garman_class_vol, get_parkinson_vol, get_yang_zhang_vol};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -47,7 +47,7 @@ fn test_volatility_estimators_match_mlfinlab_baseline() {
let (open, high, low, close) = load_ohlc();
let gm_vol = get_garman_class_vol(&open, &high, &low, &close, 20);
let yz_vol = get_yang_zhang_vol(&open, &high, &low, &close, 20);
let park_vol = get_parksinson_vol(&high, &low, 20);
let park_vol = get_parkinson_vol(&high, &low, 20);

assert_eq!(close.len(), gm_vol.len());
assert_eq!(close.len(), yz_vol.len());
Expand Down
8 changes: 4 additions & 4 deletions crates/pyopenquant/src/volatility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ fn volatility_get_daily_vol(
Ok(result.into_iter().map(|(ts, v)| (ts.format("%Y-%m-%d %H:%M:%S").to_string(), v)).collect())
}

#[pyfunction(name = "get_parksinson_vol")]
fn volatility_get_parksinson_vol(high: Vec<f64>, low: Vec<f64>, window: usize) -> Vec<f64> {
openquant::util::volatility::get_parksinson_vol(&high, &low, window)
#[pyfunction(name = "get_parkinson_vol")]
fn volatility_get_parkinson_vol(high: Vec<f64>, low: Vec<f64>, window: usize) -> Vec<f64> {
openquant::util::volatility::get_parkinson_vol(&high, &low, window)
}

#[pyfunction(name = "get_garman_class_vol")]
Expand Down Expand Up @@ -44,7 +44,7 @@ fn volatility_get_yang_zhang_vol(
pub fn register(py: Python<'_>, parent: &Bound<'_, PyModule>) -> PyResult<()> {
let m = PyModule::new(py, "volatility")?;
m.add_function(wrap_pyfunction!(volatility_get_daily_vol, &m)?)?;
m.add_function(wrap_pyfunction!(volatility_get_parksinson_vol, &m)?)?;
m.add_function(wrap_pyfunction!(volatility_get_parkinson_vol, &m)?)?;
m.add_function(wrap_pyfunction!(volatility_get_garman_class_vol, &m)?)?;
m.add_function(wrap_pyfunction!(volatility_get_yang_zhang_vol, &m)?)?;
parent.add_submodule(&m)?;
Expand Down
Loading