Refactor, part 7
This commit is contained in:
1 parent
f632fa2e50
commit
4e84b7d789
5 files changed
+42
-42
No files matched your search
@@ -9,7 +9,7 @@ namespace bts::spartan::mdp3::simulator {
|
||||
|
||||
static auto constexpr Worthless = -1.0;
|
||||
|
||||
struct PolyObserver2::Target {
|
||||
struct PolyObserver::Target {
|
||||
size_t polygon_id;
|
||||
Polygon const polygon;
|
||||
std::string const descriptor;
|
||||
@@ -21,14 +21,14 @@ struct PolyObserver2::Target {
|
||||
bool has_value() const { return value > securities::market_epsilon(); }
|
||||
};
|
||||
|
||||
struct PolyObserver2::Opportunity {
|
||||
struct PolyObserver::Opportunity {
|
||||
Target *target;
|
||||
double value;
|
||||
MDP3Quantity quantity;
|
||||
EventHeader start;
|
||||
};
|
||||
|
||||
struct PolyObserver2::PImpl {
|
||||
struct PolyObserver::PImpl {
|
||||
std::vector<std::unique_ptr<Target>> targets;
|
||||
std::optional<Opportunity> current_opportunity;
|
||||
std::unordered_map<MDP3SecurityID, MBPUpdate> books;
|
||||
@@ -36,10 +36,10 @@ struct PolyObserver2::PImpl {
|
||||
ISim *sim = nullptr;
|
||||
};
|
||||
|
||||
PolyObserver2::PolyObserver2() : me(new PImpl()) {}
|
||||
PolyObserver2::~PolyObserver2() {}
|
||||
PolyObserver::PolyObserver() : me(new PImpl()) {}
|
||||
PolyObserver::~PolyObserver() {}
|
||||
|
||||
void PolyObserver2::init(ISim &s, protos::SimRunOptions const&) {
|
||||
void PolyObserver::init(ISim &s, protos::SimRunOptions const&) {
|
||||
me->sim = &s;
|
||||
for (auto &p : s.polygons()) {
|
||||
auto descriptor = polygon_descriptor(p.second, s.instruments());
|
||||
@@ -54,9 +54,9 @@ void PolyObserver2::init(ISim &s, protos::SimRunOptions const&) {
|
||||
}
|
||||
}
|
||||
|
||||
void PolyObserver2::finit() {}
|
||||
void PolyObserver::finit() {}
|
||||
|
||||
void PolyObserver2::on_replay_start(
|
||||
void PolyObserver::on_replay_start(
|
||||
EventHeader const ¤t_event,
|
||||
std::vector<MBPUpdate> const ¤t_books) {
|
||||
me->sim->log("replay_start", current_event.event_id.first);
|
||||
@@ -65,7 +65,7 @@ void PolyObserver2::on_replay_start(
|
||||
me->books[b.security_id] = b;
|
||||
}
|
||||
|
||||
void PolyObserver2::eval() {
|
||||
void PolyObserver::eval() {
|
||||
for (auto &t : me->targets) {
|
||||
t->value = 0;
|
||||
int qty = std::numeric_limits<int>::max();
|
||||
@@ -88,7 +88,7 @@ void PolyObserver2::eval() {
|
||||
}
|
||||
}
|
||||
|
||||
void PolyObserver2::rank() {
|
||||
void PolyObserver::rank() {
|
||||
std::sort(
|
||||
me->targets.begin(), me->targets.end(),
|
||||
[](std::unique_ptr<Target> const &ptr1,
|
||||
@@ -104,7 +104,7 @@ void PolyObserver2::rank() {
|
||||
});
|
||||
}
|
||||
|
||||
void PolyObserver2::try_start_new_opportunity() {
|
||||
void PolyObserver::try_start_new_opportunity() {
|
||||
bts_assert(!me->current_opportunity);
|
||||
auto best = me->targets.begin()->get();
|
||||
if (best->has_value()) {
|
||||
@@ -119,7 +119,7 @@ void PolyObserver2::try_start_new_opportunity() {
|
||||
}
|
||||
}
|
||||
|
||||
void PolyObserver2::analyze() {
|
||||
void PolyObserver::analyze() {
|
||||
if (me->current_opportunity) {
|
||||
auto &opportunity = *me->current_opportunity;
|
||||
auto &target = *opportunity.target;
|
||||
@@ -157,9 +157,9 @@ void PolyObserver2::analyze() {
|
||||
}
|
||||
}
|
||||
|
||||
void PolyObserver2::on_order_update(EventHeader const &, OrderUpdate const &) {bts_assert(false);}
|
||||
void PolyObserver::on_order_update(EventHeader const &, OrderUpdate const &) {bts_assert(false);}
|
||||
|
||||
void PolyObserver2::on_mbp(EventHeader const &h, MBPUpdate const &mbp) {
|
||||
void PolyObserver::on_mbp(EventHeader const &h, MBPUpdate const &mbp) {
|
||||
me->last_event = h;
|
||||
me->books[mbp.security_id] = mbp;
|
||||
eval();
|
||||
@@ -167,6 +167,6 @@ void PolyObserver2::on_mbp(EventHeader const &h, MBPUpdate const &mbp) {
|
||||
analyze();
|
||||
}
|
||||
|
||||
void PolyObserver2::on_time() {}
|
||||
void PolyObserver::on_time() {}
|
||||
|
||||
} // namespace bts::spartan::mdp3::simulator
|
||||
@@ -10,10 +10,10 @@ struct Polygon;
|
||||
|
||||
namespace bts::spartan::mdp3::simulator {
|
||||
|
||||
class PolyObserver2 : public IAlgoModel {
|
||||
class PolyObserver : public IAlgoModel {
|
||||
public:
|
||||
PolyObserver2();
|
||||
~PolyObserver2();
|
||||
PolyObserver();
|
||||
~PolyObserver();
|
||||
|
||||
void init(ISim &, protos::SimRunOptions const&) override;
|
||||
void finit() override;
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
|
||||
namespace bts::spartan::mdp3::simulator {
|
||||
|
||||
enum class Sniper2::State {
|
||||
enum class SniperModel::State {
|
||||
WAIT_OPPORTUNITY,
|
||||
WAIT_FILLS,
|
||||
WAIT_OPPORTUNITY_CLEAR
|
||||
};
|
||||
|
||||
struct Sniper2::Target {
|
||||
struct SniperModel::Target {
|
||||
constexpr static double Worthless = -1.0;
|
||||
size_t polygon_id;
|
||||
Polygon const polygon;
|
||||
@@ -29,12 +29,12 @@ struct Sniper2::Target {
|
||||
bool has_value(double v) const { return value > v; }
|
||||
};
|
||||
|
||||
struct Sniper2::WorkingOrder {
|
||||
struct SniperModel::WorkingOrder {
|
||||
SmallOrderChange order;
|
||||
std::vector<OrderUpdate> fills;
|
||||
};
|
||||
|
||||
struct Sniper2::Shot {
|
||||
struct SniperModel::Shot {
|
||||
Target ⌖
|
||||
EventHeader observed;
|
||||
double value_at_observation_ts;
|
||||
@@ -43,13 +43,13 @@ struct Sniper2::Shot {
|
||||
std::unordered_map<MDP3OrderKey, WorkingOrder> working;
|
||||
};
|
||||
|
||||
struct Sniper2::DependentTargets {
|
||||
struct SniperModel::DependentTargets {
|
||||
InstrumentDefinition definition;
|
||||
MBPUpdate book;
|
||||
std::vector<Target *> dependencies;
|
||||
};
|
||||
|
||||
struct Sniper2::PImpl {
|
||||
struct SniperModel::PImpl {
|
||||
ISim *sim = nullptr;
|
||||
protos::SimRunOptions options;
|
||||
int min_orders_at_top;
|
||||
@@ -78,15 +78,15 @@ struct Sniper2::PImpl {
|
||||
std::optional<Shot> current_shot{};
|
||||
};
|
||||
|
||||
Sniper2::Sniper2() : me(new PImpl()) {}
|
||||
Sniper2::~Sniper2() {}
|
||||
SniperModel::SniperModel() : me(new PImpl()) {}
|
||||
SniperModel::~SniperModel() {}
|
||||
|
||||
void Sniper2::init(ISim &s, protos::SimRunOptions const &options) {
|
||||
void SniperModel::init(ISim &s, protos::SimRunOptions const &options) {
|
||||
me->sim = &s;
|
||||
me->options = options;
|
||||
}
|
||||
|
||||
void Sniper2::on_replay_start(EventHeader const &h,
|
||||
void SniperModel::on_replay_start(EventHeader const &h,
|
||||
std::vector<MBPUpdate> const &books) {
|
||||
auto sim = me->sim;
|
||||
auto options = me->options;
|
||||
@@ -146,7 +146,7 @@ void Sniper2::on_replay_start(EventHeader const &h,
|
||||
}
|
||||
}
|
||||
|
||||
void Sniper2::on_mbp(EventHeader const &h, const MBPUpdate &mbp) {
|
||||
void SniperModel::on_mbp(EventHeader const &h, const MBPUpdate &mbp) {
|
||||
me->current_event = h;
|
||||
auto it = me->books.find(mbp.security_id);
|
||||
if (it == me->books.end())
|
||||
@@ -179,7 +179,7 @@ void Sniper2::on_mbp(EventHeader const &h, const MBPUpdate &mbp) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sniper2::on_order_update(EventHeader const &h, const OrderUpdate &update) {
|
||||
void SniperModel::on_order_update(EventHeader const &h, const OrderUpdate &update) {
|
||||
me->current_event = h;
|
||||
bts_assert(me->state == State::WAIT_FILLS);
|
||||
bts_assert(me->current_shot);
|
||||
@@ -230,7 +230,7 @@ void Sniper2::on_order_update(EventHeader const &h, const OrderUpdate &update) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sniper2::on_time() {
|
||||
void SniperModel::on_time() {
|
||||
auto ts = me->sim->time();
|
||||
|
||||
switch (me->state) {
|
||||
@@ -281,7 +281,7 @@ void Sniper2::on_time() {
|
||||
}
|
||||
}
|
||||
|
||||
void Sniper2::eval(std::vector<Target *> const &targets) {
|
||||
void SniperModel::eval(std::vector<Target *> const &targets) {
|
||||
for (auto &t : targets) {
|
||||
t->value = 0;
|
||||
int qty = me->max_qty;
|
||||
@@ -307,7 +307,7 @@ void Sniper2::eval(std::vector<Target *> const &targets) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Sniper2::within_safety_margin(Target const &t) const {
|
||||
bool SniperModel::within_safety_margin(Target const &t) const {
|
||||
Book synth_book;
|
||||
using LegInfo = std::tuple<MDP3Quantity, md::IntPrice, Book>;
|
||||
std::vector<LegInfo> leg_mkts;
|
||||
@@ -347,7 +347,7 @@ bool Sniper2::within_safety_margin(Target const &t) const {
|
||||
return cumm_qty >= me->min_cumm_qty;
|
||||
}
|
||||
|
||||
Sniper2::MaybeShot Sniper2::pick() {
|
||||
SniperModel::MaybeShot SniperModel::pick() {
|
||||
std::sort(
|
||||
me->targets.begin(), me->targets.end(),
|
||||
[](std::unique_ptr<Target> const &ptr1,
|
||||
@@ -384,7 +384,7 @@ Sniper2::MaybeShot Sniper2::pick() {
|
||||
return {};
|
||||
}
|
||||
|
||||
void Sniper2::fire(Shot const &s) {
|
||||
void SniperModel::fire(Shot const &s) {
|
||||
auto &shot = me->current_shot.emplace(s);
|
||||
me->sim->log("shot_begin", s.target.descriptor,
|
||||
api::Side_Name(s.target.side), s.value_at_observation_ts,
|
||||
@@ -453,7 +453,7 @@ void Sniper2::fire(Shot const &s) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *Sniper2::state_name(State s) {
|
||||
const char *SniperModel::state_name(State s) {
|
||||
switch (s) {
|
||||
case State::WAIT_FILLS:
|
||||
return "WAIT_FILLS";
|
||||
@@ -465,12 +465,12 @@ const char *Sniper2::state_name(State s) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Sniper2::transition(State new_state) {
|
||||
void SniperModel::transition(State new_state) {
|
||||
me->sim->log("transition", state_name(new_state), me->streak_id);
|
||||
me->state = new_state;
|
||||
}
|
||||
|
||||
protos::SimRunOptions Sniper2::fill_defaults(protos::SimRunOptions const &in) {
|
||||
protos::SimRunOptions SniperModel::fill_defaults(protos::SimRunOptions const &in) {
|
||||
protos::SimRunOptions result = in;
|
||||
set_param_if_empty(&result, "min_orders_at_top", 1);
|
||||
set_param_if_empty(&result, "max_qty", 1);
|
||||
|
||||
@@ -11,10 +11,10 @@ struct Polygon;
|
||||
|
||||
namespace bts::spartan::mdp3::simulator {
|
||||
|
||||
class Sniper2 : public IAlgoModel {
|
||||
class SniperModel : public IAlgoModel {
|
||||
public:
|
||||
Sniper2();
|
||||
~Sniper2();
|
||||
SniperModel();
|
||||
~SniperModel();
|
||||
|
||||
void init(ISim &, protos::SimRunOptions const&) override;
|
||||
protos::SimRunOptions fill_defaults (protos::SimRunOptions const&) override;
|
||||
|
||||
@@ -135,7 +135,7 @@ void run_sim(SimDB &db, SimDB::SessionID sid, size_t remaining,
|
||||
protos::SimRunOptions const &raw_options) {
|
||||
using namespace simulator;
|
||||
|
||||
Sniper2 algo;
|
||||
SniperModel algo;
|
||||
auto options = algo.fill_defaults(raw_options);
|
||||
auto rid = db.begin_run(sid, options);
|
||||
LOG(Spartan, Warn,
|
||||
|
||||
Reference in new issue
Block a user