-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
94 lines (66 loc) · 2.37 KB
/
main.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <tradingcore2/tradingcore2.h>
void runBuyAndHold() {
auto cnfund = tr2::ExchangeMgr::getSingleton()->getExchange("cnfund");
// tr2::CNFundExchange cnfund;
// cnfund.loadFundValue("../data/cnfund/110022.csv");
// cnfund.buildTimeStampList();
auto pWallet = new tr2::Wallet(*cnfund);
pWallet->deposit(10000, tr2::str2timestampUTC("20100820", "%Y%m%d"));
tr2::StrategyBAH* bah = new tr2::StrategyBAH(*pWallet, *cnfund);
bah->init("110022", 10000);
bah->simulateTrading();
tr2::PNL pnl;
pWallet->buildPNL(pnl);
pnl.print("buy and hold 110022");
pnl.saveCSV("../data/buyandhold.110022.csv", true);
}
void runSIROC() {
auto cnfund = tr2::ExchangeMgr::getSingleton()->getExchange("cnfund");
// tr2::CNFundExchange cnfund;
// cnfund.loadFundValue("../data/cnfund/110022.csv");
// cnfund.buildTimeStampList();
auto pWallet = new tr2::Wallet(*cnfund);
pWallet->deposit(10000, tr2::str2timestampUTC("20100820", "%Y%m%d"));
tr2::StrategySI* si = new tr2::StrategySI(*pWallet, *cnfund);
si->init("110022", "roc", 1, -0.02, -0.015, 0.03, 0.04, 10000);
si->setStopLess(0.10);
si->simulateTrading();
tr2::PNL pnl;
pWallet->buildPNL(pnl);
pnl.print("roc 110022");
si->print();
pnl.saveCSV("../data/roc.110022.csv", true);
}
void train() {
auto cnfund = tr2::ExchangeMgr::getSingleton()->getExchange("cnfund");
// cnfund.loadFundValue("../data/cnfund/110022.csv");
// cnfund.buildTimeStampList();
// tr2::trainSingleIndicator2(cnfund, "110022", "roc", "../output", 10000, 2,
// 0.005, 0.015, 0.005, 0.03, 2);
// tr2::trainSingleIndicator2(cnfund, "110022", "rsi", "../output", 10000, 5,
// 2,
// 5, 2, 10, 2);
tr2::trainSingleIndicator2Ex(*cnfund, "110022", "rsi", "../output", 10000, 5,
10, 5, 10, 10, 2);
}
// void startServ(const char* addr) {
// auto pServ = tr2::newTrainServer2(addr);
// pServ->run();
// }
int main(int argc, char* argv[]) {
tr2::LogHelper log(argv[0]);
tr2::regAllIndicators();
tr2::regAllExchanges();
tr2::regAllCtrlConditionHelper();
tr2::regAllStrategy();
tr2::Config cfg;
tr2::loadConfig(cfg, "../cfg/config.yaml.default");
auto mgr = tr2::ExchangeMgr::getSingleton();
mgr->init(cfg);
// runBuyAndHold();
// runSIROC();
train();
// startServ("0.0.0.0:3721");
return 0;
}