Skip to content

Commit 417cecc

Browse files
author
yuanwenbin
committed
backtest功能完善
1 parent 2d39ea5 commit 417cecc

19 files changed

Lines changed: 232 additions & 227 deletions

service/include/Interprecter/Stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FormulaParser {
7878
bool parse(const String& code);
7979
bool parse(const String& code, TradeAction action);
8080

81-
List<TradeDecision> envoke(const Vector<symbol_t>& symbols, const List<String>& variantNames, DataContext* context);
81+
List<TradeDecision> envoke(const Vector<symbol_t>& symbols, const Set<String>& variantNames, DataContext* context);
8282

8383
private:
8484
double eval(const symbol_t& symbol, const peg::Ast& ast, DataContext* context);

service/include/Nodes/DecisionNode.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

service/include/Nodes/FunctionNode.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ class FunctionNode: public QNode {
66
public:
77
~FunctionNode();
88

9-
virtual bool Init(DataContext& context, const nlohmann::json& config);
9+
virtual bool Init(const nlohmann::json& config);
1010

1111
virtual bool Process(const String& strategy, DataContext& context);
1212

1313
virtual Map<String, ArgType> out_elements();
1414

15-
void SetFunctionName(const String& name) { _funcionName = name; }
16-
1715
template<typename T>
1816
void AddArgument(const String& name, T val) {
1917
_args[name] = val;
@@ -23,8 +21,9 @@ class FunctionNode: public QNode {
2321

2422

2523
private:
26-
String _funcionName;
2724
Map<String, std::variant<int>> _args;
2825
ICallable* _callable = nullptr;
2926
Map<String, ArgType> _params;
27+
// 输出的数据名
28+
Map<String, ArgType> _outputs;
3029
};

service/include/Nodes/QuoteNode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#pragma once
22
#include "StrategyNode.h"
3+
#include "Util/system.h"
34

45
class Server;
56
class QuoteInputNode : public QNode {
67
public:
78
QuoteInputNode(Server* server);
89

9-
bool Init(DataContext& context, const nlohmann::json& config);
10+
bool Init(const nlohmann::json& config);
1011

1112
virtual bool Process(const String& strategy, DataContext& context);
1213

1314
void AddSymbol(symbol_t symbol) { _symbols.insert(symbol); }
1415

1516
void EraseSymbol(symbol_t symbol) { _symbols.erase(symbol); }
1617

17-
void Connect(QNode* next, const String& from, const String& to);
18-
1918
Map<String, ArgType> out_elements();
2019
private:
2120
bool Init();

service/include/Nodes/SignalNode.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include "StrategyNode.h"
3+
#include "Util/system.h"
4+
5+
class FormulaParser;
6+
class Server;
7+
// 构建买入/卖出信号
8+
class SignalNode: public QNode {
9+
public:
10+
SignalNode(Server* server);
11+
~SignalNode();
12+
13+
virtual bool Init(const nlohmann::json& config);
14+
virtual bool Process(const String& strategy, DataContext& context);
15+
16+
bool ParseBuyExpression(const String& expression);
17+
bool ParseSellExpression(const String& expression);
18+
19+
private:
20+
21+
22+
private:
23+
Server* _server;
24+
FormulaParser* _buyParser;
25+
FormulaParser* _sellParser;
26+
Vector<symbol_t> _pools;
27+
};

service/include/Strategy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class QStrategy: public QNode {
7777
struct AgentStrategyInfo;
7878
// AgentStrategyInfo parse_strategy_script(const nlohmann::json& content);
7979

80+
class Server;
8081
List<QNode*> parse_strategy_script_v2(const nlohmann::json& content, Server* server);
8182
// 对输入的有向图节点作topo排序,返回排序后的节点
8283
List<QNode*> topo_sort(const List<QNode*>& graph);

service/include/StrategyNode.h

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#pragma once
22
#include "std_header.h"
3-
#include "Feature.h"
4-
#include "server.h"
53
#include "json.hpp"
6-
#include "Util/system.h"
74
#include <functional>
8-
#include <utility>
9-
#include "BrokerSubSystem.h"
105

116
class ICallable;
127
// 数据上下文,用于管理节点间传输的数据
@@ -51,7 +46,7 @@ class QNode {
5146
using Edges = MultiMap<String, QNode*>;
5247
public:
5348
virtual ~QNode(){}
54-
virtual bool Init(DataContext& context, const nlohmann::json& config) = 0;
49+
virtual bool Init(const nlohmann::json& config) = 0;
5550
/**
5651
* @brief 对输入数据做处理,并返回处理后的数据
5752
*/
@@ -86,7 +81,7 @@ class QNode {
8681

8782
class OperationNode: public QNode {
8883
public:
89-
virtual bool Init(DataContext& context, const nlohmann::json& config);
84+
virtual bool Init(const nlohmann::json& config);
9085

9186
virtual bool Process(const String& strategy, DataContext& context);
9287

@@ -96,31 +91,3 @@ class OperationNode: public QNode {
9691
private:
9792
std::function<void ()> _callable;
9893
};
99-
100-
class FeatureNode: public QNode {
101-
public:
102-
virtual bool Init(DataContext& context, const nlohmann::json& config);
103-
virtual bool Process(const String& strategy, DataContext& context);
104-
};
105-
106-
class FormulaParser;
107-
// 构建买入/卖出信号
108-
class SignalNode: public QNode {
109-
public:
110-
SignalNode(Server* server);
111-
~SignalNode();
112-
113-
virtual bool Init(DataContext& context, const nlohmann::json& config);
114-
virtual bool Process(const String& strategy, DataContext& context);
115-
116-
bool ParseBuyExpression(const String& expression);
117-
bool ParseSellExpression(const String& expression);
118-
119-
private:
120-
121-
122-
private:
123-
Server* _server;
124-
FormulaParser* _buyParser;
125-
FormulaParser* _sellParser;
126-
};

service/include/std_header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ using UnorderedSet = std::unordered_set<T, Args...>;
8080
#include "Eigen/Core"
8181
#include "Util/log.h"
8282

83-
using feature_t = std::variant<uint64_t, double, Vector<double>, Eigen::MatrixXd>;
83+
using feature_t = std::variant<std::string, uint64_t, double, Vector<double>, Eigen::MatrixXd>;

service/src/AgentSubSystem.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ void FlowSubsystem::Start(const String& strategy) {
8686
DataContext context;
8787
try {
8888
auto& flow = _flows[strategy];
89-
for (auto node: flow._graph) {
90-
if (flow._running && !node->Init(context, flow._config)) {
91-
INFO("strategy thread exit.");
92-
return;
93-
}
94-
}
89+
// for (auto node: flow._graph) {
90+
// if (flow._running && !node->Init(context, flow._config)) {
91+
// INFO("strategy thread exit.");
92+
// return;
93+
// }
94+
// }
9595
uint64_t epoch = 0;
9696
while (flow._running) {
9797
context.SetEpoch(++epoch);

service/src/Bridge/SIM/SIMExchange.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ bool StockSimulation::Once(uint& curIndex) {
332332

333333
bool StockSimulation::Once(symbol_t symbol, time_t timeAxis) {
334334

335+
return true;
335336
}
336337

337338
double StockSimulation::GetAvailableFunds()

0 commit comments

Comments
 (0)