nautilus_indicators/python/volatility/
vr.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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]
22impl VolatilityRatio {
23    #[new]
24    #[pyo3(signature = (fast_period, slow_period, use_previous=None, value_floor=None, ma_type=None))]
25    #[must_use]
26    pub fn py_new(
27        fast_period: usize,
28        slow_period: usize,
29        use_previous: Option<bool>,
30        value_floor: Option<f64>,
31        ma_type: Option<MovingAverageType>,
32    ) -> Self {
33        Self::new(fast_period, slow_period, ma_type, use_previous, value_floor)
34    }
35
36    fn __repr__(&self) -> String {
37        format!("VolatilityRatio({},{})", self.fast_period, self.slow_period)
38    }
39
40    #[getter]
41    #[pyo3(name = "name")]
42    fn py_name(&self) -> String {
43        self.name()
44    }
45
46    #[getter]
47    #[pyo3(name = "fast_period")]
48    const fn py_fast_period(&self) -> usize {
49        self.fast_period
50    }
51
52    #[getter]
53    #[pyo3(name = "slow_period")]
54    const fn py_slow_period(&self) -> usize {
55        self.slow_period
56    }
57
58    #[getter]
59    #[pyo3(name = "has_inputs")]
60    fn py_has_inputs(&self) -> bool {
61        self.has_inputs()
62    }
63
64    #[getter]
65    #[pyo3(name = "use_previous")]
66    const fn py_use_previous(&self) -> bool {
67        self.use_previous
68    }
69
70    #[getter]
71    #[pyo3(name = "value_floor")]
72    const fn py_value_floor(&self) -> f64 {
73        self.value_floor
74    }
75
76    #[getter]
77    #[pyo3(name = "value")]
78    const fn py_value(&self) -> f64 {
79        self.value
80    }
81
82    #[getter]
83    #[pyo3(name = "initialized")]
84    const fn py_initialized(&self) -> bool {
85        self.initialized
86    }
87
88    #[pyo3(name = "update_raw")]
89    fn py_update_raw(&mut self, high: f64, low: f64, close: f64) {
90        self.update_raw(high, low, close);
91    }
92
93    #[pyo3(name = "handle_quote_tick")]
94    const fn py_handle_quote_tick(&mut self, _quote: &QuoteTick) {
95        // Function body intentionally left blank.
96    }
97
98    #[pyo3(name = "handle_trade_tick")]
99    const fn py_handle_trade_tick(&mut self, _trade: &TradeTick) {
100        // Function body intentionally left blank.
101    }
102
103    #[pyo3(name = "handle_bar")]
104    fn py_handle_bar(&mut self, bar: &Bar) {
105        self.handle_bar(bar);
106    }
107
108    #[pyo3(name = "reset")]
109    fn py_reset(&mut self) {
110        self.reset();
111    }
112}