algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::math Namespace Reference

The numeric vocabulary: Scalar, missing(), and the matrix and vector types. More...

Classes

struct  Observed
 A series split into zero-filled values and a presence mask, for sums that skip gaps. More...

Typedefs

using Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
 A dense, column-major matrix of Scalar.
using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>
 A dense column vector of Scalar.
using SeriesView = Eigen::Ref<const Vector>
 A read-only reference to one series.
using MutableSeriesView = Eigen::Ref<Vector>
 A writable reference to one series, such as a Vector or a column of a Matrix.
using MatrixView = Eigen::Ref<const Matrix>
 A read-only reference to a whole matrix.
using Index = Eigen::Index
 The signed index type of rows and columns.
using Scalar = double
 The floating-point type the analytics and math layers compute in (double).

Functions

Vector unobserved (std::size_t count)
 Makes a vector filled with missing().
Matrix unobserved (std::size_t rows, std::size_t columns)
 Makes a matrix filled with missing().
Observed observed_parts (SeriesView values)
 Splits a series into zero-filled values and a presence mask.
Scalar missing ()
 Returns the value that stands for "no observation" (a quiet NaN).
bool observed (Scalar value)
 Tests whether a value is an observation.
Scalar undefined ()
 Returns the value that stands for "the data was there, but the statistic does not exist".
bool is_undefined (Scalar value)
 Tests whether a value is the undefined() marker.

Detailed Description

The numeric vocabulary: Scalar, missing(), and the matrix and vector types.

Typedef Documentation

◆ Index

using algotradelib::math::Index = Eigen::Index

The signed index type of rows and columns.

Definition at line 47 of file eigen.hpp.

◆ Matrix

using algotradelib::math::Matrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>

A dense, column-major matrix of Scalar.

Frames put time on the rows and one series per column, so a column binds to SeriesView without a copy.

Definition at line 27 of file eigen.hpp.

◆ MatrixView

using algotradelib::math::MatrixView = Eigen::Ref<const Matrix>

A read-only reference to a whole matrix.

Definition at line 44 of file eigen.hpp.

◆ MutableSeriesView

A writable reference to one series, such as a Vector or a column of a Matrix.

Definition at line 41 of file eigen.hpp.

◆ Scalar

The floating-point type the analytics and math layers compute in (double).

Prices, quantities and money in orders and broker data stay Decimal64; convert between the two with the functions in analytics/conversion.hpp.

Definition at line 18 of file scalar.hpp.

◆ SeriesView

using algotradelib::math::SeriesView = Eigen::Ref<const Vector>

A read-only reference to one series.

Binds without copying to a Vector or a column of a Matrix, and to an expression (which is evaluated into a temporary). Functions over one series take this type.

Definition at line 38 of file eigen.hpp.

◆ Vector

using algotradelib::math::Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>

A dense column vector of Scalar.

Definition at line 30 of file eigen.hpp.

Function Documentation

◆ is_undefined()

bool algotradelib::math::is_undefined ( Scalar value)
inline

Tests whether a value is the undefined() marker.

Parameters
valueThe value to test.
Returns
true only for undefined() (including a negated copy); false for missing(), any other NaN and every number.
See also
undefined() for when the marker survives.

Definition at line 73 of file scalar.hpp.

Referenced by is_undefined().

◆ missing()

Scalar algotradelib::math::missing ( )
inline

Returns the value that stands for "no observation" (a quiet NaN).

Used for an indicator's warm-up rows, a gap in a panel, or a field a broker did not report. Every reduction in the analytics layer skips it.

Returns
A quiet NaN.

Definition at line 28 of file scalar.hpp.

Referenced by algotradelib::backtest::chain_results(), algotradelib::backtest::measure_input(), missing(), algotradelib::analytics::SeriesBuffer::push(), unobserved(), and unobserved().

◆ observed()

bool algotradelib::math::observed ( Scalar value)
inline

Tests whether a value is an observation.

Parameters
valueThe value to test.
Returns
false for missing(), undefined() or any other NaN; true otherwise.

Definition at line 38 of file scalar.hpp.

Referenced by observed().

◆ observed_parts()

Observed algotradelib::math::observed_parts ( SeriesView values)
inline

Splits a series into zero-filled values and a presence mask.

Parameters
valuesThe series; any NaN counts as unobserved.
Returns
The two parts; see Observed.

Definition at line 95 of file eigen.hpp.

Referenced by observed_parts().

◆ undefined()

Scalar algotradelib::math::undefined ( )
inline

Returns the value that stands for "the data was there, but the statistic does not exist".

Examples: a z-score over a window with no dispersion, a Sortino ratio over a series that never fell below its target. It differs from missing(), which means there was no data. Both are quiet NaNs, so observed() is false for both and reductions skip both; only is_undefined() tells them apart.

Returns
A quiet NaN with a payload that is_undefined() recognizes.
Warning
Test is_undefined() on a value a function returned (or one copied from a matrix). Arithmetic on it, such as undefined() + 1.0, yields a NaN that may no longer be recognized.

Definition at line 55 of file scalar.hpp.

Referenced by algotradelib::analytics::max_drawdown(), and undefined().

◆ unobserved() [1/2]

Vector algotradelib::math::unobserved ( std::size_t count)
inline

Makes a vector filled with missing().

Parameters
countThe number of entries.
Returns
A vector of count unobserved values.

Definition at line 55 of file eigen.hpp.

Referenced by algotradelib::analytics::SeriesBuffer::SeriesBuffer(), unobserved(), and unobserved().

◆ unobserved() [2/2]

Matrix algotradelib::math::unobserved ( std::size_t rows,
std::size_t columns )
inline

Makes a matrix filled with missing().

Parameters
rowsThe number of rows.
columnsThe number of columns.
Returns
A rows by columns matrix of unobserved values.

Definition at line 66 of file eigen.hpp.