nautilus_indicators/python/average/
vidya.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::{
17    data::{Bar, QuoteTick, TradeTick},
18    enums::PriceType,
19};
20use pyo3::prelude::*;
21
22use crate::{
23    average::{MovingAverageType, vidya::VariableIndexDynamicAverage},
24    indicator::{Indicator, MovingAverage},
25};
26
27#[pymethods]
28impl VariableIndexDynamicAverage {
29    #[new]
30    #[pyo3(signature = (period, price_type=None, cmo_ma_type=None))]
31    #[must_use]
32    pub fn py_new(
33        period: usize,
34        price_type: Option<PriceType>,
35        cmo_ma_type: Option<MovingAverageType>,
36    ) -> Self {
37        Self::new(period, price_type, cmo_ma_type)
38    }
39
40    fn __repr__(&self) -> String {
41        format!(
42            "VariableIndexDynamicAverage({},{:?})",
43            self.period, self.price_type
44        )
45    }
46
47    #[getter]
48    #[pyo3(name = "name")]
49    fn py_name(&self) -> String {
50        self.name()
51    }
52
53    #[getter]
54    #[pyo3(name = "period")]
55    const fn py_period(&self) -> usize {
56        self.period
57    }
58
59    #[getter]
60    #[pyo3(name = "count")]
61    fn py_count(&self) -> usize {
62        self.count()
63    }
64
65    #[getter]
66    #[pyo3(name = "alpha")]
67    const fn py_alpha(&self) -> f64 {
68        self.alpha
69    }
70
71    #[getter]
72    #[pyo3(name = "has_inputs")]
73    fn py_has_inputs(&self) -> bool {
74        self.has_inputs()
75    }
76
77    #[getter]
78    #[pyo3(name = "initialized")]
79    const fn py_initialized(&self) -> bool {
80        self.initialized
81    }
82
83    #[getter]
84    #[pyo3(name = "cmo_pct")]
85    const fn py_cmo_pct(&self) -> f64 {
86        self.cmo_pct
87    }
88
89    #[getter]
90    #[pyo3(name = "value")]
91    const fn py_value(&self) -> f64 {
92        self.value
93    }
94
95    #[pyo3(name = "handle_quote_tick")]
96    fn py_handle_quote_tick(&mut self, quote: &QuoteTick) {
97        self.py_update_raw(quote.extract_price(self.price_type).into());
98    }
99
100    #[pyo3(name = "handle_trade_tick")]
101    fn py_handle_trade_tick(&mut self, trade: &TradeTick) {
102        self.update_raw((&trade.price).into());
103    }
104
105    #[pyo3(name = "handle_bar")]
106    fn py_handle_bar(&mut self, bar: &Bar) {
107        self.update_raw((&bar.close).into());
108    }
109
110    #[pyo3(name = "reset")]
111    fn py_reset(&mut self) {
112        self.reset();
113    }
114
115    #[pyo3(name = "update_raw")]
116    fn py_update_raw(&mut self, value: f64) {
117        self.update_raw(value);
118    }
119}