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
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ 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(ExecutionRLLib ${LIB_SOURCES})

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

# === Tests ===
enable_testing()
Expand All @@ -34,9 +33,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 ExecutionRLLib)
target_link_libraries(test_env PRIVATE ExecutionRLLib)
target_link_libraries(test_simulation PRIVATE ExecutionRLLib)

add_test(NAME AgentTest COMMAND test_agent)
add_test(NAME EnvTest COMMAND test_env)
Expand Down
18 changes: 10 additions & 8 deletions include/core/ExecutionSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
ExecutionSimulator::ExecutionSimulator(MarketEnvironment& env, QLearningAgent& agent)
: env(env), agent(agent) {}

void ExecutionSimulator::run() {
env.reset();
while (!env.isDone()) {
auto state = env.getState();
int action = agent.chooseAction(state);
double reward = env.step(action);
auto nextState = env.getState();
agent.update(state, action, reward, nextState);
void ExecutionSimulator::run(int episodes) {
for (int episode = 0; episode < episodes; ++episode) {
env.reset();
while (!env.isDone()) {
auto state = env.getState();
int action = agent.chooseAction(state);
double reward = env.step(action);
auto nextState = env.getState();
agent.update(state, action, reward, nextState);
}
}
}
2 changes: 1 addition & 1 deletion include/core/ExecutionSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ExecutionSimulator {
public:
ExecutionSimulator(MarketEnvironment& env, QLearningAgent& agent);
void run();
void run(int episodes = 1);

private:
MarketEnvironment& env;
Expand Down
17 changes: 13 additions & 4 deletions include/env/MarketEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,24 @@ 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();
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 first, second;
if (!std::getline(ss, first, ','))
continue;
if (!std::getline(ss, second, ','))
continue;
try {
prices.push_back(std::stod(second));
} catch (const std::invalid_argument&) {
// likely a header line, skip
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#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;
Expand Down
Loading