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

Flattens every position when the market enters a phase it should not hold through. More...

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

Collaboration diagram for algotradelib::strategy::vanilla::TimedLiquidation:

Classes

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

Public Member Functions

template<class Ctx>
void on_phase (Ctx &ctx, MarketPhase phase)
 Targets zero in every held instrument if phase is not in hold_through_.

Public Attributes

Params params_
 The settings.

Static Public Attributes

static constexpr std::size_t warmup_bars = 0
 No history is needed.

Detailed Description

Flattens every position when the market enters a phase it should not hold through.

On each phase change that is not in hold_through_ (including UNKNOWN, an uncovered calendar date), it states a target of zero for every instrument held. Working orders against those targets are cancelled by reconciliation.

Warning
To combine it with a signal strategy, the signal must stop stating its target once this has fired. In a backtest on_bar runs right after on_phase, and live the next bar follows it, so a signal that restates its target on every bar (such as BuyAndHold) replaces the flatten. See BuyThenLiquidate in tests/test-backtest.cpp for a gated composition.

Definition at line 28 of file timed_liquidation.hpp.

Member Function Documentation

◆ on_phase()

template<class Ctx>
void algotradelib::strategy::vanilla::TimedLiquidation::on_phase ( Ctx & ctx,
MarketPhase phase )
inline

Targets zero in every held instrument if phase is not in hold_through_.

Template Parameters
CtxThe runner's context type.
Parameters
ctxThe context.
phaseThe new market phase.

Definition at line 50 of file timed_liquidation.hpp.

Member Data Documentation

◆ params_

Params algotradelib::strategy::vanilla::TimedLiquidation::params_

The settings.

Definition at line 38 of file timed_liquidation.hpp.

◆ warmup_bars

std::size_t algotradelib::strategy::vanilla::TimedLiquidation::warmup_bars = 0
staticconstexpr

No history is needed.

Definition at line 41 of file timed_liquidation.hpp.


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