Skip to content

Commit f55062a

Browse files
committed
Refactoring the strategy files
1 parent de87fd1 commit f55062a

File tree

14 files changed

+206
-81
lines changed

14 files changed

+206
-81
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ add_subdirectory(external/libpqxx)
2828
# Include directories
2929
include_directories(
3030
${CMAKE_SOURCE_DIR}/source/include
31-
${CMAKE_SOURCE_DIR}/external
31+
${CMAKE_SOURCE_DIR}/source/include/strategy
32+
${CMAKE_SOURCE_DIR}/external
3233
)
3334

3435
# Collect all .cpp files in the src directory

backtesting-engine-cpp.xcodeproj/project.pbxproj

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
940A61142C92CE210083FEB8 /* ConfigManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61112C92CE210083FEB8 /* ConfigManager.cpp */; };
1212
940A61172C92CE960083FEB8 /* ServiceA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61152C92CE960083FEB8 /* ServiceA.cpp */; };
1313
940A61182C92CE960083FEB8 /* ServiceA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61152C92CE960083FEB8 /* ServiceA.cpp */; };
14+
941B549A2D3BBADE00E3BF64 /* strategy_variables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941B54992D3BBADD00E3BF64 /* strategy_variables.cpp */; };
15+
941B549B2D3BBADE00E3BF64 /* strategy_variables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941B54992D3BBADD00E3BF64 /* strategy_variables.cpp */; };
1416
94280BA32D2FC00200F1CF56 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94280BA22D2FC00200F1CF56 /* Base64.cpp */; };
1517
94280BA42D2FC00200F1CF56 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94280BA22D2FC00200F1CF56 /* Base64.cpp */; };
1618
944698852D3A545B0070E30F /* libpq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 94CD8A972D2D34A100041BBA /* libpq.a */; };
@@ -43,9 +45,16 @@
4345
940A61122C92CE210083FEB8 /* ConfigManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ConfigManager.hpp; sourceTree = "<group>"; };
4446
940A61152C92CE960083FEB8 /* ServiceA.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceA.cpp; sourceTree = "<group>"; };
4547
940A61162C92CE960083FEB8 /* ServiceA.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ServiceA.hpp; sourceTree = "<group>"; };
48+
941B54902D3BBA4900E3BF64 /* ohlc_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ohlc_variables.hpp; sourceTree = "<group>"; };
49+
941B54912D3BBA5600E3BF64 /* ohlc_rsi_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ohlc_rsi_variables.hpp; sourceTree = "<group>"; };
50+
941B54922D3BBA6500E3BF64 /* trading_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = trading_variables.hpp; sourceTree = "<group>"; };
51+
941B54932D3BBA7300E3BF64 /* strategy_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = strategy_variables.hpp; sourceTree = "<group>"; };
52+
941B54942D3BBA8300E3BF64 /* strategy.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = strategy.hpp; sourceTree = "<group>"; };
53+
941B54972D3BBAA200E3BF64 /* configuration.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = configuration.hpp; sourceTree = "<group>"; };
54+
941B54992D3BBADD00E3BF64 /* strategy_variables.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = strategy_variables.cpp; sourceTree = "<group>"; };
55+
941B549C2D3BBFB900E3BF64 /* strategy_head.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = strategy_head.hpp; sourceTree = "<group>"; };
4656
94280BA12D2FC00200F1CF56 /* Base64.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Base64.hpp; sourceTree = "<group>"; };
4757
94280BA22D2FC00200F1CF56 /* Base64.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
48-
944698842D3A53DF0070E30F /* StrategyConfiguration.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = StrategyConfiguration.hpp; sourceTree = "<group>"; };
4958
944D0DC82C8C3704004DD0FC /* LICENSE.MD */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.MD; sourceTree = "<group>"; };
5059
944D0DC92C8C3704004DD0FC /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
5160
944D0DCA2C8C3704004DD0FC /* clean.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = clean.sh; sourceTree = "<group>"; };
@@ -1251,6 +1260,27 @@
12511260
/* End PBXFrameworksBuildPhase section */
12521261

12531262
/* Begin PBXGroup section */
1263+
941B548F2D3BBA3B00E3BF64 /* strategy */ = {
1264+
isa = PBXGroup;
1265+
children = (
1266+
941B54972D3BBAA200E3BF64 /* configuration.hpp */,
1267+
941B54942D3BBA8300E3BF64 /* strategy.hpp */,
1268+
941B54932D3BBA7300E3BF64 /* strategy_variables.hpp */,
1269+
941B54922D3BBA6500E3BF64 /* trading_variables.hpp */,
1270+
941B54912D3BBA5600E3BF64 /* ohlc_rsi_variables.hpp */,
1271+
941B54902D3BBA4900E3BF64 /* ohlc_variables.hpp */,
1272+
);
1273+
path = strategy;
1274+
sourceTree = "<group>";
1275+
};
1276+
941B54982D3BBAD800E3BF64 /* strategy */ = {
1277+
isa = PBXGroup;
1278+
children = (
1279+
941B54992D3BBADD00E3BF64 /* strategy_variables.cpp */,
1280+
);
1281+
path = strategy;
1282+
sourceTree = "<group>";
1283+
};
12541284
94280BA72D2FC29F00F1CF56 /* utilities */ = {
12551285
isa = PBXGroup;
12561286
children = (
@@ -1319,6 +1349,7 @@
13191349
9470B5A22C8C5AD0007D9CC6 /* source */ = {
13201350
isa = PBXGroup;
13211351
children = (
1352+
941B54982D3BBAD800E3BF64 /* strategy */,
13221353
94DE4F772C8C3E7C00FE48FF /* include */,
13231354
9470B5A32C8C5AD0007D9CC6 /* Main.cpp */,
13241355
948A9CFB2C906C9C00E23669 /* Application.cpp */,
@@ -3421,7 +3452,8 @@
34213452
94DE4F772C8C3E7C00FE48FF /* include */ = {
34223453
isa = PBXGroup;
34233454
children = (
3424-
944698842D3A53DF0070E30F /* StrategyConfiguration.hpp */,
3455+
941B548F2D3BBA3B00E3BF64 /* strategy */,
3456+
941B549C2D3BBFB900E3BF64 /* strategy_head.hpp */,
34253457
94280BA12D2FC00200F1CF56 /* Base64.hpp */,
34263458
940A61162C92CE960083FEB8 /* ServiceA.hpp */,
34273459
948A9CFC2C906C9C00E23669 /* Application.hpp */,
@@ -3527,6 +3559,7 @@
35273559
948A9CFD2C906C9C00E23669 /* Application.cpp in Sources */,
35283560
9470B5A42C8C5AD0007D9CC6 /* Main.cpp in Sources */,
35293561
94280BA32D2FC00200F1CF56 /* Base64.cpp in Sources */,
3562+
941B549B2D3BBADE00E3BF64 /* strategy_variables.cpp in Sources */,
35303563
94CD8BA02D2E8CE500041BBA /* DatabaseConnection.cpp in Sources */,
35313564
940A61132C92CE210083FEB8 /* ConfigManager.cpp in Sources */,
35323565
940A61172C92CE960083FEB8 /* ServiceA.cpp in Sources */,
@@ -3539,6 +3572,7 @@
35393572
files = (
35403573
94CD8BA12D2E8CE500041BBA /* DatabaseConnection.cpp in Sources */,
35413574
94280BA42D2FC00200F1CF56 /* Base64.cpp in Sources */,
3575+
941B549A2D3BBADE00E3BF64 /* strategy_variables.cpp in Sources */,
35423576
940A61182C92CE960083FEB8 /* ServiceA.cpp in Sources */,
35433577
9470B5B62C8C5BFD007D9CC6 /* Main.cpp in Sources */,
35443578
9470B5AF2C8C5B99007D9CC6 /* tests.mm in Sources */,

source/Main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#include "Base64.hpp"
1515
#include <string>
1616
#include <nlohmann/json.hpp>
17-
#include "StrategyConfiguration.hpp"
17+
#include "strategy_head.hpp" // For everything
18+
1819

1920
using json = nlohmann::json;
2021

source/include/Base64.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <iostream>
88
#include <vector>
99
#include <string>
10-
#include <algorithm> // for std::remove_if, std::all_of
11-
#include <cstring> // for strchr
12-
#include <string> // for std::string
10+
#include <algorithm>
11+
#include <cstring>
12+
#include <string>
1313

1414
class Base64 {
1515
public:

source/include/StrategyConfiguration.hpp

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Backtesting Engine in C++
2+
//
3+
// (c) 2025 Ryan McCaffery | https://mccaffers.com
4+
// This code is licensed under MIT license (see LICENSE.txt for details)
5+
// ---------------------------------------
6+
7+
#pragma once
8+
#include <string>
9+
#include <nlohmann/json.hpp>
10+
#include "strategy.hpp"
11+
12+
namespace strategy {
13+
struct Configuration {
14+
std::string RUN_ID;
15+
std::string SYMBOLS;
16+
int LAST_MONTHS;
17+
Strategy STRATEGY;
18+
};
19+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Configuration,
20+
RUN_ID,
21+
SYMBOLS,
22+
LAST_MONTHS,
23+
STRATEGY
24+
);
25+
26+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Backtesting Engine in C++
2+
//
3+
// (c) 2025 Ryan McCaffery | https://mccaffers.com
4+
// This code is licensed under MIT license (see LICENSE.txt for details)
5+
// ---------------------------------------
6+
7+
#pragma once
8+
#include <nlohmann/json.hpp>
9+
10+
namespace strategy {
11+
struct OHLCRSIVariables {
12+
int RSI_LONG;
13+
int RSI_SHORT;
14+
};
15+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(OHLCRSIVariables, RSI_LONG, RSI_SHORT);
16+
} // namespace strategy
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Backtesting Engine in C++
2+
//
3+
// (c) 2025 Ryan McCaffery | https://mccaffers.com
4+
// This code is licensed under MIT license (see LICENSE.txt for details)
5+
// ---------------------------------------
6+
7+
#pragma once
8+
#include <nlohmann/json.hpp>
9+
10+
namespace strategy {
11+
struct OHLCVariables {
12+
int OHLC_COUNT;
13+
int OHLC_MINUTES;
14+
};
15+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(OHLCVariables, OHLC_COUNT, OHLC_MINUTES);
16+
} // namespace strategy
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Backtesting Engine in C++
2+
//
3+
// (c) 2025 Ryan McCaffery | https://mccaffers.com
4+
// This code is licensed under MIT license (see LICENSE.txt for details)
5+
// ---------------------------------------
6+
7+
#pragma once
8+
#include <string>
9+
#include <vector>
10+
#include <nlohmann/json.hpp>
11+
#include "trading_variables.hpp"
12+
#include "ohlc_variables.hpp"
13+
#include "strategy_variables.hpp"
14+
15+
namespace strategy {
16+
struct Strategy {
17+
std::string UUID;
18+
TradingVariables TRADING_VARIABLES;
19+
std::vector<OHLCVariables> OHLC_VARIABLES;
20+
StrategyVariables STRATEGY_VARIABLES;
21+
};
22+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Strategy,
23+
UUID,
24+
TRADING_VARIABLES,
25+
OHLC_VARIABLES,
26+
STRATEGY_VARIABLES
27+
);
28+
} // namespace strategy

0 commit comments

Comments
 (0)