algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
buy_and_hold.hpp
1#pragma once
2
3#include "../event.hpp"
4#include "../intent.hpp"
5
6#include <algotradelib/core>
7
8#include <cstddef>
9#include <string>
10
11namespace algotradelib {
12namespace strategy {
13namespace vanilla {
14
21struct BuyAndHold {
23 struct Params {
29 std::string tag_{"buy-and-hold"};
30 };
31
34
36 static constexpr std::size_t warmup_bars = 1;
37
44 template <class Ctx>
45 void on_bar(Ctx& ctx, const BarEvent& bar) {
46 if (!(bar.instrument_ == params_.instrument_)) {
47 return;
48 }
49 TargetPosition target;
52 target.tag_ = params_.tag_;
53 ctx.submit(target);
54 }
55};
56
57} // namespace vanilla
58} // namespace strategy
59} // namespace algotradelib
An exact signed decimal: an int64 coefficient times 10^-scale.
Definition types.hpp:297
The events a runner delivers to a strategy's handlers, and the market phase.
What a strategy asks the runner for: orders (OrderIntent), target positions (TargetPosition) and canc...
The strategies this library ships (buy and hold, crossovers, mean reversion, sizing,...
What a strategy sees and emits: events, intents, the portfolio, reconciliation and risk limits.
Definition concept.hpp:16
The library: broker-neutral types (core), and the modules below.
Identifies an instrument: its country, venue and symbol.
Definition types.hpp:78
One bar, delivered to on_bar.
Definition event.hpp:202
The position a strategy wants to hold in one instrument.
Definition intent.hpp:442
InstrumentId instrument_
The instrument.
Definition intent.hpp:444
std::string tag_
A label carried to the orders and their fills.
Definition intent.hpp:450
Decimal64 target_quantity_
The position to hold, signed: negative is short, and zero means flat.
Definition intent.hpp:446
InstrumentId instrument_
The instrument to hold; bars for any other instrument are ignored.
Holds a fixed quantity of one instrument.
void on_bar(Ctx &ctx, const BarEvent &bar)
States the target position on each bar of the instrument.
static constexpr std::size_t warmup_bars
One bar of history is enough.