-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLogging.cpp
More file actions
43 lines (34 loc) · 1.47 KB
/
Logging.cpp
File metadata and controls
43 lines (34 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Logging.hpp"
#include "InputParameter.hpp"
#include "ReportGenerator.hpp"
#include <fstream>
#include <sstream>
#include <filesystem>
#include "nlohmann/json.hpp"
using json = nlohmann::json;
Logging::Logging(SCStudyInterfaceRef sc) : sc(sc) {}
void Logging::LogMetrics(SCStudyInterfaceRef sc, const std::string &strategyName, const std::string &reportPath, const std::vector<std::pair<std::string, double>> ¶ms, int studyId)
{
std::filesystem::create_directories(std::filesystem::path(reportPath).parent_path());
std::ofstream log(reportPath, std::ios::app);
if (!log.is_open())
return;
json result;
result["customStudyInformation"] = InputParameter::GetCustomStudyInformation(sc, studyId);
result["combination"] = ReportGenerator::GetCombination(params);
result["studyParameters"] = InputParameter::GetStudyParameters(sc, studyId);
result["tradesData"] = ReportGenerator::GetTradesData(sc);
result["tradeStatistics"] = ReportGenerator::GetTradeStatistics(sc);
log << result.dump(4);
// csv
std::stringstream fileNameStream;
fileNameStream
<< reportPath << ".csv";
std::ofstream csvLog(fileNameStream.str(), std::ios::app);
if (!csvLog.is_open())
return;
ReportGenerator::WriteSummaryHeader(csvLog, strategyName, InputParameter::GetCurrentDllName(sc, studyId), params);
ReportGenerator::WriteTradesData(sc, csvLog);
ReportGenerator::WriteTradeStatisticsV2(sc, csvLog);
// csv
}