nautilus_indicators/python/volatility/
kp.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::kp::KeltnerPosition};
20
21#[pymethods]
22impl KeltnerPosition {
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!("KeltnerPosition({})", 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 = "value")]
86    const fn py_value(&self) -> f64 {
87        self.value
88    }
89
90    #[getter]
91    #[pyo3(name = "initialized")]
92    const fn py_initialized(&self) -> bool {
93        self.initialized
94    }
95
96    #[pyo3(name = "update_raw")]
97    fn py_update_raw(&mut self, high: f64, low: f64, close: f64) {
98        self.update_raw(high, low, close);
99    }
100
101    #[pyo3(name = "handle_bar")]
102    fn py_handle_bar(&mut self, bar: &Bar) {
103        self.handle_bar(bar);
104    }
105
106    #[pyo3(name = "reset")]
107    fn py_reset(&mut self) {
108        self.reset();
109    }
110}