tzutrader
A composable C++ backtesting library for trading strategies (experimental)
Loading...
Searching...
No Matches
runners.h
Go to the documentation of this file.
1#ifndef RUNNERS_H
2#define RUNNERS_H
3
4#include "strategies.h"
5#include "portfolios.h"
6#include "streamers.h"
7
8namespace tzu {
9
10template <class T>
11class Runner {
12public:
13 void run() {
14 static_cast<T*>(this)->run();
15 }
16};
17
31template <typename Portfolio, typename Strat, typename Streamer>
32class BasicRunner: public Runner<BasicRunner<Portfolio, Strat, Streamer>> {
33 Portfolio portfolio;
34 Strat strat;
35 Streamer streamer;
36public:
37 BasicRunner(Portfolio& portfolio, Strat& strat, Streamer& streamer)
38 : portfolio(portfolio), strat(strat), streamer(streamer) {}
39 void run(bool verbose = false) {
40 for (const auto& row : streamer) {
41 auto sig = strat.update(row);
42 portfolio.update(sig);
43 if (verbose) std::cout << portfolio << std::endl;
44 }
45 if (!verbose)
46 std::cout << portfolio << std::endl;
47 }
48};
49
50} // namespace tzu
51
52#endif // RUNNERS_H
BasicRunner(Portfolio &portfolio, Strat &strat, Streamer &streamer)
Definition runners.h:37
void run(bool verbose=false)
Definition runners.h:39
Definition portfolios.h:15
Definition runners.h:11
void run()
Definition runners.h:13
Definition defs.h:20