Skip to main content

nautilus_indicators/python/momentum/
ichimoku.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::{indicator::Indicator, momentum::ichimoku::IchimokuCloud};
20
21#[pymethods]
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23impl IchimokuCloud {
24    /// Creates a new `IchimokuCloud` instance.
25    ///
26    /// The indicator becomes `initialized` after `senkou_period` bars,
27    /// at which point `tenkan_sen` and `kijun_sen` are valid. The displaced
28    /// outputs (`senkou_span_a`, `senkou_span_b`, `chikou_span`) require an
29    /// additional `displacement` bars before they become non-zero.
30    #[new]
31    #[pyo3(signature = (tenkan_period=9, kijun_period=26, senkou_period=52, displacement=26))]
32    #[must_use]
33    pub fn py_new(
34        tenkan_period: usize,
35        kijun_period: usize,
36        senkou_period: usize,
37        displacement: usize,
38    ) -> Self {
39        Self::new(tenkan_period, kijun_period, senkou_period, displacement)
40    }
41
42    fn __repr__(&self) -> String {
43        format!("{self}")
44    }
45
46    #[getter]
47    #[pyo3(name = "name")]
48    fn py_name(&self) -> String {
49        self.name()
50    }
51
52    #[getter]
53    #[pyo3(name = "tenkan_period")]
54    const fn py_tenkan_period(&self) -> usize {
55        self.tenkan_period
56    }
57
58    #[getter]
59    #[pyo3(name = "kijun_period")]
60    const fn py_kijun_period(&self) -> usize {
61        self.kijun_period
62    }
63
64    #[getter]
65    #[pyo3(name = "senkou_period")]
66    const fn py_senkou_period(&self) -> usize {
67        self.senkou_period
68    }
69
70    #[getter]
71    #[pyo3(name = "displacement")]
72    const fn py_displacement(&self) -> usize {
73        self.displacement
74    }
75
76    #[getter]
77    #[pyo3(name = "has_inputs")]
78    fn py_has_inputs(&self) -> bool {
79        self.has_inputs()
80    }
81
82    #[getter]
83    #[pyo3(name = "tenkan_sen")]
84    const fn py_tenkan_sen(&self) -> f64 {
85        self.tenkan_sen
86    }
87
88    #[getter]
89    #[pyo3(name = "kijun_sen")]
90    const fn py_kijun_sen(&self) -> f64 {
91        self.kijun_sen
92    }
93
94    #[getter]
95    #[pyo3(name = "senkou_span_a")]
96    const fn py_senkou_span_a(&self) -> f64 {
97        self.senkou_span_a
98    }
99
100    #[getter]
101    #[pyo3(name = "senkou_span_b")]
102    const fn py_senkou_span_b(&self) -> f64 {
103        self.senkou_span_b
104    }
105
106    #[getter]
107    #[pyo3(name = "chikou_span")]
108    const fn py_chikou_span(&self) -> f64 {
109        self.chikou_span
110    }
111
112    #[getter]
113    #[pyo3(name = "initialized")]
114    const fn py_initialized(&self) -> bool {
115        self.initialized
116    }
117
118    /// Updates the indicator with OHLC values.
119    #[pyo3(name = "update_raw")]
120    fn py_update_raw(&mut self, high: f64, low: f64, close: f64) {
121        self.update_raw(high, low, close);
122    }
123
124    #[pyo3(name = "handle_bar")]
125    fn py_handle_bar(&mut self, bar: &Bar) {
126        self.handle_bar(bar);
127    }
128
129    #[pyo3(name = "reset")]
130    fn py_reset(&mut self) {
131        self.reset();
132    }
133}