algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
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
11
namespace
algotradelib
{
12
namespace
strategy
{
13
namespace
vanilla
{
14
21
struct
BuyAndHold
{
23
struct
Params
{
25
InstrumentId
instrument_
;
27
Decimal64
quantity_
;
29
std::string
tag_
{
"buy-and-hold"
};
30
};
31
33
Params
params_
;
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;
50
target.
instrument_
=
params_
.
instrument_
;
51
target.
target_quantity_
=
params_
.
quantity_
;
52
target.
tag_
=
params_
.
tag_
;
53
ctx.submit(target);
54
}
55
};
56
57
}
// namespace vanilla
58
}
// namespace strategy
59
}
// namespace algotradelib
algotradelib::Decimal64
An exact signed decimal: an int64 coefficient times 10^-scale.
Definition
types.hpp:297
event.hpp
The events a runner delivers to a strategy's handlers, and the market phase.
intent.hpp
What a strategy asks the runner for: orders (OrderIntent), target positions (TargetPosition) and canc...
algotradelib::strategy::vanilla
The strategies this library ships (buy and hold, crossovers, mean reversion, sizing,...
Definition
buy_and_hold.hpp:13
algotradelib::strategy
What a strategy sees and emits: events, intents, the portfolio, reconciliation and risk limits.
Definition
concept.hpp:16
algotradelib
The library: broker-neutral types (core), and the modules below.
Definition
conversion.hpp:13
algotradelib::InstrumentId
Identifies an instrument: its country, venue and symbol.
Definition
types.hpp:78
algotradelib::strategy::BarEvent
One bar, delivered to on_bar.
Definition
event.hpp:202
algotradelib::strategy::TargetPosition
The position a strategy wants to hold in one instrument.
Definition
intent.hpp:442
algotradelib::strategy::TargetPosition::instrument_
InstrumentId instrument_
The instrument.
Definition
intent.hpp:444
algotradelib::strategy::TargetPosition::tag_
std::string tag_
A label carried to the orders and their fills.
Definition
intent.hpp:450
algotradelib::strategy::TargetPosition::target_quantity_
Decimal64 target_quantity_
The position to hold, signed: negative is short, and zero means flat.
Definition
intent.hpp:446
algotradelib::strategy::vanilla::BuyAndHold::Params
The strategy's settings.
Definition
buy_and_hold.hpp:23
algotradelib::strategy::vanilla::BuyAndHold::Params::instrument_
InstrumentId instrument_
The instrument to hold; bars for any other instrument are ignored.
Definition
buy_and_hold.hpp:25
algotradelib::strategy::vanilla::BuyAndHold::Params::quantity_
Decimal64 quantity_
The shares to hold.
Definition
buy_and_hold.hpp:27
algotradelib::strategy::vanilla::BuyAndHold::Params::tag_
std::string tag_
The tag on the targets.
Definition
buy_and_hold.hpp:29
algotradelib::strategy::vanilla::BuyAndHold
Holds a fixed quantity of one instrument.
Definition
buy_and_hold.hpp:21
algotradelib::strategy::vanilla::BuyAndHold::on_bar
void on_bar(Ctx &ctx, const BarEvent &bar)
States the target position on each bar of the instrument.
Definition
buy_and_hold.hpp:45
algotradelib::strategy::vanilla::BuyAndHold::params_
Params params_
The settings.
Definition
buy_and_hold.hpp:33
algotradelib::strategy::vanilla::BuyAndHold::warmup_bars
static constexpr std::size_t warmup_bars
One bar of history is enough.
Definition
buy_and_hold.hpp:36
algotradelib
src
strategy
vanilla
buy_and_hold.hpp
Generated by
1.18.0