Skip to main content

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