Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/brew.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

# Check if a package is already installed via Homebrew, then skip
# Function to check if a package is already installed via Homebrew, then skip installation if it is
check_and_install() {
if ! brew list $1 &>/dev/null; then
echo "Installing $1..."
brew install $1
echo "Installing $1..." # Inform the user that the package is being installed
brew install $1 # Install the package using Homebrew
else
echo "$1 is already installed"
echo "$1 is already installed" # Inform the user that the package is already installed
fi
}

# Install packages if they don't exist
check_and_install postgresql
check_and_install pkg-config
check_and_install postgresql # Check and install PostgreSQL
check_and_install pkg-config # Check and install pkg-config
6 changes: 6 additions & 0 deletions .github/workflows/cpp_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PROFILE_DIR=$(ls -t /tmp/Build/ProfileData | head -n 1);
xcrun llvm-cov show \
/tmp/Build/Products/Debug/tests.xctest/Contents/MacOS/tests \
-instr-profile="/tmp/Build/ProfileData/${PROFILE_DIR}/Coverage.profdata" \
-format=text \
> coverage.txt
53 changes: 32 additions & 21 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Backtesting C++ Workflow
# To build, test and perform SonarCloud analysis
name: Build

on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
push:
branches:
- main # Trigger on pushes to main branch
- main
pull_request:
types:
- opened # When PR is first created
- synchronize # When new commits are pushed to the PR
- reopened # When PR is reopened after being closed
types: [opened, synchronize, reopened]
name: Build

# Environment variables used across jobs
env:
BUILD_TYPE: Release # Set CMake build configuration
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Output directory for build wrapper
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed

jobs:

build:
name: Build & Test
runs-on: macos-14 # Use macOS 14 (Sonoma) runner
Expand Down Expand Up @@ -52,17 +49,21 @@ jobs:
# - Outputs results in JUnit format
- name: Run tests
run: >
OTHER_CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
OTHER_CPLUSPLUSFLAGS="-fprofile-instr-generate -fcoverage-mapping"
OTHER_SWIFT_FLAGS="-profile-generate -profile-coverage-mapping"
LLVM_PROFILE_FILE="/tmp/coverage.profraw"
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
xcodebuild
-scheme tests
-destination 'platform=macOS'
xcodebuild
-scheme tests
-destination 'platform=macOS'
-resultBundlePath TestResult/
-enableCodeCoverage YES
-derivedDataPath "${RUNNER_TEMP}/Build/DerivedData"
HEADER_SEARCH_PATHS="./external/libpqxx/include/pqxx/internal ./external/libpqxx/include/ ./external/libpqxx/build/include/ ./external/" \
LIBRARY_SEARCH_PATHS="./external/libpqxx/src/ ./external/libpqxx/build/src/" \
HEADER_SEARCH_PATHS="./external/libpqxx/include/pqxx/internal ./external/libpqxx/include/ ./external/libpqxx/build/include/ ./external/"
LIBRARY_SEARCH_PATHS="./external/libpqxx/src/ ./external/libpqxx/build/src/"
OTHER_LDFLAGS="-L./external/libpqxx/build/src -lpqxx -lpq -L/opt/homebrew/Cellar/pkgconf/2.3.0_1/lib -L/opt/homebrew/Cellar/pkgconf/2.3.0_1/lib/pkgconfig -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14 -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14/pgxs -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14/pkgconfig"
clean build test
clean build test
| xcpretty -r junit && exit ${PIPESTATUS[0]}
- name: Convert coverage report to sonarqube format
run: >
Expand All @@ -73,8 +74,8 @@ jobs:
uses: actions/upload-artifact@v4
with:
path: sonarqube-generic-coverage.xml
retention-days: 1

retention-days: 1 # Artifact will be available only for 5 days.
sonar-scan:
name: SonarCloud Scan
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,18 +110,28 @@ jobs:
# https://github.com/SonarSource/sonarqube-scan-action
- name: Install Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4.2.1
# This step installs the SonarQube build wrapper, which is necessary for analyzing C/C++ projects.

# Downloads all artifacts generated by previous steps in the workflow
- name: Download all workflow run artifacts
uses: actions/download-artifact@v4

# Configures the CMake build system, specifying the source directory and build directory, and setting the build type
- name: Configure CMake
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# Runs the build wrapper to capture build commands and outputs them to the specified directory. Then builds the project using CMake
- name: Run build-wrapper
run: |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

# Performs the SonarQube scan using the scan action. Uses captured build commands for analysis and requires GitHub and SonarQube tokens for authentication
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v4.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
--define sonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ TestResult
.DS_Store

xcuserdata/
xcuserstate/
xcuserstate/
TestResult.xcresult/
sonarqube-generic-coverage.xml
67 changes: 67 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"files.associations": {
"unordered_map": "cpp",
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"any": "cpp",
"array": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"execution": "cpp",
"memory": "cpp",
"forward_list": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"print": "cpp",
"queue": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"source_location": "cpp",
"span": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
}
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_subdirectory(external/libpqxx EXCLUDE_FROM_ALL)
include_directories(
${CMAKE_SOURCE_DIR}/source/include
${CMAKE_SOURCE_DIR}/source/include/utilities
${CMAKE_SOURCE_DIR}/source/include/models
${CMAKE_SOURCE_DIR}/source/include/trading
${CMAKE_SOURCE_DIR}/source/include/trading_definitions
${CMAKE_SOURCE_DIR}/external
)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feel free to explore, but this code base is usuable at the moment.

I'm developing a high-performance C++ backtesting engine designed to analyze financial data and evaluate multiple trading strategies at scale.

![alt](images/development_active.svg) [![Build](https://github.com/mccaffers/backtesting-engine-cpp/actions/workflows/sonarcloud.yml/badge.svg)](https://github.com/mccaffers/backtesting-engine-cpp/actions/workflows/sonarcloud.yml) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=bugs)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=coverage)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp)
[![Build](https://github.com/mccaffers/backtesting-engine-cpp/actions/workflows/sonarcloud.yml/badge.svg)](https://github.com/mccaffers/backtesting-engine-cpp/actions/workflows/sonarcloud.yml) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=bugs)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mccaffers_backtesting-engine-cpp&metric=coverage)](https://sonarcloud.io/summary/new_code?id=mccaffers_backtesting-engine-cpp)

I'm extracting results and creating various graphs for trend analyses using SciPy for calculations and Plotly for visualization.

Expand Down Expand Up @@ -63,7 +63,7 @@ Xcode - Library Path
"/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14"
```

### Test build with cmake
### Test the build

`sh ./scripts/build.sh`

Expand Down
56 changes: 56 additions & 0 deletions backtesting-engine-cpp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
941B549B2D3BBADE00E3BF64 /* trading_definitions_json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941B54992D3BBADD00E3BF64 /* trading_definitions_json.cpp */; };
94280BA32D2FC00200F1CF56 /* base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94280BA22D2FC00200F1CF56 /* base64.cpp */; };
94280BA42D2FC00200F1CF56 /* base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94280BA22D2FC00200F1CF56 /* base64.cpp */; };
943398242D57E53400287A2D /* jsonParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 943398232D57E53400287A2D /* jsonParser.cpp */; };
943398252D57E53400287A2D /* jsonParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 943398232D57E53400287A2D /* jsonParser.cpp */; };
943398272D57E54000287A2D /* jsonParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = 943398262D57E54000287A2D /* jsonParser.mm */; };
94364CB62D416D8D00F35B55 /* db.mm in Sources */ = {isa = PBXBuildFile; fileRef = 94364CB52D416D8000F35B55 /* db.mm */; };
944698852D3A545B0070E30F /* libpq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 94CD8A972D2D34A100041BBA /* libpq.a */; };
94674B872D533B4000973137 /* tradeManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94674B852D533B4000973137 /* tradeManager.cpp */; };
94674B882D533B4000973137 /* tradeManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94674B852D533B4000973137 /* tradeManager.cpp */; };
94674B8A2D533BDA00973137 /* tradeManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 94674B892D533BDA00973137 /* tradeManager.mm */; };
94674B8D2D533E7800973137 /* trade.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94674B8B2D533E7800973137 /* trade.cpp */; };
94674B8E2D533E7800973137 /* trade.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94674B8B2D533E7800973137 /* trade.cpp */; };
9470B5A42C8C5AD0007D9CC6 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9470B5A32C8C5AD0007D9CC6 /* main.cpp */; };
9470B5B62C8C5BFD007D9CC6 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9470B5A32C8C5AD0007D9CC6 /* main.cpp */; };
94CD8B992D2DCDD800041BBA /* libpqxx-7.10.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 94CD8B982D2DCDD800041BBA /* libpqxx-7.10.a */; };
Expand Down Expand Up @@ -54,6 +62,9 @@
94280BA12D2FC00200F1CF56 /* base64.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = base64.hpp; sourceTree = "<group>"; };
94280BA22D2FC00200F1CF56 /* base64.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = base64.cpp; sourceTree = "<group>"; };
942966D82D48E84A00532862 /* priceData.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = priceData.hpp; sourceTree = "<group>"; };
943398222D57E52900287A2D /* jsonParser.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = jsonParser.hpp; sourceTree = "<group>"; };
943398232D57E53400287A2D /* jsonParser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = jsonParser.cpp; sourceTree = "<group>"; };
943398262D57E54000287A2D /* jsonParser.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = jsonParser.mm; sourceTree = "<group>"; };
94364CB52D416D8000F35B55 /* db.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = db.mm; sourceTree = "<group>"; };
944D0DC82C8C3704004DD0FC /* LICENSE.MD */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.MD; sourceTree = "<group>"; };
944D0DC92C8C3704004DD0FC /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
Expand All @@ -65,6 +76,11 @@
944D0DD02C8C3704004DD0FC /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
944D0DD12C8C3704004DD0FC /* random-indices-sp500-variable.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "random-indices-sp500-variable.svg"; sourceTree = "<group>"; };
944D0DD32C8C3704004DD0FC /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
94674B822D533B1D00973137 /* trade.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = trade.hpp; sourceTree = "<group>"; };
94674B832D533B2F00973137 /* tradeManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = tradeManager.hpp; sourceTree = "<group>"; };
94674B852D533B4000973137 /* tradeManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = tradeManager.cpp; sourceTree = "<group>"; };
94674B892D533BDA00973137 /* tradeManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = tradeManager.mm; sourceTree = "<group>"; };
94674B8B2D533E7800973137 /* trade.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = trade.cpp; sourceTree = "<group>"; };
94685CCE2D384A8B00863D04 /* json.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = json.hpp; sourceTree = "<group>"; };
9470B5A12C8C5AD0007D9CC6 /* source */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = source; sourceTree = BUILT_PRODUCTS_DIR; };
9470B5A32C8C5AD0007D9CC6 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1289,6 +1305,7 @@
942966D72D48E84100532862 /* models */ = {
isa = PBXGroup;
children = (
94674B822D533B1D00973137 /* trade.hpp */,
942966D82D48E84A00532862 /* priceData.hpp */,
);
path = models;
Expand Down Expand Up @@ -1343,6 +1360,30 @@
path = images;
sourceTree = "<group>";
};
94674B842D533B2F00973137 /* trading */ = {
isa = PBXGroup;
children = (
94674B832D533B2F00973137 /* tradeManager.hpp */,
);
path = trading;
sourceTree = "<group>";
};
94674B862D533B4000973137 /* trading */ = {
isa = PBXGroup;
children = (
94674B852D533B4000973137 /* tradeManager.cpp */,
);
path = trading;
sourceTree = "<group>";
};
94674B8C2D533E7800973137 /* models */ = {
isa = PBXGroup;
children = (
94674B8B2D533E7800973137 /* trade.cpp */,
);
path = models;
sourceTree = "<group>";
};
94685CCF2D384A8B00863D04 /* nlohmann */ = {
isa = PBXGroup;
children = (
Expand All @@ -1354,6 +1395,9 @@
9470B5A22C8C5AD0007D9CC6 /* source */ = {
isa = PBXGroup;
children = (
943398232D57E53400287A2D /* jsonParser.cpp */,
94674B8C2D533E7800973137 /* models */,
94674B862D533B4000973137 /* trading */,
94DE4F772C8C3E7C00FE48FF /* include */,
941B54982D3BBAD800E3BF64 /* trading_definitions */,
94280BA72D2FC29F00F1CF56 /* utilities */,
Expand All @@ -1368,6 +1412,8 @@
9470B5AD2C8C5B99007D9CC6 /* tests */ = {
isa = PBXGroup;
children = (
943398262D57E54000287A2D /* jsonParser.mm */,
94674B892D533BDA00973137 /* tradeManager.mm */,
94364CB52D416D8000F35B55 /* db.mm */,
);
path = tests;
Expand Down Expand Up @@ -3464,6 +3510,8 @@
94DE4F772C8C3E7C00FE48FF /* include */ = {
isa = PBXGroup;
children = (
943398222D57E52900287A2D /* jsonParser.hpp */,
94674B842D533B2F00973137 /* trading */,
942966D72D48E84100532862 /* models */,
94B8C7932D3D770800E17EB6 /* utilities */,
941B548F2D3BBA3B00E3BF64 /* trading_definitions */,
Expand Down Expand Up @@ -3569,8 +3617,11 @@
buildActionMask = 2147483647;
files = (
9470B5A42C8C5AD0007D9CC6 /* main.cpp in Sources */,
943398252D57E53400287A2D /* jsonParser.cpp in Sources */,
94280BA32D2FC00200F1CF56 /* base64.cpp in Sources */,
94674B8E2D533E7800973137 /* trade.cpp in Sources */,
941B549B2D3BBADE00E3BF64 /* trading_definitions_json.cpp in Sources */,
94674B872D533B4000973137 /* tradeManager.cpp in Sources */,
94CD8BA02D2E8CE500041BBA /* databaseConnection.cpp in Sources */,
940A61132C92CE210083FEB8 /* configManager.cpp in Sources */,
940A61172C92CE960083FEB8 /* serviceA.cpp in Sources */,
Expand All @@ -3582,9 +3633,14 @@
buildActionMask = 2147483647;
files = (
94CD8BA12D2E8CE500041BBA /* databaseConnection.cpp in Sources */,
943398242D57E53400287A2D /* jsonParser.cpp in Sources */,
94280BA42D2FC00200F1CF56 /* base64.cpp in Sources */,
94674B8D2D533E7800973137 /* trade.cpp in Sources */,
941B549A2D3BBADE00E3BF64 /* trading_definitions_json.cpp in Sources */,
94674B8A2D533BDA00973137 /* tradeManager.mm in Sources */,
940A61182C92CE960083FEB8 /* serviceA.cpp in Sources */,
94674B882D533B4000973137 /* tradeManager.cpp in Sources */,
943398272D57E54000287A2D /* jsonParser.mm in Sources */,
9470B5B62C8C5BFD007D9CC6 /* main.cpp in Sources */,
94364CB62D416D8D00F35B55 /* db.mm in Sources */,
940A61142C92CE210083FEB8 /* configManager.cpp in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Loading