Crypto backtesting
Loading...
Searching...
No Matches
main.cxx File Reference
#include "backtest.h"
#include "fx/constants.h"
#include "summary.h"
#include <benchmark/benchmark.h>
#include <filesystem>
#include <fstream>
#include <ranges>
#include <string_view>
#include <vector>
#include <print>
Include dependency graph for main.cxx:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Convert arguments to files, validate them as CSVs and backtest.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Convert arguments to files, validate them as CSVs and backtest.

Definition at line 13 of file main.cxx.

13 {
14
15 using namespace std::literals::string_view_literals;
16
17 // Create vector of only CSV files
18 std::vector<std::string_view> files;
19 for (int i = 0; i < argc; ++i)
20 if (std::filesystem::path(argv[i]).extension() == ".csv"sv)
21 files.push_back(argv[i]);
22
23 // Run backtests
24 const auto summary = to_summary(files);
25
26 // Create results
27 const auto markdown = to_markdown(summary);
28 const auto csv = to_csv(summary);
29
30 // Report results
31 std::println(
32 "- {} currency pairs (from Marketstack, Coinbase, Kraken, Binance)", std::size(files));
33 std::println("- {}% take profit", fx::take_profit);
34 std::println("- {}% stop loss", fx::stop_loss);
35 std::println("- {} candles window size", fx::win);
36 std::println("- {} minimum ATR (normalised)", fx::minimum_atr);
37 std::println("- {} minimum entry price\n", fx::minimum_entry);
38 std::println("{}", markdown);
39
40 // Write CSV to file
41 std::ofstream{"summary.csv"} << csv;
42
43 ::benchmark::Initialize(&argc, argv);
44 ::benchmark::RunSpecifiedBenchmarks();
45}
std::vector< trade_t > to_summary(std::span< const std::string_view > files)
Definition backtest.cxx:10
constexpr auto stop_loss
Close position if price has decreased by this percentage.
Definition constants.h:14
constexpr auto minimum_entry
Minimum price to consider a trade.
Definition constants.h:17
constexpr auto take_profit
Close position if price has increased by this percentage.
Definition constants.h:11
constexpr auto win
The number of prices in a trading window.
Definition constants.h:6
constexpr auto minimum_atr
Minimum (normalised) ATR to consider a trade.
Definition constants.h:20
std::string to_csv(std::span< const trade_t > summary)
Convert summary of trades to CSV string.
Definition summary.cxx:8
std::string to_markdown(std::span< const trade_t > summary)
Convert summary of trades to markdown string.
Definition summary.cxx:39
Here is the call graph for this function: