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

Performance metrics: maximum drawdown, Sharpe and Sortino ratios, annualization, turnover. More...

#include "./numeric.hpp"
#include <cmath>
#include <cstddef>
#include <stdexcept>
Include dependency graph for metrics.hpp:

Go to the source code of this file.

Classes

struct  algotradelib::analytics::MaxDrawdown
 The worst peak-to-trough decline of a level series, and where it happened. More...

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.

Enumerations

enum class  algotradelib::analytics::TurnoverStart { algotradelib::analytics::FROM_CASH , algotradelib::analytics::SKIP }
 How turnover treats the first period. More...

Functions

MaxDrawdown algotradelib::analytics::max_drawdown (math::SeriesView levels)
 Finds the worst peak-to-trough decline of a level series.
Scalar algotradelib::analytics::sharpe (math::SeriesView period_returns, Scalar risk_free=Scalar{0})
 Computes the per-period Sharpe ratio, (mean(returns) - risk_free) / stdev(returns).
Scalar algotradelib::analytics::sortino (math::SeriesView period_returns, Scalar target=Scalar{0})
 Computes the per-period Sortino ratio, (mean(returns) - target) / downside_deviation.
Scalar algotradelib::analytics::annualize_ratio (Scalar ratio, Scalar periods_per_year)
 Annualizes a per-period ratio by multiplying it by sqrt(periods_per_year).
math::Vector algotradelib::analytics::one_way_turnover (math::MatrixView weights, TurnoverStart start=TurnoverStart::FROM_CASH)
 Computes the one-way turnover of each period, 0.5 * sum(|w[i] - w[i - 1]|).
math::Vector algotradelib::analytics::two_way_turnover (math::MatrixView weights, TurnoverStart start=TurnoverStart::FROM_CASH)
 Computes the two-way turnover of each period, sum(|w[i] - w[i - 1]|).

Detailed Description

Performance metrics: maximum drawdown, Sharpe and Sortino ratios, annualization, turnover.

Each function states the convention it implements. Ratios are per period; annualize them explicitly with annualize_ratio.

Definition in file metrics.hpp.