Merge branch 'spartan_tas' of bitbucket.org:bluetradesys/spark into spartan_tas

This commit is contained in:
Taha Afzal committed 2020-12-17 12:15:27 -05:00
commit 468df062c3
4 files changed
+51 -25

No files matched your search

+31 -18
View File
@@ -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,50 @@ 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,
not(cast(val9 as bool)) and not cast (val10 as bool) saved
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;
@@ -315,5 +315,17 @@ def ib_percentage(fills,begin_eid,event_len):
'SIDE_BUY':ib_percentage_side(ibs['SIDE_BUY'])
}
def parse_latency_logs(file,out_path):
rx = ".*\|Latency.*\|PROD\|(.*)"
with open(out_path,mode='w') as out_file:
with open(file) as f:
for l in f.readlines():
m = re.match(rx,l)
if m:
log = m.groups()[0]
log = log.strip()
log = log.replace("::","_")
row = { nv[0]:nv[1] for nv in [ kv.split(':') for kv in log.strip().split(" ") ] }
if row['sn'] != '0':
print (row['sn'],",",row['entry_type'],",",row['app_arrival'],",",row['now'],file=out_file)
@@ -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);
@@ -132,6 +132,7 @@ void Sim::handle_pending_sim_op() {
bts_assert(me->state == State::REPLAY);
me->pending_sim_op = PendingSimOP::NONE;
me->state = State::PRESIM;
me->sim_seq++;
sim_log("presim_start");
break;
case PendingSimOP::STOP:
@@ -337,7 +338,6 @@ void Sim::on_algo_action() {
void Sim::_start_simulation() {
bts_assert(me->state == State::PRESIM);
bts_assert(!me->simulation);
me->sim_seq++;
me->state = State::SIM;
auto &simulation = me->simulation.emplace();
auto &matcher = simulation.matcher;