nautilus_indicators/python/ratio/spread_analyzer.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::QuoteTick, identifiers::InstrumentId};
17use pyo3::prelude::*;
18
19use crate::{indicator::Indicator, ratio::spread_analyzer::SpreadAnalyzer};
20
21#[pymethods]
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23impl SpreadAnalyzer {
24 /// An indicator which calculates the efficiency ratio across a rolling window.
25 ///
26 /// The Kaufman Efficiency measures the ratio of the relative market speed in
27 /// relation to the volatility, this could be thought of as a proxy for noise.
28 #[new]
29 fn py_new(instrument_id: InstrumentId, capacity: usize) -> Self {
30 Self::new(capacity, instrument_id)
31 }
32
33 fn __repr__(&self) -> String {
34 format!("SpreadAnalyzer({})", self.capacity)
35 }
36
37 #[getter]
38 #[pyo3(name = "name")]
39 fn py_name(&self) -> String {
40 self.name()
41 }
42
43 #[getter]
44 #[pyo3(name = "capacity")]
45 const fn py_capacity(&self) -> usize {
46 self.capacity
47 }
48
49 #[getter]
50 #[pyo3(name = "current")]
51 const fn py_current(&self) -> f64 {
52 self.current
53 }
54
55 #[getter]
56 #[pyo3(name = "average")]
57 const fn py_average(&self) -> f64 {
58 self.average
59 }
60
61 #[getter]
62 #[pyo3(name = "initialized")]
63 const fn py_initialized(&self) -> bool {
64 self.initialized
65 }
66
67 #[getter]
68 #[pyo3(name = "has_inputs")]
69 fn py_has_inputs(&self) -> bool {
70 self.has_inputs()
71 }
72
73 #[pyo3(name = "handle_quote_tick")]
74 fn py_handle_quote_tick(&mut self, quote: &QuoteTick) {
75 self.handle_quote(quote);
76 }
77
78 #[pyo3(name = "reset")]
79 fn py_reset(&mut self) {
80 self.reset();
81 }
82}