From 95d8d8a42d3449cbee9c2b70c4675ecc5417035e Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Tue, 10 Nov 2020 10:47:34 -0500 Subject: [PATCH] Better logging for sniper. --- .../md/mdp3/back_testing/algos/Sniper.cpp | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/Sniper.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/Sniper.cpp index f611eb91a..7adbb21bb 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/Sniper.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/Sniper.cpp @@ -70,6 +70,7 @@ struct Sniper::PImpl { MDP3TimeStamp transact_time; MDP3TimeStamp observable_time; AlgoEventID current_event; + size_t streak_id = 0; }; Sniper::Sniper() : me(new PImpl()) {} @@ -242,6 +243,9 @@ Sniper::MaybeShot Sniper::pick() { void Sniper::fire(Shot const &s) { auto &shot = me->current_shot.emplace(s); + me->sim->log("shot_begin", me->current_event.first, me->current_event.second, + s.target.descriptor, s.value_at_observation_ts, + s.quantity.value(), me->streak_id); if (me->ms_to_work_shot == 0) { shot.forced_completion = true; @@ -329,6 +333,7 @@ void Sniper::operator()(const MBPUpdate &mbp) { case State::WAIT_OPPORTUNITY: { auto best_shot = pick(); if (best_shot) { + me->streak_id++; fire(best_shot.value()); transition(State::WAIT_FILLS); } @@ -343,6 +348,7 @@ void Sniper::operator()(const MBPUpdate &mbp) { me->state = State::WAIT_OPPORTUNITY; auto best_shot = pick(); if (best_shot) { + me->streak_id++; fire(best_shot.value()); transition(State::WAIT_FILLS); } @@ -386,14 +392,20 @@ void Sniper::operator()(const OrderUpdate &update) { in_flight.observed_event_id.first, in_flight.observed_event_id.second, me->current_event.first, me->current_event.second, in_flight.value_at_observation_ts * in_flight.quantity.value(), - pandl.net_cash(all_fills)); + pandl.net_cash(all_fills), me->streak_id); me->sim->log_pandl(); if (!me->double_dip) transition(State::WAIT_CLEAR); else { auto best_shot = pick(); - if (best_shot) + if (best_shot) { + me->sim->log( + "double_dip", + me->current_event.first, + me->current_event.second, + me->streak_id); fire(best_shot.value()); + } else transition(State::WAIT_OPPORTUNITY); } @@ -403,15 +415,24 @@ void Sniper::operator()(const OrderUpdate &update) { const char *Sniper::state_name(State s) { switch (s) { case State::WAIT_FILLS: - return "WAIT"; + return "WAIT_FILLS"; case State::WAIT_OPPORTUNITY: - return "WATCH"; + return "WAIT_OPPORTUNITY"; case State::WAIT_CLEAR: return "WAIT_CLEAR"; } return nullptr; } -void Sniper::transition(State new_state) { me->state = new_state; } +void Sniper::transition(State new_state) { + me->sim->log( + "transition", + state_name(new_state), + me->current_event.first, + me->current_event.second, + me->streak_id); + me->state = new_state; + +} } // namespace bts::spartan::mdp3