Crate sliding_features
source ·Expand description
Sliding Features
Modular, chainable sliding windows with various signal processing functions and technical indicators.
A View
defines the function which processes the incoming values and provides an output value.
View
’s can easily be added by implementing the Trait which requires two methods:
update(&mut self, val: f64)
: Call whenever you have a new value with which to update the Viewlast(&self) -> f64
: Retrieve the last value from the View
This enables multiple View
’s to be chained together to apply many signal processing functions consecutively.
For example you may want to compose a chained function that firstly smoothes the input values using an EMA
,
applies the rate of change ROC
function and finally applies normalization to it
HLNormalizer
.
This can be achieved as such:
let mut chain = HLNormalizer::new(ROC:new(EMA::new(Echo::new(), 10), 15), 20);
Imagine this process as a tree with nodes (which is more accurate) as you can merge multiple Views
together.
An example of such a combining node is the Add
node for example.
How to use
To use this crate in your project add this to your Cargo.toml:
sliding_features = "2.5.3"
To create a new View, call the appropriate constructor as such:
let mut rsi = RSI::new(Echo::new(), 16);
This creates an RSI indicator with window length of 16. Notice that Echo will always be at the end of a View chain, as it just returns the latest observed value. Now to update the values of the chain, assuming test_values contains f64 values:
for v in &test_values {
rsi.update(v);
let last = rsi.last();
println!("latest rsi value: {}", last);
}
Each View will first call it’s chained View to get it’s last value, which will then be used to update the state of the View. Some Views have additional parameters such as ALMA.
Examples
See examples folder for some code ideas
cargo run --release --example basic_single_view
cargo run --release --example basic_chainable_view
Views
A View defines the function which processes value updates. They currently include:
- Echo
- Technical Indicators
- Center of Gravity
- Cyber Cycle
- Laguerre RSI
- Laguerre Filter
- ReFlex
- TrendFlex
- ROC
- RSI
- MyRSI (RSI in range [-1.0, 1.0])
- NET (John Ehlers noise elimination technology using kendall correlation)
- Correlation Trend Indicator (CTI)
- Polarized Fractal Efficiency
- Ehlers Fisher Transform
- SuperSmoother by JohnEhlers
- RoofingFilter by JohnEhlers
- Normalization / variance / mean standardization
- HLNormalizer, a sliding high-low normalizer
- Variance Stabilizing Transform (VST)
- Variance Stabilizing Centering Transform (VSCT)
- Moving Averages
- ALMA (Arnaux Legoux Moving Average)
- SMA (Simple Moving Average)
- EMA (Exponential Moving Average)
- Math combinations of Views
- Add
- Subtract
- Multiply
- Divide
- Math functions
- Tanh
- GTE - Greater Than or Equal clipping function
- LTE - Lower Than or Equal clipping function
- Standard deviation sliding window estimation using WelfordOnlineSliding
- Cumulative
- Entropy
Images
Underlying data synthetically generated by MathisWellmann/time_series_generator-rs using a standard normal (gaussian) process. Note that each run uses common test data from test_data.rs for consistency.























TODOs:
Feel free to implement the following and create a PR for some easy open-source contributions:
- FRAMA
- MAMA
- FAMA
- Stochastic
- Zero Lag
- gaussian filter
- correlation cycle indicator
- some indicators can be built with const sized arrays, for better performance
- add Default impl for all
- and so much more…
Contributing
If you have a sliding window function or indicator which you would like to integrate, feel free to create a pull request. Any help is highly appreciated. Let’s build the greatest sliding window library together :handshake:
Donations :moneybag: :money_with_wings:
I you would like to support the development of this crate, feel free to send over a donation:
Monero (XMR) address:
47xMvxNKsCKMt2owkDuN1Bci2KMiqGrAFCQFSLijWLs49ua67222Wu3LZryyopDVPYgYmAnYkSZSz9ZW2buaDwdyKTWGwwb
License
Copyright (C) 2020 <MathisWellmann wellmannmathis@gmail.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
The sliding_features crate provides modular, chainable sliding windows
for various signal processing function and technical indicators
Structs
- ALMA - Arnaud Legoux Moving Average reference: https://forex-station.com/download/file.php?id=3326661&sid=d6b440bfbba5e1905b4c75188c2797ce
- Add View a to b
- Shannon entropy sliding window over values, where a positive / negative values are interpreted as true / false
- John Ehlers Center of Gravity Indicator from: https://mesasoftware.com/papers/TheCGOscillator.pdf
- Provides a float value to other views
- John Ehlers Correlation Trend Indicator from: https://financial-hacker.com/petra-on-programming-a-unique-trend-indicator/
- Cumulative Sliding Window with a chained view
- John Ehlers Cyber Cycle Indicator from: https://www.mesasoftware.com/papers/TheInverseFisherTransform.pdf
- Divide View a by b
- EMA - Exponential Moving Average
- Echo always return the last value just like an echo
- John Ehlers Fisher Transform Indicator from: http://www.mesasoftware.com/papers/UsingTheFisherTransform.pdf
- Greater Than or Equal Will allow values >= clipping_point tough and clip other values to the clipping point
- A sliding High - Low Normalizer
- Lower Than or Equal filter, which only allows values lower than the specified clipping point through
- John Ehlers Laguerre Filter from: http://mesasoftware.com/papers/TimeWarp.pdf
- John Ehlers LaguerreRSI from: http://mesasoftware.com/papers/TimeWarp.pdf
- Multiply View a by b
- John Ehlers MyRSI from: http://www.mesasoftware.com/papers/Noise%20Elimination%20Technology.pdf
- John Ehlers Noise elimination technology using kendall correlation from http://www.mesasoftware.com/papers/Noise%20Elimination%20Technology.pdf
- A PolarizedFractalEfficiency indicator with output range [-1.0 and 1.0] rather than [-100, 100] it is also possible to use a custom moving average instead of the default EMA in the original
- Rate of Change Indicator
- Relative Strength Index Indicator
- John Ehlers ReFlex Indicator from: https://financial-hacker.com/petra-on-programming-a-new-zero-lag-indicator/
- Roofing Filter by John Ehlers From paper: http://www.stockspotter.com/files/PredictiveIndicators.pdf
- SMA - Simple Moving Average
- Subtract View a from b
- John Ehlers SuperSmoother filter from https://www.mesasoftware.com/papers/PredictiveIndicatorsForEffectiveTrading%20Strategies.pdf
- Applies the Tanh function to the output of its View component
- John Ehlers TrendFlex Indicators from: https://financial-hacker.com/petra-on-programming-a-new-zero-lag-indicator/
- Variance Stabilizing Centering Transform Sliding Window
- Variance Stabilizing Transform uses the standard deviation to normalize values
- Welford online algorithm for computing mean and variance on-the-fly over a sliding window
Traits
- The most important Trait, defining methods which each sliding feature needs to implement