From 43f4fe20113982bb1304576da099b131398d4cd0 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Thu, 17 Dec 2020 09:39:41 -0500 Subject: [PATCH] Better logging for sniper model. --- src/data_files/files/spartan/sim_db.sql | 48 ++++++++++++------- .../mdp3/back_testing/algos/SniperModel.cpp | 9 ++-- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/data_files/files/spartan/sim_db.sql b/src/data_files/files/spartan/sim_db.sql index bea4ff0d5..466eee5c3 100644 --- a/src/data_files/files/spartan/sim_db.sql +++ b/src/data_files/files/spartan/sim_db.sql @@ -71,6 +71,7 @@ drop view if exists sniper_shots; create view sniper_shots as select run_id, + sim_seq, t_time, h_t_time, val3 begin_eid, @@ -79,38 +80,49 @@ select cast(val6 as real) outcome, cast(val5 as real) / cast(val8 as numeric) target_edge, cast(val8 as numeric) target_quantity, - cast(val9 as bool) clean + cast(val9 as bool) clean, + cast(val10 as bool) forced from log where entry_type='shot_outcome'; +drop view if exists sniper_run_stats; +create view sniper_run_stats as +select + run_id, + sum(outcome) pandl, + count(*) n, + sum(clean) c, + sum(forced) f, + (count(*) - sum(clean) - sum(forced)) s, + (100 * sum(clean) / count(*)) hr, + sum (case when outcome > 0 then 1 else 0 end) w, + sum (case when outcome <= 0 then 1 else 0 end) l, + sum (case when outcome >0 then outcome else 0 end) wcash, + sum (case when outcome <= 0 then outcome else 0 end) lcash +from + sniper_shots +group + by run_id ; + drop view if exists sniper_run; create view sniper_run as select - run_id, market_date mkt_date, base_algo_latency_ns s_latency, - transaction_latency_ns e_latency, - use_first_packet_st fp, - realized_pandl pandl, - position_pandl pos, - param1 p1, + sniper_run_stats.*, param2 p2, - param3 p3, param4 p4, param5 p5, - param6 p6, - param7 p7, param8 p8, param9 p9, - param10 p10, - param11 p11, - param12 p12 + param10 p10 from - run; + run, sniper_run_stats +where + run.run_id = sniper_run_stats.run_id +order by + mkt_date, + pandl; - - - - diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/SniperModel.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/SniperModel.cpp index 521e4ce2e..60f8bc15a 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/SniperModel.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/algos/SniperModel.cpp @@ -191,12 +191,11 @@ void SniperModel::on_order_update(EventHeader const &h, in_flight.working[update.key].fills.push_back(update); auto pending_orders = in_flight.working.size(); - bool all_aggressors = true; + bool clean_fills = true; for (auto const &p : in_flight.working) { auto &these_fills = p.second.fills; for (auto &f : these_fills) { - all_aggressors = - all_aggressors && (f.fill_type == OrderUpdate::AGGRESSIVE); + clean_fills = clean_fills && (f.fill_type == OrderUpdate::AGGRESSIVE); if (f.status == OrderUpdate::CANCELED || f.status == OrderUpdate::FILLED) { pending_orders--; @@ -223,7 +222,9 @@ void SniperModel::on_order_update(EventHeader const &h, api::Side_Name(in_flight.target.side), in_flight.observed.event_id.first, in_flight.observed.event_id.second, in_flight.value_at_observation_ts * in_flight.quantity.value(), net, - commission, in_flight.quantity.value(), all_aggressors); + commission, in_flight.quantity.value(), + clean_fills && !me->current_shot->forced_completion, + me->current_shot->forced_completion); me->sim->log_pandl(); if (!me->double_dip) transition(State::PAUSED);