diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6a9c312..6c2052d 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index aa72f65..66a3b47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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) diff --git a/include/env/MarketEnvironment.cpp b/include/env/MarketEnvironment.cpp index c1bc781..e26360e 100644 --- a/include/env/MarketEnvironment.cpp +++ b/include/env/MarketEnvironment.cpp @@ -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"; + } } } diff --git a/src/main.cpp b/src/main.cpp index f93774d..5e842e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; }