Skip to main content

nautilus_indicators/python/volatility/
rvi.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::{
20    average::MovingAverageType, indicator::Indicator, volatility::rvi::RelativeVolatilityIndex,
21};
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl RelativeVolatilityIndex {
26    /// An indicator which calculates a Relative Volatility Index (RVI) across a rolling window.
27    #[new]
28    #[pyo3(signature = (period, scalar=None, ma_type=None))]
29    #[must_use]
30    pub fn py_new(period: usize, scalar: Option<f64>, ma_type: Option<MovingAverageType>) -> Self {
31        Self::new(period, scalar, ma_type)
32    }
33
34    fn __repr__(&self) -> String {
35        format!(
36            "RelativeVolatilityIndex({},{},{},{})",
37            self.period, self.ma_type, self.scalar, self.ma_type,
38        )
39    }
40
41    #[getter]
42    #[pyo3(name = "name")]
43    fn py_name(&self) -> String {
44        self.name()
45    }
46
47    #[getter]
48    #[pyo3(name = "period")]
49    const fn py_period(&self) -> usize {
50        self.period
51    }
52
53    #[getter]
54    #[pyo3(name = "scalar")]
55    const fn py_scalar(&self) -> f64 {
56        self.scalar
57    }
58
59    #[getter]
60    #[pyo3(name = "has_inputs")]
61    fn py_has_inputs(&self) -> bool {
62        self.has_inputs()
63    }
64
65    #[getter]
66    #[pyo3(name = "value")]
67    const fn py_value(&self) -> f64 {
68        self.value
69    }
70
71    #[getter]
72    #[pyo3(name = "initialized")]
73    const fn py_initialized(&self) -> bool {
74        self.initialized
75    }
76
77    #[pyo3(name = "update_raw")]
78    fn py_update_raw(&mut self, close: f64) {
79        self.update_raw(close);
80    }
81
82    #[pyo3(name = "handle_quote_tick")]
83    const fn py_handle_quote_tick(&mut self, _quote: &QuoteTick) {
84        // Function body intentionally left blank.
85    }
86
87    #[pyo3(name = "handle_trade_tick")]
88    const fn py_handle_trade_tick(&mut self, _trade: &TradeTick) {
89        // Function body intentionally left blank.
90    }
91
92    #[pyo3(name = "handle_bar")]
93    fn py_handle_bar(&mut self, bar: &Bar) {
94        self.update_raw((&bar.close).into());
95    }
96
97    #[pyo3(name = "reset")]
98    fn py_reset(&mut self) {
99        self.reset();
100    }
101}