algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
rolling.hpp File Reference

Trailing-window statistics: sums, means, deviations, extremes and moving averages. More...

#include "./numeric.hpp"
#include <cmath>
#include <cstddef>
#include <limits>
#include <stdexcept>
#include <string>
Include dependency graph for rolling.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  algotradelib
 The library: broker-neutral types (core), and the modules below.
namespace  algotradelib::analytics
 Returns, rolling statistics, indicators and performance metrics over numeric series.

Functions

math::Vector algotradelib::analytics::rolling_sum (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the trailing sum of the observed values.
math::Vector algotradelib::analytics::rolling_sum (math::SeriesView values, std::size_t window)
 Computes the trailing sum, requiring every row of the window.
math::Vector algotradelib::analytics::rolling_mean (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the trailing mean of the observed values.
math::Vector algotradelib::analytics::rolling_mean (math::SeriesView values, std::size_t window)
 Computes the trailing mean, requiring every row of the window.
math::Vector algotradelib::analytics::rolling_stdev (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the trailing sample standard deviation (divisor count - 1).
math::Vector algotradelib::analytics::rolling_stdev (math::SeriesView values, std::size_t window)
 Computes the trailing sample standard deviation, requiring every row of the window.
math::Vector algotradelib::analytics::rolling_min (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the trailing minimum of the observed values.
math::Vector algotradelib::analytics::rolling_min (math::SeriesView values, std::size_t window)
 Computes the trailing minimum, requiring every row of the window.
math::Vector algotradelib::analytics::rolling_max (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the trailing maximum of the observed values.
math::Vector algotradelib::analytics::rolling_max (math::SeriesView values, std::size_t window)
 Computes the trailing maximum, requiring every row of the window.
math::Vector algotradelib::analytics::sma (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the simple moving average; identical to rolling_mean.
math::Vector algotradelib::analytics::sma (math::SeriesView values, std::size_t window)
 Computes the simple moving average, requiring every row of the window.
math::Vector algotradelib::analytics::wma (math::SeriesView values, std::size_t window, std::size_t min_observed)
 Computes the linearly weighted moving average.
math::Vector algotradelib::analytics::wma (math::SeriesView values, std::size_t window)
 Computes the linearly weighted moving average, requiring every row of the window.
Scalar algotradelib::analytics::alpha_from_span (std::size_t span)
 Converts an EMA span to its smoothing factor, 2 / (span + 1).
Scalar algotradelib::analytics::ema_step (Scalar level, Scalar value, Scalar alpha)
 Advances an exponential moving average by one value.
Scalar algotradelib::analytics::ema_step (Scalar level, Scalar value, std::size_t span)=delete
 Deleted: an integer here would be a span. Pass alpha_from_span(span) instead.
math::Vector algotradelib::analytics::ema (math::SeriesView values, Scalar alpha, std::size_t min_observed=1)
 Computes the exponentially weighted moving average of a series.
math::Vector algotradelib::analytics::ema (math::SeriesView values, std::size_t span, std::size_t min_observed=1)=delete
 Deleted: an integer here would be a span. Write ema(values, alpha_from_span(span)).

Detailed Description

Trailing-window statistics: sums, means, deviations, extremes and moving averages.

Every series function returns a series as long as its input: row i of the result describes the window ending at row i of the input. A row that cannot be computed is missing().

Two numbers describe a window:

  • window is how many trailing rows are looked at, whether or not they carry a value;
  • min_observed is how many of those rows must carry a value before a result is reported.

Unobserved values inside a window are skipped, and the statistic is computed over the values that are there. rolling_mean(closes, 20, 15) reports as soon as 15 of the 20 rows are observed. The overloads without min_observed require every row of the window.

Definition in file rolling.hpp.