yata/lib.rs
1/*
2
3Copyright 2020 AMvDev (amv-dev@protonmail.com)
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17*/
18#![warn(
19 missing_docs,
20 missing_debug_implementations,
21 missing_copy_implementations,
22 trivial_casts,
23 trivial_numeric_casts,
24 unsafe_code,
25 unstable_features,
26 unused_import_braces,
27 unused_qualifications
28)]
29#![deny(clippy::all)]
30#![deny(clippy::pedantic)]
31#![allow(clippy::module_name_repetitions)]
32#![allow(clippy::cast_lossless)]
33#![allow(clippy::missing_errors_doc)]
34#![allow(clippy::cast_precision_loss)]
35#![allow(renamed_and_removed_lints)] // workaround clippy unknown lints when rust stable 1.50. May be removed in the future
36#![allow(clippy::unknown_clippy_lints)] // workaround clippy unknown lints when rust stable 1.50. May be removed in the future
37#![allow(unknown_lints)] // workaround clippy unknown lints when rust stable 1.50. May be removed in the future
38#![allow(clippy::upper_case_acronyms)]
39#![deny(clippy::nursery)]
40#![allow(clippy::use_self)]
41#![cfg_attr(feature = "period_type_u64", allow(clippy::cast_possible_truncation))]
42
43//! Yet Another Technical Analysis library
44//!
45//! `YaTa` implements most common technical analysis [methods] and [indicators]
46//!
47//! It also provides you an interface to create your own indicators.
48//!
49//! ## Available **moving averages**:
50//!
51//! - [Simple moving average (SMA)](crate::methods::SMA);
52//! - [Weighted moving average (WMA)](crate::methods::WMA);
53//! - Exponential moving average family: [EMA](crate::methods::EMA), [DMA](crate::methods::DMA), [TMA](crate::methods::TMA),
54//! [DEMA](crate::methods::DEMA), [TEMA](crate::methods::TEMA);
55//! - [Simple moving median (SMM)](crate::methods::SMM);
56//! - [Linear regression moving average (LSMA)](crate::methods::LinReg);
57//! - [Volume weighted moving average (VWMA)](crate::methods::VWMA);
58//! - [Symmetrically weighted moving average (SWMA)](crate::methods::SWMA);
59//! - [Hull moving average (HMA)](crate::methods::HMA);
60//! - [Running Moving Average (RMA)](crate::methods::RMA);
61//! - [Triangular Moving Average (TRIMA)](crate::methods::TRIMA);
62//! - [Wilder’s Smoothing Average (WSMA)](crate::methods::WSMA);
63//! - [Kaufman Adaptive Moving Average (KAMA)](crate::indicators::Kaufman);
64//! - [Convolution Moving Average](crate::methods::Conv);
65//! - [Variable Index Dynamic Average (Vidya)](crate::methods::Vidya);
66//!
67//! [See all](crate::methods#structs)
68//!
69//! ## Timeseries conversion
70//!
71//! - [Timeframe Collapsing](crate::methods::CollapseTimeframe);
72//! - [Heikin Ashi](crate::methods::HeikinAshi);
73//! - [Renko](crate::methods::Renko);
74//!
75//! ## Some commonly used **methods**:
76//!
77//! - [Accumulation-distribution index](crate::methods::ADI);
78//! - [Commodity channel index](crate::methods::CCI);
79//! - [`Cross`](crate::methods::Cross) / [`CrossAbove`](crate::methods::CrossAbove) / [`CrossUnder`](crate::methods::CrossUnder);
80//! - [Derivative](crate::methods::Derivative) (differential);
81//! - [Highest](crate::methods::Highest) / [Lowest](crate::methods::Lowest) / [Highest-Lowest Delta](crate::methods::HighestLowestDelta);
82//! - [Highest Index](crate::methods::HighestIndex) / [Lowest Index](crate::methods::LowestIndex);
83//! - [Integral](crate::methods::Integral) (sum);
84//! - [Mean absolute deviation](crate::methods::MeanAbsDev);
85//! - [Median absolute deviation](crate::methods::MedianAbsDev);
86//! - [Momentum](crate::methods::Momentum);
87//! - [Past](crate::methods::Past);
88//! - [Rate Of Change](crate::methods::RateOfChange) (ROC);
89//! - [Reversal points](crate::methods::ReversalSignal);
90//! - [Standard Deviation](crate::methods::StDev);
91//! - [True Range](crate::methods::TR);
92//! - [True Strength Index](crate::methods::TSI);
93//! - [Volatility](crate::methods::LinearVolatility);
94//!
95//! [See all](crate::methods#structs)
96//!
97//! ## Some commonly used **indicators**:
98//!
99//! - Average Directional Index;
100//! - Awesome Oscillator;
101//! - Bollinger Bands;
102//! - Commodity Channel Index;
103//! - Detrended Price Oscillator;
104//! - Ease Of Movement;
105//! - Elders Force Index;
106//! - Envelopes;
107//! - Fisher Transform;
108//! - Ichimoku Cloud;
109//! - Keltner Channels;
110//! - Moving Average Convergence Divergence (MACD);
111//! - Money Flow Index;
112//! - Price Channel Strategy;
113//! - Relative Strength Index (RSI);
114//! - Stochastic Oscillator;
115//! - Trix;
116//! - Woodies CCI;
117//!
118//! And many others: [See Full list](crate::indicators#structs)
119//!
120//! ## Method usage example
121//!
122//! ```
123//! use yata::prelude::*;
124//! use yata::methods::EMA;
125//!
126//! // EMA of length=3
127//! let mut ema = EMA::new(3, &3.0).unwrap();
128//!
129//! ema.next(&3.0);
130//! ema.next(&6.0);
131//!
132//! assert_eq!(ema.next(&9.0), 6.75);
133//! assert_eq!(ema.next(&12.0), 9.375);
134//! ```
135//!
136//! ## Indicator usage example
137//!
138//! ```
139//! use yata::helpers::{RandomCandles, MA};
140//! use yata::indicators::MACD;
141//! use yata::prelude::*;
142//!
143//! let mut candles = RandomCandles::new();
144//! let mut macd = MACD::default();
145//!
146//! macd.ma1 = "sma-4".parse().unwrap(); // one way of defining methods inside indicators
147//!
148//! macd.signal = MA::TEMA(5); // another way of defining methods inside indicators
149//!
150//! let mut macd = macd.init(&candles.first()).unwrap();
151//!
152//! for candle in candles.take(10) {
153//! let result = macd.next(&candle);
154//!
155//! println!("{:?}", result);
156//! }
157//! ```
158//!
159//! ## Current usafe status
160//!
161//! By default, there is no `unsafe` code in the crate. But you can optionally enable `unsafe_performance` feature throw you `Cargo.toml` or by `--feature` flag in your CLI.
162//!
163//! `usafe_performance` enables some unsafe code blocks, most of them are unsafe access to a vector's elements. For some methods it may increase performance by ~5-10%.
164//!
165//! ## Suggestions
166//!
167//! You are welcome to give any suggestions about new indicators and methods
168//!
169//! # Say thanks
170//!
171//! If you like this library and you want to say thanks, you can do it also by donating to bitcoin address `1P3gTnaTK9LKSYx2nETrKe2zjP4HMkdhvK`
172
173pub mod core;
174pub mod helpers;
175pub mod indicators;
176pub mod methods;
177
178#[cfg(all(feature = "period_type_u64", target_pointer_width = "32"))]
179compile_error!("Feature `period_type_u64` can't be used on 32-bit machines");
180
181#[cfg(all(
182 any(feature = "period_type_u32", feature = "period_type_u64"),
183 target_pointer_width = "16"
184))]
185compile_error!("Features `period_type_u64` and `period_type_u32` can't be used on 16-bit machines");
186
187/// Contains main traits you need to start using this library
188pub mod prelude {
189 pub use super::core::{
190 Candle, Error, IndicatorConfig, IndicatorInstance, Method, Sequence, OHLCV,
191 };
192
193 pub use super::helpers::{Buffered, Peekable};
194
195 /// Dynamically dispatchable traits for indicators creation
196 pub mod dd {
197 pub use crate::core::{IndicatorConfigDyn, IndicatorInstanceDyn};
198 }
199}