nautilus_indicators/python/volatility/
kc.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;
17use pyo3::prelude::*;
18
19use crate::{average::MovingAverageType, indicator::Indicator, volatility::kc::KeltnerChannel};
20
21#[pymethods]
22impl KeltnerChannel {
23    #[new]
24    #[pyo3(signature = (period, k_multiplier, ma_type=None, ma_type_atr=None, use_previous=None, atr_floor=None))]
25    #[must_use]
26    pub fn py_new(
27        period: usize,
28        k_multiplier: f64,
29        ma_type: Option<MovingAverageType>,
30        ma_type_atr: Option<MovingAverageType>,
31        use_previous: Option<bool>,
32        atr_floor: Option<f64>,
33    ) -> Self {
34        Self::new(
35            period,
36            k_multiplier,
37            ma_type,
38            ma_type_atr,
39            use_previous,
40            atr_floor,
41        )
42    }
43
44    fn __repr__(&self) -> String {
45        format!("KeltnerChannel({})", self.period)
46    }
47
48    #[getter]
49    #[pyo3(name = "name")]
50    fn py_name(&self) -> String {
51        self.name()
52    }
53
54    #[getter]
55    #[pyo3(name = "period")]
56    const fn py_period(&self) -> usize {
57        self.period
58    }
59
60    #[getter]
61    #[pyo3(name = "k_multiplier")]
62    const fn py_k_multiplier(&self) -> f64 {
63        self.k_multiplier
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 = "atr_floor")]
74    const fn py_atr_floor(&self) -> f64 {
75        self.atr_floor
76    }
77
78    #[getter]
79    #[pyo3(name = "has_inputs")]
80    fn py_has_inputs(&self) -> bool {
81        self.has_inputs()
82    }
83
84    #[getter]
85    #[pyo3(name = "upper")]
86    const fn py_upper(&self) -> f64 {
87        self.upper
88    }
89
90    #[getter]
91    #[pyo3(name = "middle")]
92    const fn py_middle(&self) -> f64 {
93        self.middle
94    }
95
96    #[getter]
97    #[pyo3(name = "lower")]
98    const fn py_lower(&self) -> f64 {
99        self.lower
100    }
101
102    #[getter]
103    #[pyo3(name = "initialized")]
104    const fn py_initialized(&self) -> bool {
105        self.initialized
106    }
107
108    #[pyo3(name = "update_raw")]
109    fn py_update_raw(&mut self, high: f64, low: f64, close: f64) {
110        self.update_raw(high, low, close);
111    }
112
113    #[pyo3(name = "handle_bar")]
114    fn py_handle_bar(&mut self, bar: &Bar) {
115        self.handle_bar(bar);
116    }
117
118    #[pyo3(name = "reset")]
119    fn py_reset(&mut self) {
120        self.reset();
121    }
122}