Skip to main content

nautilus_indicators/python/volatility/
vr.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use nautilus_model::data::{Bar, QuoteTick, TradeTick};
17use pyo3::prelude::*;
18
19use crate::{average::MovingAverageType, indicator::Indicator, volatility::vr::VolatilityRatio};
20
21#[pymethods]
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23impl VolatilityRatio {
24    /// Creates a new `VolatilityRatio` instance.
25    #[new]
26    #[pyo3(signature = (fast_period, slow_period, use_previous=None, value_floor=None, ma_type=None))]
27    #[must_use]
28    pub fn py_new(
29        fast_period: usize,
30        slow_period: usize,
31        use_previous: Option<bool>,
32        value_floor: Option<f64>,
33        ma_type: Option<MovingAverageType>,
34    ) -> Self {
35        Self::new(fast_period, slow_period, ma_type, use_previous, value_floor)
36    }
37
38    fn __repr__(&self) -> String {
39        format!("VolatilityRatio({},{})", self.fast_period, self.slow_period)
40    }
41
42    #[getter]
43    #[pyo3(name = "name")]
44    fn py_name(&self) -> String {
45        self.name()
46    }
47
48    #[getter]
49    #[pyo3(name = "fast_period")]
50    const fn py_fast_period(&self) -> usize {
51        self.fast_period
52    }
53
54    #[getter]
55    #[pyo3(name = "slow_period")]
56    const fn py_slow_period(&self) -> usize {
57        self.slow_period
58    }
59
60    #[getter]
61    #[pyo3(name = "has_inputs")]
62    fn py_has_inputs(&self) -> bool {
63        self.has_inputs()
64    }
65
66    #[getter]
67    #[pyo3(name = "use_previous")]
68    const fn py_use_previous(&self) -> bool {
69        self.use_previous
70    }
71
72    #[getter]
73    #[pyo3(name = "value_floor")]
74    const fn py_value_floor(&self) -> f64 {
75        self.value_floor
76    }
77
78    #[getter]
79    #[pyo3(name = "value")]
80    const fn py_value(&self) -> f64 {
81        self.value
82    }
83
84    #[getter]
85    #[pyo3(name = "initialized")]
86    const fn py_initialized(&self) -> bool {
87        self.initialized
88    }
89
90    #[pyo3(name = "update_raw")]
91    fn py_update_raw(&mut self, high: f64, low: f64, close: f64) {
92        self.update_raw(high, low, close);
93    }
94
95    #[pyo3(name = "handle_quote_tick")]
96    const fn py_handle_quote_tick(&mut self, _quote: &QuoteTick) {
97        // Function body intentionally left blank.
98    }
99
100    #[pyo3(name = "handle_trade_tick")]
101    const fn py_handle_trade_tick(&mut self, _trade: &TradeTick) {
102        // Function body intentionally left blank.
103    }
104
105    #[pyo3(name = "handle_bar")]
106    fn py_handle_bar(&mut self, bar: &Bar) {
107        self.handle_bar(bar);
108    }
109
110    #[pyo3(name = "reset")]
111    fn py_reset(&mut self) {
112        self.reset();
113    }
114}