Fix synthetic_net_change unit test

This commit is contained in:
Eric Harding committed 2019-02-22 08:37:21 -05:00
1 parent 1205a35b69
commit bf0507e434
2 files changed
+18 -6

No files matched your search

+3
View File
@@ -15,6 +15,9 @@ struct Co2TestInstrument
MDProducerHandle producer();
MDConsumerHandle consumer();
ColdEntry& cold() { return *_cold; }
private:
std::shared_ptr<uint8_t> _cold_buffer;
ColdEntry* _cold;
+15 -6
View File
@@ -103,22 +103,29 @@ tuple<shared_ptr<SyntheticStrategy>,vector<Co2TestInstrument>> make_securities(c
api::Side side;
std::tie(quantity, mult, tick_size, side) = ldesc;
Co2TestInstrument instr("ES", api::SECURITYTYPE_FUTURE);
// tick_size / display_factor
auto display_factor = pow10(instr.cold().security.display_factor);
instr.cold().security.low_tick = tick_size / display_factor;
instr.cold().security.high_tick = tick_size / display_factor;
instr.producer().set_key(security_key);
++security_key;
auto& s = synthetic->security;
// Set the synthetic tick size equal to the (last) leg. (needs to not be 0)
s.mutable_contract_spec()->set_low_tick(tick_size);
s.mutable_contract_spec()->set_high_tick(tick_size);
auto* ps = s.mutable_synthetic();
auto l = ps->mutable_legs()->Add();
l->mutable_security()->CopyFrom(instr.consumer().get_normalized_security());
l->mutable_security()->mutable_contract_spec()->set_low_tick(tick_size);
l->mutable_security()->mutable_contract_spec()->set_high_tick(tick_size);
l->set_quantity(quantity);
l->set_price_multiplier(quantity * (side == api::SIDE_BUY ? 1.0 : -1));
l->set_side(side);
synthetic->legs.push_back(instr.consumer());
legs.push_back(instr);
}
return { synthetic, legs };
}
// tuple = (quantity, tick_size, side)
@@ -381,7 +388,11 @@ TEST_CASE("AggregationAcrossLevels", "[md][synthetic]") {
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 }});
// This tick size is what you get when you make up a test and then later have to figure out the tick size because NetChange suddenly depends on tick size
tie(synthetic, test_instr) = make_securities({ {1.0, 10.0, api::SIDE_BUY}, {2.0, 10.0, api::SIDE_SELL }});
// Set to tick in "# ticks"
synthetic->security.mutable_contract_spec()->set_low_tick(1.0);
synthetic->security.mutable_contract_spec()->set_high_tick(1.0);
auto es_buy1 = test_instr[0];
auto es_sell2 = test_instr[1];
MDConsumerHandle synthetic_handle{synthetic};
@@ -404,11 +415,9 @@ TEST_CASE("Synthetic_net_change", "[md][synthetic]") {
{{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}, {50,5}, {70,1}, {80,4}, {100,4}, {110,1}, {130,1}});
// precise {{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}});
{{-1,1}, {-2,7}, {-4,4}, {-7,4}, {-8,2}, {-10,2}},
{{2,2}, {5,5}, {7,1}, {8,4}, {10,4}, {11,1}, {13,1}});
}
}