diff --git a/src/data_files/files/spartan/sim_db.sql b/src/data_files/files/spartan/sim_db.sql index 9831c6c87..13778f979 100644 --- a/src/data_files/files/spartan/sim_db.sql +++ b/src/data_files/files/spartan/sim_db.sql @@ -22,6 +22,8 @@ create table run( /* Clock time when we started / ended this run */ begin_time text, end_time text, + realized_pandl real, + position_pandl real, foreign key(session_id) references session(session_id) ); @@ -59,8 +61,8 @@ specific. Some of the standard entries are: - order_update ->* status,symbol, side, last_fills, last_price, ok, sk */ -drop table if exists log_entry; -create table log_entry( +drop table if exists log; +create table log( log_entry_id integer primary_key, run_id numeric, t_time numeric, diff --git a/src/server/sparkd/cmds/Spartan.cpp b/src/server/sparkd/cmds/Spartan.cpp index 95979169b..0519df8fd 100644 --- a/src/server/sparkd/cmds/Spartan.cpp +++ b/src/server/sparkd/cmds/Spartan.cpp @@ -71,7 +71,7 @@ int load_sim_input(std::string const &sim_input) { } } -int run_sim(std::string const &input_file) { +int sim(std::string const &input_file) { spartan::protos::SimSessionOptions options; std::ifstream proto_in(input_file); std::string str((std::istreambuf_iterator(proto_in)), @@ -257,9 +257,9 @@ void validate_fifo(std::string const &pcap) { std::map const &)>> extensions = { - {"run_sim", + {"sim", [](auto const &args) { - run_sim(args[1]); + sim(args[1]); return 0; }}, 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 8752449bb..728601b7d 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 @@ -5,8 +5,8 @@ #include "lib/logging/Logger.h" #include "lib/os/os.h" #include "server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimSessionOptions.pb.h" -#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h" #include "server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandL.h" +#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h" #include #include @@ -15,7 +15,6 @@ namespace bts::spartan::mdp3 { enum class Sniper::State { WATCH, WAIT }; - struct Sniper::Target { constexpr static double Worthless = -1.0; @@ -23,13 +22,9 @@ struct Sniper::Target { std::string const descriptor; double value = Worthless; - void mark_as_worthless() { - value = Worthless; - } + void mark_as_worthless() { value = Worthless; } - bool has_value () const { - return value > securities::market_epsilon(); - } + bool has_value() const { return value > securities::market_epsilon(); } }; struct Sniper::Shot { @@ -41,7 +36,7 @@ struct Sniper::Shot { struct Sniper::DependentTargets { MBPUpdate book; - std::vector dependencies; + std::vector dependencies; }; struct Sniper::PImpl { @@ -82,17 +77,17 @@ void Sniper::init(ISimServices &s, protos::SimRunOptions const &options) { me->observable_time = MDP3TimeStamp{0}; for (auto &p : s.polygons()) { - auto buy_t = Target{ - p.second, polygon_descriptor(p.second, me->sim->instruments())}; - auto sell_t = Target{ - flip(p.second), - polygon_descriptor(flip(p.second), me->sim->instruments())}; + auto buy_t = Target{p.second, + polygon_descriptor(p.second, me->sim->instruments())}; + auto sell_t = + Target{flip(p.second), + polygon_descriptor(flip(p.second), me->sim->instruments())}; me->targets.emplace_back(buy_t); me->targets.emplace_back(sell_t); } - for (auto & t:me->targets) { + for (auto &t : me->targets) { for (auto &pp : t.polygon.parts) { auto &dependencies = me->books[pp.sec_id].dependencies; dependencies.push_back(&t); @@ -113,7 +108,7 @@ api::Side side_from_ratio(int ratio) { return api::Side::SIDE_SELL; } -void Sniper::eval(std::vector const&targets) { +void Sniper::eval(std::vector const &targets) { for (auto &t : targets) { t->value = 0; for (auto &l : t->polygon.parts) { @@ -122,8 +117,7 @@ void Sniper::eval(std::vector const&targets) { if (mkt[0].n_orders < me->min_orders_at_top) { t->mark_as_worthless(); break; - } - else { + } else { auto cash = me->sim->get_sec(l.sec_id).to_cash(mkt[0].price); t->value += -l.ratio * cash; } @@ -131,7 +125,7 @@ void Sniper::eval(std::vector const&targets) { } } -Sniper::MaybeShot Sniper::pick(std::vector &targets) { +Sniper::MaybeShot Sniper::pick(std::vector &targets) { std::sort(targets.begin(), targets.end(), [](Target const *ptr1, Target const *ptr2) { if (std::abs(ptr1->value - ptr2->value) > @@ -145,10 +139,12 @@ Sniper::MaybeShot Sniper::pick(std::vector &targets) { if (targets[0]->has_value()) { for (auto t : targets) if (t->has_value()) - me->sim->log("opportunity",t->descriptor,t->value); - return Shot{*targets[0], me->sim->now(), targets[0]->value, {}}; - } - else + me->sim->log("opportunity", t->descriptor, t->value); + if (me->order_qty) + return Shot{*targets[0], me->sim->now(), targets[0]->value, {}}; + else + return {}; + } else return {}; } @@ -181,9 +177,11 @@ void Sniper::fire(Shot const &s) { order_change.change = OrderChange::removed; me->sim->send(order_change); } + me->sim->log("shot", shot.target.descriptor, shot.observed_ts.value(), + shot.value_at_observation_ts); } -void Sniper::eval_pick_fire(std::vector &targets) { +void Sniper::eval_pick_fire(std::vector &targets) { bts_assert(me->state == State::WATCH); eval(targets); auto best_shot = pick(targets); @@ -195,13 +193,13 @@ void Sniper::eval_pick_fire(std::vector &targets) { void Sniper::operator()(const MBPUpdate &mbp) { - auto it = me->books.find(mbp.security_id) ; + auto it = me->books.find(mbp.security_id); if (it == me->books.end()) return; auto &book = it->second; book.book = mbp; - + switch (me->state) { case State::WATCH: eval_pick_fire(book.dependencies); @@ -218,35 +216,34 @@ void Sniper::operator()(const OrderUpdate &update) { bts_assert(in_flight.fills.count(update.key)); in_flight.fills[update.key].push_back(update); - auto all_done = true; + auto pending_orders = in_flight.fills.size(); for (auto const &p : in_flight.fills) { auto &these_fills = p.second; - if (these_fills.empty() || - these_fills.back().status == OrderUpdate::PARTIALLY_FILLED) { - all_done = false; - break; - } + for (auto &f : these_fills) + if (f.status == OrderUpdate::CANCELED || + f.status == OrderUpdate::FILLED) { + pending_orders--; + break; + } } - if (all_done) { + if (pending_orders == 0) { std::vector all_fills; for (auto const &p : in_flight.fills) { auto &these_fills = p.second; all_fills.insert(all_fills.end(), these_fills.begin(), these_fills.end()); } - PandL pandl (me->sim->instruments()); - me->sim->log("shot", - in_flight.target.descriptor, + PandL pandl(me->sim->instruments()); + me->sim->log("shot_outcome", in_flight.target.descriptor, in_flight.observed_ts.value(), - in_flight.value_at_observation_ts, - me->sim->now().value(), + in_flight.value_at_observation_ts, me->sim->now().value(), pandl.net_cash(all_fills)); me->sim->log_pandl(); me->in_flight.reset(); transition(State::WATCH); - std::vector all_targets_ptr; + std::vector all_targets_ptr; for (auto &t : me->targets) all_targets_ptr.push_back(&t); eval_pick_fire(all_targets_ptr); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp index 261fdfea4..1093ad16c 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp @@ -39,10 +39,8 @@ FifoSecurityMatcher::_find_order(MDP3OrderKey key) { auto map_it = _order_map.find(key); if(map_it != _order_map.end()){ auto& ord = map_it->second; - if(ord.is_active){ - FifoPriceLevelMatcher* p_level = _find_price_level(ord.side,ord.price); - return std::make_tuple(p_level,&ord); - } + FifoPriceLevelMatcher* p_level = _find_price_level(ord.side,ord.price); + return std::make_tuple(p_level,&ord); } return std::tuple( nullptr, nullptr); @@ -68,7 +66,7 @@ void FifoSecurityMatcher::_cleanup() { }); } void FifoSecurityMatcher::_on_new_order(const MDP3Order &ord, - std::vector* res) { + std::vector* res) { _log_trace_order(ord,"FifoSecurityMatcher::_on_new_order begin"); auto& opp_book = _book(_opp_side(ord.side)); uint32_t new_ord_rem = total_quantity(ord).value(); @@ -116,16 +114,6 @@ void FifoSecurityMatcher::_on_new_order(const MDP3Order &ord, ord_corrected.quantity = MDP3Quantity(new_ord_rem); price_level->on_new_same_side_order(ord_corrected); } - else{ - // since _on_new_order is also the same code path - // thats called when an order changes price levels - auto it = _order_map.find(ord.key); - if(it != _order_map.end()){ - MatcherOrder& ex_ord = it->second; - ex_ord.quantity = MDP3Quantity(0); - ex_ord.is_active = false; - } - } } void FifoSecurityMatcher::_on_order_update(const MDP3Order &ord, diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimOrchestrator.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimOrchestrator.cpp index bc5435e39..d3731139b 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimOrchestrator.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimOrchestrator.cpp @@ -156,8 +156,8 @@ void SimOrchestrator::run() { db.log(rid, ts, entry_type, args); }; ExchangeSim sim(logger, r->inputs); - sim.run(*algo, r->options); - db.end_run(rid); + auto pandl = sim.run(*algo, r->options); + db.end_run(rid, pandl.cash, pandl.position); } }); } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.cpp index 4e5025b81..505dee91d 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.cpp @@ -13,12 +13,20 @@ namespace bts::spartan::mdp3 { +struct SimDB::PendingLog { + RunID rid; + MDP3TimeStamp ts; + std::string log_entry_type; + std::vector args; +}; + struct SimDB::PImpl { PImpl(std::string const &loc) : db(loc, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE), lock() {} SQLite::Database db; std::mutex lock; + std::vector pending; }; SimDB::SimDB(std::string const &loc) { @@ -101,53 +109,73 @@ SimDB::RunID SimDB::begin_run(SessionID sid, return run_id; } -void SimDB::end_run(RunID run_id) { +void SimDB::end_run(RunID run_id, double realized_pandl, + double position_pandl) { std::lock_guard l(me->lock); auto update_run = "update run " "set " - "end_time=:end_time " + "end_time=:end_time, " + "realized_pandl=:realized_pandl," + "position_pandl=:position_pandl " "where " "run_id=:run_id"; SQLite::Statement statement(me->db, update_run); statement.bind(":end_time", datetime::time_string(datetime::now())); statement.bind(":run_id", run_id.value()); + statement.bind(":realized_pandl", realized_pandl); + statement.bind(":position_pandl", position_pandl); statement.exec(); + if (me->pending.size()) + _log(true); } void SimDB::log(RunID rid, MDP3TimeStamp now, std::string const &entry_type, std::initializer_list const &log_args) { bts_assert(log_args.size()); - return; - std::lock_guard l(me->lock); + me->pending.emplace_back(PendingLog{rid, now, entry_type, log_args}); + _log(false); +} - std::ostringstream insert_log_entry; - insert_log_entry << "insert into log_entry(" - "run_id," - "t_time," - "h_t_time," - "entry_type"; - for (size_t i = 0; i < log_args.size(); i++) - insert_log_entry << ",val" << i + 1; - insert_log_entry << ") values (:run_id,:t_time,:h_t_time,:entry_type"; - for (size_t i = 0; i < log_args.size(); i++) - insert_log_entry << ",:val" << i + 1; - insert_log_entry << ")"; +void SimDB::_log(bool flush) { + if (me->pending.size() > 100 || flush) { + me->db.exec("begin"); + for (auto &l : me->pending) { + auto rid = l.rid; + auto now = l.ts; + auto &entry_type = l.log_entry_type; + auto &log_args = l.args; - SQLite::Statement statement(me->db, insert_log_entry.str()); - statement.bind(":run_id", rid.value()); - statement.bind(":t_time", (long long)now.value()); - statement.bind(":h_t_time", to_time_string(now)); - statement.bind(":entry_type", entry_type); + std::ostringstream insert_log_entry; + insert_log_entry << "insert into log(" + "run_id," + "t_time," + "h_t_time," + "entry_type"; + for (size_t i = 0; i < log_args.size(); i++) + insert_log_entry << ",val" << i + 1; + insert_log_entry << ") values (:run_id,:t_time,:h_t_time,:entry_type"; + for (size_t i = 0; i < log_args.size(); i++) + insert_log_entry << ",:val" << i + 1; + insert_log_entry << ")"; - size_t i = 1; - for (auto &arg : log_args) { - statement.bind(fmt::format(":val{}", i++), arg); + SQLite::Statement statement(me->db, insert_log_entry.str()); + statement.bind(":run_id", rid.value()); + statement.bind(":t_time", (long long)now.value()); + statement.bind(":h_t_time", to_time_string(now)); + statement.bind(":entry_type", entry_type); + + size_t i = 1; + for (auto &arg : log_args) { + statement.bind(fmt::format(":val{}", i++), arg); + } + statement.exec(); + } + me->db.exec("commit"); + me->pending.clear(); } - - statement.exec(); } void SimDB::_add_param(RunID run_id, std::string const ¶m_name, diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.h b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.h index 2719e099a..88b5602fb 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/sim_db/SimDB.h @@ -23,7 +23,7 @@ class SimDB { using RunID = utils::ValueWrapper; RunID begin_run(SessionID, protos::SimRunOptions const &); - void end_run(RunID); + void end_run(RunID,double realized_pandl, double position_pandl); void log(RunID, MDP3TimeStamp, std::string const &log_entry_type, std::initializer_list const &log_args); @@ -41,7 +41,9 @@ class SimDB { void _add_param(RunID, std::string const ¶m_name, std::string const ¶m_value); + void _log(bool flush = false); int last_insert_rowid(); + struct PendingLog; struct PImpl; std::unique_ptr me; }; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.cpp index 6a46cf5df..6941298a0 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.cpp @@ -61,8 +61,9 @@ ExchangeSim::ExchangeSim(SimLogger const &logger, ExchangeSim::~ExchangeSim() {} -void ExchangeSim::run(IAlgoModel &algo, const protos::SimRunOptions &options) { - run({&algo}, options); +PandLSummary ExchangeSim::run(IAlgoModel &algo, + const protos::SimRunOptions &options) { + return run({&algo}, options); } void ExchangeSim::prepare_run(std::vector const &algos, @@ -107,15 +108,17 @@ void ExchangeSim::prepare_run(std::vector const &algos, me->run_state->simulator.emit_event(first_ev_ts.value() - 1); } -void ExchangeSim::run(std::vector const &algos, - const protos::SimRunOptions &options) { +PandLSummary ExchangeSim::run(std::vector const &algos, + const protos::SimRunOptions &options) { prepare_run(algos, options); while (has_work()) do_work(); + PandLSummary summary; for (auto &a : me->run_state->algos) - a.finit(); + summary += a.finit(); + return summary; } bool ExchangeSim::has_work() const { @@ -147,19 +150,16 @@ void ExchangeSim::do_work() { completed_events - me->run_state->last_completed_count; size_t elapsed_secs = sec_diff(now, me->run_state->run_start); - auto eta = (remaining_events * elapsed_secs / completed_events) ; + auto eta = (remaining_events * elapsed_secs / completed_events); auto TPS = completed_this_cycle / log_period_s; - + me->run_state->last_time_log = now; me->run_state->last_sim_time = sim_time; me->run_state->last_completed_count = completed_events; - + LOG(Spartan, Info, "Simulation Status -> Time: {} TPS: {} Complete: {}% ETA: {} secs", - to_time_string(MDP3TimeStamp{sim_time}), - TPS, - p_complete, - eta); + to_time_string(MDP3TimeStamp{sim_time}), TPS, p_complete, eta); } } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.h b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.h index 71af79391..5e82f5b97 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/ExchangeSim.h @@ -3,6 +3,7 @@ #include "../../common/mdp3_common.h" #include "server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimSessionOptions.pb.h" #include "server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/SimLogger.h" +#include "server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandLSummary.h" #include "IExchangeServices.h" #include "SimInput.h" @@ -21,12 +22,12 @@ class ExchangeSim : public IExchangeServices { ~ExchangeSim(); // Run a single algo through all the SimInput events - void run(IAlgoModel &, - const protos::SimRunOptions & = protos::SimRunOptions()); + PandLSummary run(IAlgoModel &, + const protos::SimRunOptions & = protos::SimRunOptions()); // Run a set of algos - void run(std::vector const &, - const protos::SimRunOptions & = protos::SimRunOptions()); + PandLSummary run(std::vector const &, + const protos::SimRunOptions & = protos::SimRunOptions()); private: struct PImpl; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandLSummary.h b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandLSummary.h new file mode 100644 index 000000000..a2f3db11b --- /dev/null +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandLSummary.h @@ -0,0 +1,15 @@ +#pragma once + +namespace bts::spartan::mdp3 { + +struct PandLSummary { + double cash = 0; + double position = 0; + PandLSummary &operator+=(PandLSummary const &rhs) { + cash += rhs.cash; + position += rhs.position; + return *this; + } +}; + +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.cpp index c3376665d..d7d155a90 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.cpp @@ -66,39 +66,46 @@ void AlgoAgent::handle(sim::Event const &ev) { } } +double AlgoAgent::price_at_market(MDP3SecurityID id, MDP3Quantity qty, + api::Side s) const { + auto book = me->services.book(id, securities::other_side(s)); + double cummulative_flow = 0; + auto remaining_qty = qty.value(); + for (auto &l : book) { + if (remaining_qty == 0) + return cummulative_flow; + else { + auto from_this_level = std::min(remaining_qty, l.quantity.value()); + cummulative_flow += + (from_this_level * get_sec(id).to_cash(l.price.price())); + remaining_qty -= from_this_level; + } + } + if (remaining_qty) + return os::nan(); + else + return cummulative_flow; +} + void AlgoAgent::log_pandl() { auto mkt_pricer = [this](MDP3SecurityID id, MDP3Quantity qty, api::Side s) { - auto book = me->services.book(id, securities::other_side(s)); - double cummulative_flow = 0; - auto remaining_qty = qty.value(); - for (auto &l : book) { - if (remaining_qty == 0) - return cummulative_flow; - else { - auto from_this_level = std::min(remaining_qty, l.quantity.value()); - cummulative_flow += - (from_this_level * get_sec(id).to_cash(l.price.price())); - remaining_qty -= from_this_level; - } - } - if (remaining_qty) - return os::nan(); - else - return cummulative_flow; + return price_at_market(id, qty, s); }; PandL pl{me->instruments, mkt_pricer}; - auto outright_pos = pl.outright_position(me->my_fills) ; + auto outright_pos = pl.outright_position(me->my_fills); log("pnl", pl.net_cash(me->my_fills), pl.position_liquidation_value(outright_pos)); for (auto &[id, pos] : outright_pos) - log("outright_pos",get_sec(id).symbol(),pos); + if (pos) + log("outright_pos", get_sec(id).symbol(), pos); - auto per_symbol_pnl = pl.symbol_net_cash(me->my_fills) ; + auto per_symbol_pnl = pl.symbol_net_cash(me->my_fills); for (auto &[symbol, cash] : per_symbol_pnl) - log("symbol_pnl", symbol, cash); + if (std::abs(cash) > securities::market_epsilon()) + log("symbol_pnl", symbol, cash); } AlgoAgent::~AlgoAgent() {} @@ -136,13 +143,25 @@ void AlgoAgent::send(OrderChange const &change, uint64_t propagation_delay) { void AlgoAgent::_log(std::string const &log_entry_type, std::initializer_list const &log_args) { std::ostringstream str; - str << to_time_string (now()) << " " << log_entry_type << " "; + str << to_time_string(now()) << " " << log_entry_type << " "; for (auto const &a : log_args) str << a << " "; - LOG(Spartan,Info,"{}", str.str()); + LOG(Spartan, Info, "{}", str.str()); me->services.log(now(), log_entry_type, log_args); } -void AlgoAgent::finit() { log_pandl(); } +PandLSummary AlgoAgent::finit() { + log_pandl(); + + auto mkt_pricer = [this](MDP3SecurityID id, MDP3Quantity qty, api::Side s) { + return price_at_market(id, qty, s); + }; + PandL pl{me->instruments, mkt_pricer}; + auto outright_pos = pl.outright_position(me->my_fills); + return { + pl.net_cash(me->my_fills), + pl.position_liquidation_value(outright_pos) + }; +} } // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.h b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.h index c5bb41176..f27b753d4 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/AlgoAgent.h @@ -5,6 +5,7 @@ #include "../core/AgentBase.h" #include "../events/SimEvents.h" #include "server/sparkd/cmds/spartan/md/mdp3/back_testing/orchestrator/SimSessionOptions.pb.h" +#include "server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/PandLSummary.h" #include #include @@ -30,8 +31,7 @@ class AlgoAgent : ISimServices, public sim::AgentBase { // From IAgent void init() override; void handle(sim::Event const &) override; - - void finit(); + PandLSummary finit(); private: // From ISimservices @@ -47,9 +47,7 @@ private: void send(OrderChange const &, uint64_t propagation_delay) override; // End ISimServices - double price_to_cash(MDP3SecurityID, double) const; - double net_cash_flow(std::vector const&fills) const; - std::unordered_map per_symbol_net_cash_flow() const; + double price_at_market(MDP3SecurityID id, MDP3Quantity qty, api::Side) const; struct PImpl; std::unique_ptr me; };