![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The strategies this library ships (buy and hold, crossovers, mean reversion, sizing, liquidation). More...
Classes | |
| struct | BuyAndHold |
| Holds a fixed quantity of one instrument. More... | |
| struct | Crossing |
| The last two values of an indicator line, for testing a crossing. More... | |
| struct | DonchianBreakout |
| Donchian channel breakout: holds after the close breaks above the channel, exits after it breaks below. More... | |
| struct | EmaCrossover |
| MovingAverageCrossover with exponential averages. More... | |
| struct | EqualWeightRebalance |
| Holds an equal fraction of portfolio value in each instrument of a universe. More... | |
| struct | MovingAverageCrossover |
| Holds quantity_ shares while the fast moving average is above the slow one, and is flat otherwise. More... | |
| struct | RsiThreshold |
| Long-only RSI strategy: buys when the index is oversold, sells when it is overbought. More... | |
| struct | SmaCrossover |
| MovingAverageCrossover with simple averages. More... | |
| struct | TimedLiquidation |
| Flattens every position when the market enters a phase it should not hold through. More... | |
| struct | VolatilityTargetSizing |
| Holds a long position sized so its value volatility per bar matches a risk budget. More... | |
| struct | ZScoreReversion |
| Long-only mean reversion on the z-score of the close. More... | |
Enumerations | |
| enum class | AverageKind { SIMPLE , EXPONENTIAL } |
| Which moving average MovingAverageCrossover uses. More... | |
Functions | |
| std::optional< Crossing > | last_two (const math::Vector &line) |
| Returns the last two values of a line. | |
| math::Vector | adjusted_ema (math::SeriesView values, math::Scalar alpha, std::size_t min_observed=1) |
| Computes the bias-adjusted exponential moving average. | |
| math::Vector | exponential_line (math::SeriesView closes, std::size_t span) |
| Computes the exponential moving average MovingAverageCrossover reads. | |
| std::optional< math::SeriesView > | trailing (math::SeriesView values, std::size_t count) |
| Returns the last count + 1 rows of a series. | |
The strategies this library ships (buy and hold, crossovers, mean reversion, sizing, liquidation).
|
strong |
Which moving average MovingAverageCrossover uses.
| Enumerator | |
|---|---|
| SIMPLE | The simple mean of the window. |
| EXPONENTIAL | An exponential average with alpha = 2 / (span + 1), over every cached bar. |
Definition at line 33 of file crossover.hpp.
|
inline |
Computes the bias-adjusted exponential moving average.
At each row, the exponentially weighted mean of the observations so far, with weights 1, q, q^2, ... (newest first, q = 1 - alpha) normalized to sum to one. On finite observed rows it equals pandas' ewm(alpha=alpha, adjust=True, ignore_na=True).mean(). Unlike analytics::ema, the first observation never weighs more than its exponential share, so use it on a short series with no history before its first row. A finite constant series gives exactly that constant.
| values | The series; NaN entries are skipped and their rows left missing(). |
| alpha | The smoothing factor, in (0, 1]. |
| min_observed | How many observations must be seen before a value is reported. |
| std::invalid_argument | unless 0 < alpha <= 1, or if min_observed is zero. |
Definition at line 82 of file signal.hpp.
Referenced by adjusted_ema(), and exponential_line().
|
inline |
Computes the exponential moving average MovingAverageCrossover reads.
With at least 3 * span observed closes, analytics::ema seeded at the oldest; with fewer, adjusted_ema, since the seed would still weigh too much. Reported from the span-th observation.
| closes | The whole close series. |
| span | The EMA span. |
| std::invalid_argument | if span is zero. |
Definition at line 122 of file signal.hpp.
Referenced by exponential_line().
|
inline |
Returns the last two values of a line.
| line | The indicator line. |
Definition at line 52 of file signal.hpp.
Referenced by last_two(), and algotradelib::strategy::vanilla::MovingAverageCrossover::on_bar().
|
inline |
Returns the last count + 1 rows of a series.
Slice before computing a windowed indicator when only its latest values are needed, so the cost per bar does not grow with the cached history. Not for a recursive indicator such as an EMA, whose value depends on every earlier row.
| values | The series. |
| count | The indicator's window; one more row is kept for the previous value. |
Definition at line 145 of file signal.hpp.
Referenced by algotradelib::strategy::vanilla::DonchianBreakout::on_bar(), algotradelib::strategy::vanilla::VolatilityTargetSizing::on_bar(), algotradelib::strategy::vanilla::ZScoreReversion::on_bar(), and trailing().