quoter tests

This commit is contained in:
Taha Afzal committed 2017-10-05 22:26:11 -04:00
1 parent c499693a63
commit f3b22ff690
4 files changed
+52 -27

No files matched your search

+13 -10
View File
@@ -373,14 +373,17 @@ void SingleLegQuoter::_compute_price_quantity(Price& price, Quantity& quantity)
{
if (idx != _this_leg_index)
{
const orderman::Book leg_book = _order_bridge.get_book(idx);
Price leg_price; Quantity leg_quantity, quoter_leg_quantity;
Quantity leg_target_quantity = _price_quantity_state.remaining_to_fill();
SpreaderUtils::traverse_depth_for_quantity(leg_book, api::BuySell::BUY, Quantity(static_cast<uint32_t>(leg_target_quantity.value() * 1.0 /*TODO*/)), leg_price, leg_quantity);
quoter_leg_quantity = Quantity(static_cast<uint32_t>(1.0 /*TODOit->lean_ratio*/ * leg_quantity.value()));
const orderman::Book& other_leg_book = _order_bridge.get_book(idx);
const LegPropertyData& other_leg_data = _order_bridge.get_leg_data(idx);
Price other_leg_calc_price; Quantity other_leg_calc_quantity, this_leg_calc_quantity;
Quantity this_leg_target_quantity = _price_quantity_state.remaining_to_fill();
double other_leg_total_lean_ratio = other_leg_data.leg_params.quote_params().lean_quantity_ratio() * other_leg_data.size_multiplier() / _this_leg_data.size_multiplier();
double other_leg_target_quantity = this_leg_target_quantity.value() * other_leg_total_lean_ratio;
SpreaderUtils::traverse_depth_for_quantity(other_leg_book, SpreaderUtils::invert_side (other_leg_data.trading_side), Quantity(other_leg_target_quantity), other_leg_calc_price, other_leg_calc_quantity);
this_leg_calc_quantity = Quantity(static_cast<uint32_t>(1.0 /*TODOit->lean_ratio*/ * other_leg_calc_quantity.value()));
PQPair& leg_price_quantity = _aux_comp_data.at(idx);
leg_price_quantity.set(leg_price, leg_quantity, quoter_leg_quantity);
if (_aux_comp_data.at(min_quoter_leg_quantity_index).quoter_leg_quantity.value() <= quoter_leg_quantity.value())
leg_price_quantity.set(other_leg_calc_price, other_leg_calc_quantity, this_leg_calc_quantity);
if (_aux_comp_data.at(min_quoter_leg_quantity_index).quoter_leg_quantity.value() <= this_leg_calc_quantity.value())
min_quoter_leg_quantity_index = idx;
}
}
@@ -390,14 +393,14 @@ void SingleLegQuoter::_compute_price_quantity(Price& price, Quantity& quantity)
Price SingleLegQuoter::_compute_leg_price(const std::vector<PQPair>& leg_values)
{
size_t idx = 0;
double sum = 0;
for (auto it = leg_values.begin(); it != leg_values.end(); it++)
for (size_t idx = 0; idx < _order_bridge.n_legs(); idx++)
{
if (idx != _this_leg_index)
{
const PQPair& leg_pq_pair = leg_values[idx];
const LegPropertyData& leg_data = _order_bridge.get_leg_data (idx);
sum += it->leg_price.value() * leg_data.price_multiplier();
sum += leg_pq_pair.leg_price.value() * leg_data.price_multiplier();
}
}
double rv = _price_quantity_state.target_spread_price().value() - sum; /// TODO, needs a divisor
+1 -1
View File
@@ -192,7 +192,7 @@ private:
// to the size of an other leg.
double _get_equivelant_quantity(size_t leg_index, Quantity quantity);
// using the market of the other legs, computes the
// quoting price and quantity, and if the quantity > 0
// quoting price and quantity
void _compute_price_quantity(Price& price, Quantity& quantity);
Price _compute_leg_price(const std::vector<PQPair>& leg_values);
};
@@ -12,6 +12,7 @@
#include "SpreaderBookkeepingData.h"
#include "SpreaderUtils.h"
#include "../src/lib/utils/bts_chrono.h"
#include "SpreaderOrderUpdateMessage.h"
#include <future>
#include <stdlib.h>
@@ -99,12 +100,14 @@ namespace bts {
_leg_1_qmz.set_outside_ticks(1);
_leg_1_qmz.set_inside_ticks(1);
_leg_1_q_params.set_allocated_quote_mute_zone(&_leg_1_qmz);
_leg_1_q_params.set_lean_quantity_ratio(1.0);
_leg_1_spr_params.set_allocated_quote_params(&_leg_1_q_params);
_leg_1_property_data = new LegPropertyData(0, _leg_1_contract, _leg_1_spr_params, api::BuySell::BUY);
_leg_2_qmz.set_outside_ticks(1);
_leg_2_qmz.set_inside_ticks(1);
_leg_2_q_params.set_allocated_quote_mute_zone(&_leg_2_qmz);
_leg_2_q_params.set_lean_quantity_ratio(1.0);
_leg_2_spr_params.set_allocated_quote_params(&_leg_2_q_params);
_leg_2_property_data = new LegPropertyData(1, _leg_2_contract, _leg_1_spr_params, api::BuySell::BUY);
@@ -266,5 +269,39 @@ namespace bts {
// }
//}
TEST_CASE("Simple Single Quoter Reprice Perf", "[spreader]")
{
SECTION("Reprice Perf")
{
// create sim spreader
bts::spreader::SpreaderManagerSim sim;
// create quoter
OrderTemplate ord_templ;
SingleLegQuoter quoter(sim, ord_templ, 0, Price(0.0), Quantity(100));
REQUIRE(quoter.get_state() == SingleLegQuoter::QuoterState::START);
quoter.init();
REQUIRE(quoter.get_state() == SingleLegQuoter::QuoterState::WAITING_FOR_MARKET);
// fire md update
Book book;
uint16_t book_sizes[] = { 10, 30, 100, 5, 5 };
_fill_book(book, 2500, 0.25, book_sizes, api::BuySell::BUY);
sim.bookkeeping_data->get_leg_data(1).set_book(book);
quoter.update_md(1);
quoter.update_md(1);
quoter.update_order_status(SpreaderOrderUpdateMessage(OrderKey(1), api::orderman::OrderStatus::OS_NEW, Quantity(0), Price(0), Quantity(0), Price(0), NULL));
size_t n_runs = 10, n_updates = 1000000;
for (size_t t = 0; t < n_runs; t++)
{
auto t0 = Timer::now();
for (size_t u = 0; u < n_updates; u++)
quoter.update_md(1);
auto t1 = Timer::now();
int64_t diff = us_diff(t1, t0);
REQUIRE(diff < 10000000);
}
}
}
}
}
+1 -16
View File
@@ -49,22 +49,7 @@ public:
bts_assert_d(out_index < key_to_index_map.size());
return true;
}
}
/*static void fill_leg_shared_data(const bts::api::Security& sec, const bts::spark::ExecutionStrategy& execution_strategy, api::BuySell order_side,
std::vector<LegPropertyData>& out_v)
{
bts_assert(sec.has_synthetic());
size_t index = 0;
for (auto it = sec.synthetic().legs().begin(); it != sec.synthetic().legs().end(); ++it)
{
uint32_t sec_key = it->security().id();
auto st_it = execution_strategy.leg_params_map().find(sec_key);
bts_assert(st_it != execution_strategy.leg_params_map().end());
const bts::api::ContractLeg& leg = *it;
api::BuySell leg_order_side = get_leg_side(order_side, leg);
out_v.push_back(LegPropertyData(index, sec, leg, st_it->second, leg_order_side));
}
}*/
}
const static bts::spark::LegSpreaderParams& find_spread_params(const bts::spark::ExecutionStrategy& exec_strategy,
const bts::api::Security& leg_security)
{