algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::strategy::vanilla::RsiThreshold Struct Reference

Long-only RSI strategy: buys when the index is oversold, sells when it is overbought. More...

#include <algotradelib/src/strategy/vanilla/reversion.hpp>

Collaboration diagram for algotradelib::strategy::vanilla::RsiThreshold:

Classes

struct  Params
 The strategy's settings. More...

Public Member Functions

std::size_t warmup_bars () const
 Returns how many bars to load before the first live bar.
template<class Ctx>
void on_bar (Ctx &ctx, const BarEvent &bar)
 States a target position for the instrument when its signal enters or exits.

Public Attributes

Params params_
 The settings.

Detailed Description

Long-only RSI strategy: buys when the index is oversold, sells when it is overbought.

Buys quantity_ when flat and Wilder's RSI (analytics::rsi) is at or below oversold_; goes flat when holding and it is at or above overbought_. The defaults 30 and 70 are Wilder's.

The index is computed over every cached close (up to the runner's series_capacity), because Wilder's smoothing depends on its seed. With about 99 closes the seed's weight falls below 0.2% for period 14.

Note
A backtest, whose cache keeps growing, can differ from a live run that loaded fewer bars, until the live cache catches up. Once the cache is full, each bar evicts the oldest close, which can change the index a lot: a full cache of unchanged closes after one fall reads 0, and 50 once that fall is evicted. So the signal can change on an unchanged close.

Definition at line 122 of file reversion.hpp.

Member Function Documentation

◆ on_bar()

template<class Ctx>
void algotradelib::strategy::vanilla::RsiThreshold::on_bar ( Ctx & ctx,
const BarEvent & bar )
inline

States a target position for the instrument when its signal enters or exits.

Template Parameters
CtxThe runner's context type.
Parameters
ctxThe context.
barThe new bar.

Definition at line 155 of file reversion.hpp.

◆ warmup_bars()

std::size_t algotradelib::strategy::vanilla::RsiThreshold::warmup_bars ( ) const
inline

Returns how many bars to load before the first live bar.

Returns
period_ + 1, the first row at which the index exists.

Definition at line 146 of file reversion.hpp.

Referenced by on_bar().

Member Data Documentation

◆ params_

Params algotradelib::strategy::vanilla::RsiThreshold::params_

The settings.

Definition at line 140 of file reversion.hpp.

Referenced by on_bar(), and warmup_bars().


The documentation for this struct was generated from the following file: