template<typename T, std::size_t MaxSize = 1000>
TimeSeries class
Time series container using boost::circular_buffer.
| Template parameters | |
|---|---|
| T | Value type |
| MaxSize | Maximum number of points to store |
Efficient storage for time-ordered data with automatic old data removal. Supports various time series analysis operations including moving averages, trend detection, and seasonal decomposition.
Public types
- using value_type = T
- using time_point = TimePoint<T>
- using duration = std::chrono::steady_clock::duration
-
using buffer_type = boost::circular_buffer<time_
point>
Constructors, destructors, conversion operators
- TimeSeries()
- Default constructor.
Public functions
- void add(const T& value)
- Add a value with current timestamp.
- void add(std::chrono::steady_clock::time_point timestamp, const T& value)
- Add a value with specific timestamp.
- auto size() const -> std::size_t
- Get size of time series.
- auto empty() const -> bool
- Check if empty.
- auto latest() const -> boost::optional<T>
- Get most recent value.
- auto oldest() const -> boost::optional<T>
- Get oldest value.
- auto get_window(duration window_duration) const -> std::vector<T>
- Get values within time window.
- auto simple_moving_average(std::size_t periods) const -> std::vector<double>
- Calculate simple moving average.
- auto exponential_moving_average(double alpha) const -> std::vector<double>
- Calculate exponential moving average.
- auto linear_trend() const -> std::pair<double, double>
- Detect trend using linear regression.
- auto rate_of_change(std::size_t periods) const -> boost::optional<double>
- Calculate rate of change.
- auto detect_outliers(double threshold = 3.0) const -> std::vector<std::size_t>
- Detect outliers using z-score method.
- auto savitzky_golay_filter(std::size_t window_size, std::size_t poly_order) const -> std::vector<double>
- Apply Savitzky-Golay filter for smoothing.
- auto autocorrelation(std::size_t lag) const -> boost::optional<double>
- Calculate autocorrelation.
-
auto get_data() const -> std::vector<time_
point> - Get raw data points.
- void clear()
- Clear all data.
- auto resample(duration interval) const -> TimeSeries
- Resample time series to fixed intervals.
Function documentation
template<typename T, std::size_t MaxSize>
void liarsdice:: statistics:: TimeSeries<T, MaxSize>:: add(const T& value)
Add a value with current timestamp.
| Parameters | |
|---|---|
| value | Value to add |
template<typename T, std::size_t MaxSize>
void liarsdice:: statistics:: TimeSeries<T, MaxSize>:: add(std::chrono::steady_clock::time_point timestamp,
const T& value)
Add a value with specific timestamp.
| Parameters | |
|---|---|
| timestamp | Time point |
| value | Value to add |
template<typename T, std::size_t MaxSize>
std::size_t liarsdice:: statistics:: TimeSeries<T, MaxSize>:: size() const
Get size of time series.
| Returns | Number of data points |
|---|
template<typename T, std::size_t MaxSize>
bool liarsdice:: statistics:: TimeSeries<T, MaxSize>:: empty() const
Check if empty.
| Returns | True if no data points |
|---|
template<typename T, std::size_t MaxSize>
boost::optional<T> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: latest() const
Get most recent value.
| Returns | Optional containing last value |
|---|
template<typename T, std::size_t MaxSize>
boost::optional<T> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: oldest() const
Get oldest value.
| Returns | Optional containing first value |
|---|
template<typename T, std::size_t MaxSize>
std::vector<T> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: get_window(duration window_duration) const
Get values within time window.
| Parameters | |
|---|---|
| window_duration | Duration of window from now |
| Returns | Vector of values within window |
template<typename T, std::size_t MaxSize>
std::vector<double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: simple_moving_average(std::size_t periods) const
Calculate simple moving average.
| Parameters | |
|---|---|
| periods | Number of periods |
| Returns | Vector of moving averages |
template<typename T, std::size_t MaxSize>
std::vector<double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: exponential_moving_average(double alpha) const
Calculate exponential moving average.
| Parameters | |
|---|---|
| alpha | Smoothing factor (0 < alpha < 1) |
| Returns | Vector of EMAs |
template<typename T, std::size_t MaxSize>
std::pair<double, double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: linear_trend() const
Detect trend using linear regression.
| Returns | Pair of (slope, intercept) |
|---|
template<typename T, std::size_t MaxSize>
boost::optional<double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: rate_of_change(std::size_t periods) const
Calculate rate of change.
| Parameters | |
|---|---|
| periods | Number of periods to look back |
| Returns | Rate of change percentage |
template<typename T, std::size_t MaxSize>
std::vector<std::size_t> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: detect_outliers(double threshold = 3.0) const
Detect outliers using z-score method.
| Parameters | |
|---|---|
| threshold | Z-score threshold (default: 3) |
| Returns | Indices of outliers |
template<typename T, std::size_t MaxSize>
std::vector<double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: savitzky_golay_filter(std::size_t window_size,
std::size_t poly_order) const
Apply Savitzky-Golay filter for smoothing.
| Parameters | |
|---|---|
| window_size | Window size (must be odd) |
| poly_order | Polynomial order |
| Returns | Smoothed values |
template<typename T, std::size_t MaxSize>
boost::optional<double> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: autocorrelation(std::size_t lag) const
Calculate autocorrelation.
| Parameters | |
|---|---|
| lag | Lag value |
| Returns | Autocorrelation coefficient |
template<typename T, std::size_t MaxSize>
std::vector<time_ point> liarsdice:: statistics:: TimeSeries<T, MaxSize>:: get_data() const
Get raw data points.
| Returns | Vector of time points |
|---|
template<typename T, std::size_t MaxSize>
TimeSeries liarsdice:: statistics:: TimeSeries<T, MaxSize>:: resample(duration interval) const
Resample time series to fixed intervals.
| Parameters | |
|---|---|
| interval | Target interval duration |
| Returns | Resampled time series |