Skip to content

Commit

Permalink
Reimplemented Time Taken using new Backtester class
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwporter committed Sep 29, 2023
1 parent 0998174 commit 727c45c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 55 deletions.
8 changes: 8 additions & 0 deletions Engines/backtester.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "backtester.h"

#include <chrono>

Backtester::Backtester() {};

void Backtester::run()
{
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();

Portfolio p = Portfolio(&dh);
RiskHandler rh = RiskHandler(&dh, &p);
Strategy s = Strategy(&dh, &rh);
Expand All @@ -17,6 +21,10 @@ void Backtester::run()
};
};
m = Metrics(&p);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

m.TIME_TAKEN = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();

}
void Backtester::metrics(){
m.display_metrics();
Expand Down
2 changes: 1 addition & 1 deletion Metrics/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void Metrics::printf_csv(std::string path, MoneyMatrixX matrix) {
void Metrics::display_metrics() {
VariadicTable<std::string, double> vt({"Metric", "Value"}, 10);

vt.addRow("Time Taken", 100);// TIME_TAKEN);
vt.addRow("Time Taken", TIME_TAKEN);
vt.addRow("Sharpe Ratio", SHARPE_RATIO(252));
vt.addRow("Total Return", TOTAL_RETURN);
vt.addRow("Max DD", MAX_DRAWDOWN);
Expand Down
54 changes: 0 additions & 54 deletions engine.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
// #include "Portfolio/ticker.h"
// #include "Portfolio/position.h"
// #include "Portfolio/portfolio.h"
// #include "utility.h"
// #include "DataHandler/dh.h"
// #include "Strategy/strategy.h"
// #include "Metrics/metrics.h"

// #include <chrono>

// #include <Eigen/Dense>
// #include <Eigen/Core>

// #include <iostream>

// using namespace std;


// void engine() {
// std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();

// DataHandler dh = DataHandler();
// Portfolio p = Portfolio(&dh);
// RiskHandler rh = RiskHandler(&dh, &p);
// Strategy strategy = Strategy(&dh, &rh);

// for(dh.current = dh.warmup_period; dh.current < dh.total_bars; dh.current++) {
// p.update_value();
// for (auto symbol : dh.symbols) {
// if (dh.symbol_data_locations[symbol][0] <= dh.current && dh.current < dh.symbol_data_locations[symbol][1]) {
// strategy.on_data(symbol);
// };
// };
// };

// std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

// Metrics m(&p);
// m.TIME_TAKEN = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();

// // std::cout << Eigen::Matrix({m.EQUITY_CURVE, m.RETURNS});
// // std::cout << m.holdings;

// m.display_metrics();

// // std::cout << dh.symbol_data["GOOG"];
// // std::cout << dh.symbol_data["AAPL"];
// }

// int main() {
// engine();
// return 0;
// }

#include "Engines/backtester.h"

int main() {
Expand Down
Binary file modified engine.exe
Binary file not shown.

0 comments on commit 727c45c

Please sign in to comment.