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// -------------------------------------------------------------------------------------------------
1516//! Moving average type indicators.
1718pub mod ama;
19pub mod dema;
20pub mod ema;
21pub mod hma;
22pub mod lr;
23pub mod rma;
24pub mod sma;
25pub mod vidya;
26pub mod vwap;
27pub mod wma;
2829use nautilus_model::enums::PriceType;
30use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
3132use crate::{
33 average::{
34 dema::DoubleExponentialMovingAverage, ema::ExponentialMovingAverage,
35 hma::HullMovingAverage, rma::WilderMovingAverage, sma::SimpleMovingAverage,
36 },
37 indicator::MovingAverage,
38};
3940#[repr(C)]
41#[derive(
42 Copy,
43 Clone,
44 Debug,
45 Display,
46 Hash,
47 PartialEq,
48 Eq,
49 PartialOrd,
50 Ord,
51 AsRefStr,
52 FromRepr,
53 EnumIter,
54 EnumString,
55)]
56#[strum(ascii_case_insensitive)]
57#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
58#[cfg_attr(
59 feature = "python",
60 pyo3::pyclass(eq, eq_int, module = "nautilus_trader.core.nautilus_pyo3.indicators")
61)]
62pub enum MovingAverageType {
63 Simple,
64 Exponential,
65 DoubleExponential,
66 Wilder,
67 Hull,
68}
6970pub struct MovingAverageFactory;
7172impl MovingAverageFactory {
73#[must_use]
74pub fn create(
75 moving_average_type: MovingAverageType,
76 period: usize,
77 ) -> Box<dyn MovingAverage + Send + Sync> {
78let price_type = Some(PriceType::Last);
7980match moving_average_type {
81 MovingAverageType::Simple => Box::new(SimpleMovingAverage::new(period, price_type)),
82 MovingAverageType::Exponential => {
83 Box::new(ExponentialMovingAverage::new(period, price_type))
84 }
85 MovingAverageType::DoubleExponential => {
86 Box::new(DoubleExponentialMovingAverage::new(period, price_type))
87 }
88 MovingAverageType::Wilder => Box::new(WilderMovingAverage::new(period, price_type)),
89 MovingAverageType::Hull => Box::new(HullMovingAverage::new(period, price_type)),
90 }
91 }
92}