Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 7 additions & 11 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: configure
run: ./configure
- name: make
run: make
- name: make check
run: make check
- name: make distcheck
run: make distcheck
- uses: actions/checkout@v4
- name: Configure
run: cmake -S . -B build
- name: Build
run: cmake --build build
- name: Run tests
run: cd build && ctest --output-on-failure
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ include_directories(
)

# === Source files ===
set(SOURCE_FILES
src/main.cpp

set(LIB_SOURCES
include/agents/QLearningAgent.cpp
include/core/ExecutionSimulator.cpp
include/env/MarketEnvironment.cpp
include/utils/Logger.cpp
include/utils/MathUtils.cpp
)
include/utils/MathUtils.cpp)

add_library(executionrl_lib ${LIB_SOURCES})
target_include_directories(executionrl_lib PUBLIC include)

# === Executable ===
add_executable(ExecutionRL ${SOURCE_FILES})
add_executable(ExecutionRL src/main.cpp)
target_link_libraries(ExecutionRL PRIVATE executionrl_lib)

# === Tests ===
enable_testing()
Expand All @@ -34,9 +34,9 @@ add_executable(test_agent tests/test_agent.cpp)
add_executable(test_env tests/test_env.cpp)
add_executable(test_simulation tests/test_simulation.cpp)

target_include_directories(test_agent PRIVATE include)
target_include_directories(test_env PRIVATE include)
target_include_directories(test_simulation PRIVATE include)
target_link_libraries(test_agent PRIVATE executionrl_lib)
target_link_libraries(test_env PRIVATE executionrl_lib)
target_link_libraries(test_simulation PRIVATE executionrl_lib)

add_test(NAME AgentTest COMMAND test_agent)
add_test(NAME EnvTest COMMAND test_env)
Expand Down
27 changes: 23 additions & 4 deletions include/env/MarketEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,34 @@ bool MarketEnvironment::isDone() const {
}

void MarketEnvironment::loadMarketData() {
std::ifstream file("prices.csv");
std::ifstream file("data/price_series.csv");
if (!file.is_open()) {
file.open("../data/price_series.csv");
}
std::string line;

prices.clear();

// Skip header line if present
if (std::getline(file, line)) {
if (line.find("price") == std::string::npos) {
std::stringstream ss(line);
std::string timestamp, priceStr;
if (std::getline(ss, timestamp, ',') && std::getline(ss, priceStr, ',')) {
prices.push_back(std::stod(priceStr));
}
}
}

while (std::getline(file, line)) {
std::stringstream ss(line);
std::string cell;
if (std::getline(ss, cell, ',')) {
prices.push_back(std::stod(cell));
std::string timestamp, priceStr;
if (std::getline(ss, timestamp, ',') && std::getline(ss, priceStr, ',')) {
try {
prices.push_back(std::stod(priceStr));
} catch (const std::exception& e) {
std::cerr << "Invalid price value: " << priceStr << "\n";
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "include/core/ExecutionSimulator.hpp"
#include "include/env/MarketEnvironment.hpp"
#include "include/agents/QLearningAgent.hpp"
#include "core/ExecutionSimulator.hpp"
#include "env/MarketEnvironment.hpp"
#include "agents/QLearningAgent.hpp"

int main() {
MarketEnvironment env;
QLearningAgent agent(0.1, 0.9, 0.1); // alpha, gamma, epsilon

ExecutionSimulator simulator(env, agent);
simulator.run(1000); // Run for 1000 episodes
simulator.run();

return 0;
}