Refactor part 8.

This commit is contained in:
Pedro Pinto committed 2020-12-10 08:56:14 -05:00
1 parent cef6815e5c
commit 0dc97dd2d9
16 files changed
+29 -28

No files matched your search

@@ -5,7 +5,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h"
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
static auto constexpr Worthless = -1.0;
@@ -169,4 +169,4 @@ void PolyObserver::on_mbp(EventHeader const &h, MBPUpdate const &mbp) {
void PolyObserver::on_time() {}
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -6,9 +6,6 @@
namespace bts::spartan::mdp3 {
struct Polygon;
}
namespace bts::spartan::mdp3::simulator {
class PolyObserver : public IAlgoModel {
public:
@@ -33,4 +30,4 @@ class PolyObserver : public IAlgoModel {
std::unique_ptr<PImpl> me;
};
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -8,7 +8,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h"
#include <boost/container/small_vector.hpp>
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
enum class SniperModel::State {
WAIT_OPPORTUNITY,
@@ -485,4 +485,4 @@ protos::SimRunOptions SniperModel::fill_defaults(protos::SimRunOptions const &in
return result;
}
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -9,7 +9,7 @@ namespace bts::spartan::mdp3 {
struct Polygon;
}
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class SniperModel : public IAlgoModel {
public:
@@ -133,10 +133,16 @@ gen_runs(protos::SimSessionOptions const &options) {
void run_sim(SimDB &db, SimDB::SessionID sid, size_t remaining,
protos::SimRunOptions const &raw_options) {
using namespace simulator;
SniperModel algo;
auto options = algo.fill_defaults(raw_options);
std::unique_ptr<IAlgoModel> algo;
if (raw_options.algo() == "Snipe")
algo.reset(new SniperModel());
else if (raw_options.algo() == "PolyObserver")
algo.reset(new PolyObserver());
else
bts_assert(false);
auto options = algo->fill_defaults(raw_options);
auto rid = db.begin_run(sid, options);
LOG(Spartan, Warn,
"Starting preload for run {}. {} still queued"
@@ -156,7 +162,7 @@ void run_sim(SimDB &db, SimDB::SessionID sid, size_t remaining,
rid.value());
auto event_gen = source.get_event_generator();
Sim sim(algo, options, source.instruments(), source.icebergs(),
Sim sim(*algo, options, source.instruments(), source.icebergs(),
source.polygons(), event_gen, logger);
auto pnl = sim.run();
db.end_run(rid, pnl.cash , pnl.commission, pnl.position);
@@ -8,7 +8,6 @@
namespace bts::spartan::mdp3 {
class MDP3EventGenerator;
class AlgoModel;
void run_sim(protos::SimRunOptions const&);
void run_sim(std::string const&path_to_run_options);
@@ -11,7 +11,7 @@ struct MBPUpdate;
struct OrderUpdate;
}
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class ISim;
@@ -1,6 +1,6 @@
#include "ISim.h"
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
ISim::~ISim() {}
@@ -4,7 +4,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h"
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class ISim {
public:
@@ -34,4 +34,4 @@ void ISim::log(std::string const &log_entry_type, T &&... args) const {
algo_log(log_entry_type, lst);
}
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -17,7 +17,7 @@
#include <queue>
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
enum class Sim::State {
REPLAY, // Get book state from pcap, do not log.
@@ -675,4 +675,4 @@ MDP3TimeStamp Sim::get_send_time(PCapEvent const &ev) const {
return ev.last_packet_send_time;
}
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -16,7 +16,7 @@ namespace bts::spartan::protos {
class SimRunOptions;
}
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class IAlgoModel;
class PCapEventGenerator;
@@ -90,4 +90,4 @@ void Sim::sim_log(std::string const &log_entry_type, T &&... args) const {
_log("sim", log_entry_type, lst);
}
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -2,7 +2,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
#include <queue>
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
struct PCapEventGenerator::PImpl {
PImpl(std::string const &pcap, IChannelObserver &obs)
@@ -103,4 +103,4 @@ void PCapEventGenerator::on_real_time_event(MDP3Event const &ev_in) {
void PCapEventGenerator::on_real_time_channel_loss() { bts_assert(false); }
} // namespace bts::spartan::mdp3::simulator
} // namespace bts::spartan::mdp3
@@ -6,7 +6,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/handler/IChannelObserver.h"
#include <memory>
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class PCapEventGenerator : IChannelObserver {
public:
@@ -6,7 +6,7 @@
#include "server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonFinder.h"
#include "server/sparkd/cmds/spartan/md/mdp3/back_testing/sim/pcap/PCapEvent.h"
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
struct PCapEventSource::PImpl {
std::string pcap_file;
@@ -17,7 +17,7 @@ class InstrumentDefinition;
class MDP3Event;
}
namespace bts::spartan::mdp3::simulator {
namespace bts::spartan::mdp3 {
class PCapEventSource {
public:
@@ -5,7 +5,6 @@
namespace bts::spartan::mdp3 {
class IAlgoModel;
struct AlgoRecord;
using AlgoEventID = std::pair<size_t,size_t> ;