SPARK-1666 Add tests for synthetic md calculation

This commit is contained in:
Eric Harding committed 2018-10-01 14:39:04 -04:00
1 parent a6214a47b5
commit 6db1aeea3f
2 files changed
+46 -4

No files matched your search

+2 -2
View File
@@ -197,8 +197,8 @@ TimeStamp copy_depth(const SyntheticStrategy& synth, size_t count, PriceSize* bi
if (leg_params.leg_md_calc() == spark::LegSpreaderParams::NET_CHANGE) {
auto settle = synth.legs[x].settlement_price();
for (size_t d = 0; d < COCONUT_MAX_DEPTH; ++d) {
bids[x] = bids[x] - settle;
asks[x] = asks[x] - settle;
bids[d] = bids[d] - settle;
asks[d] = asks[d] - settle;
}
}
+44 -2
View File
@@ -74,11 +74,15 @@ void expect_market(const MDConsumerHandle& handle, const vector<PS> bids, const
tuple<shared_ptr<SyntheticStrategy>,vector<Co2TestInstrument>> make_securities(const vector<tuple<double, double,api::Side>>& leg_descr) {
vector<Co2TestInstrument> legs;
auto synthetic = make_shared<SyntheticStrategy>();
uint32_t security_key = 100;
for (const auto& ldesc : leg_descr) {
double quantity, tick_size;
api::Side side;
std::tie(quantity, tick_size, side) = ldesc;
Co2TestInstrument instr("ES", api::SECURITYTYPE_FUTURE);
instr.producer().set_key(security_key);
++security_key;
auto& s = synthetic->security;
s.mutable_contract_spec()->set_low_tick(tick_size);
s.mutable_contract_spec()->set_high_tick(tick_size);
@@ -90,12 +94,16 @@ tuple<shared_ptr<SyntheticStrategy>,vector<Co2TestInstrument>> make_securities(c
l->set_side(side);
synthetic->legs.push_back(instr.consumer());
legs.push_back(instr);
// We *should* insert a LegSpreaderParams into the synthetic->strategy.leg_params_map()
// but c++ makes it really troublesome
}
return { synthetic, legs };
}
void set_leg_params(SyntheticStrategy& strat, uint security_key, const spark::LegSpreaderParams& params) {
auto* map = strat.strategy.mutable_leg_params_map();
map->insert({ security_key, params });
}
TEST_CASE("SyntheticBookMerge", "[md][synthetic]") {
shared_ptr<SyntheticStrategy> synthetic;
vector<Co2TestInstrument> test_instr;
@@ -227,6 +235,40 @@ TEST_CASE("SPARK-955", "[md][synthetic]") {
{ {5.00, 3}, {5.25, 1}, {6.00,3}, {6.50,6} });
}
TEST_CASE("Synthetic_net_change", "[md][synthetic]") {
shared_ptr<SyntheticStrategy> synthetic;
vector<Co2TestInstrument> test_instr;
tie(synthetic, test_instr) = make_securities({ {1.0, 0.01, api::SIDE_BUY}, {2.0, 0.01, api::SIDE_SELL }});
auto es_buy1 = test_instr[0];
auto es_sell2 = test_instr[1];
MDConsumerHandle synthetic_handle{synthetic};
// Set legs to use net change
spark::LegSpreaderParams lparam;
lparam.set_leg_md_calc(spark::LegSpreaderParams::NET_CHANGE);
set_leg_params(*synthetic, es_buy1.producer().key(), lparam);
set_leg_params(*synthetic, es_sell2.producer().key(), lparam);
// set settlement prices
es_buy1.producer().update_settlement(TimeStamp::now(), { 100, 0 }, datetime::today());
es_sell2.producer().update_settlement(TimeStamp::now(), { 50, 0 }, datetime::today());
SECTION("buy 1 sell 2 Net") {
setup_market(es_buy1.producer(),
{{190,1}, {180,11}, {170,4}, {160,10}},
{{200,2}, {210,6}, {220,8}, {230,12}});
setup_market(es_sell2.producer(),
{{90,5}, {80,9}, {70,11}, {60,10}, {50,1}},
{{100,16}, {110,8}, {120,12}, {130,5}});
// Validate merge
expect_market(synthetic_handle,
{{-10,1}, {-20,7}, {-40,4}, {-70,4}, {-80,2}, {-100,2}},
{{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}});
}
}
//
// Benchmarks
//