Dorman Algo : Use the lower value when between entries in the step table

This commit is contained in:
Eric Harding committed 2019-09-04 14:41:59 -04:00
1 parent a31ad90be4
commit 9edb5625c1
2 files changed
+33 -31

No files matched your search

@@ -194,10 +194,12 @@ void DormanAlgo::on_book(SecurityKey key, const Book& book) {
auto target = Quantity {0};
if (available > 0) {
for (const auto& entry : me->params.steps.step_table) {
target = Quantity { std::get<1>(entry) };
if (std::get<0>(entry) > available) {
break;
}
else {
target = Quantity { std::get<1>(entry) };
}
}
}
target = Quantity { std::min(target.value(), me->params.steps.maximum) };
@@ -189,7 +189,6 @@ size_t count_status(const std::vector<ChildOrder>& child_orders, ChildStatus sta
return match;
}
TEST_CASE("dorman_order_size", "[algo][dorman]") {
// create a table of various sizes
// send market state to the algo
@@ -211,13 +210,14 @@ TEST_CASE("dorman_order_size", "[algo][dorman]") {
SECTION("initial size vs market") {
std::vector<ExpectedSize> test_sizes {
{ 10, 250 },
{ 200, 250 },
{ 250, 250 },
{ 500, 400 },
{ 999, 400 },
{ 2500, 750 },
{ 9999, 800 }
{ 10, 0 },
{ 200, 0 },
{ 250, 0 },
{ 500, 250 },
{ 999, 250 },
{ 2500, 600 },
{ 9999, 750 },
{ 20002, 800 },
};
for (auto& s : test_sizes)
@@ -244,10 +244,10 @@ TEST_CASE("dorman_order_size", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(400));
REQUIRE(state.algo().exposed_qty() == Quantity(250));
// Check that orders were created
REQUIRE(400 == count_exposed(state.child_orders()));
REQUIRE(250 == count_exposed(state.child_orders()));
for(const auto& ch : state.child_orders()) {
REQUIRE(ch.cstate.quantity == state.quantity());
}
@@ -255,9 +255,9 @@ TEST_CASE("dorman_order_size", "[algo][dorman]") {
// Reduce market
book.bid()[0] = { some_price, 405 };
state.update_book(book);
REQUIRE(state.algo().exposed_qty() == Quantity(250));
REQUIRE(state.algo().exposed_qty() == Quantity(0));
REQUIRE(
250 == count_exposed(state.child_orders()));
0 == count_exposed(state.child_orders()));
}
SECTION("Increase qty w/ delay when market grows") {
@@ -268,28 +268,28 @@ TEST_CASE("dorman_order_size", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(400));
REQUIRE(state.algo().exposed_qty() == Quantity(250));
// Check that orders were created
REQUIRE(
400 == count_exposed(state.child_orders()));
250 == count_exposed(state.child_orders()));
// INCREASE market
book.bid()[0] = { some_price, 1001 };
state.update_book(book);
// NOTE: that the orders do not follow the market instantly
// so this is still 400
// so this is still 250
REQUIRE(
400 == count_exposed(state.child_orders()));
250 == count_exposed(state.child_orders()));
// Still 400 after the timer ticks but not enough time has passed
// Still 250 after the timer ticks but not enough time has passed
state.advance_time(std::chrono::seconds());
REQUIRE(
400 == count_exposed(state.child_orders()));
250 == count_exposed(state.child_orders()));
state.advance_time(std::chrono::seconds(input.steps.trail_seconds));
REQUIRE(
600 == count_exposed(state.child_orders()));
400 == count_exposed(state.child_orders()));
}
SECTION("Respect maximum") {
@@ -336,7 +336,7 @@ TEST_CASE("Dorman fills", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.algo().exposed_qty() == Quantity(250));
for (const auto& order : state.child_orders()) {
state.fill(order.key, price, order.cstate.quantity);
@@ -360,7 +360,7 @@ TEST_CASE("Dorman fills", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(650));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {500});
// Fill 400
@@ -405,7 +405,7 @@ TEST_CASE("Dorman overfill", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(650));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {100});
REQUIRE(state.child_orders().size() == 1);
@@ -467,7 +467,7 @@ TEST_CASE("Dorman profit-orders", "[algo][dorman]") {
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(650));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {100});
REQUIRE(state.child_orders().size() == 1);
@@ -714,26 +714,26 @@ TEST_CASE("Dorman market move up then back down", "[algo][dorman]") {
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 350 };
book.bid()[0] = { some_price, 1350 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(250));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.child_orders().size() == 1);
state.advance_time(std::chrono::seconds(1));
// Update book sets future quantity = 450
book.bid()[0] = { some_price, 999 };
// Update book sets future quantity = 650
book.bid()[0] = { some_price, 2219 };
state.update_book(book);
state.advance_time(std::chrono::seconds(10));
// Algo does not increase exposure after 10 second
REQUIRE(state.algo().exposed_qty() == Quantity(250));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
book.bid()[0] = { some_price, 425 };
book.bid()[0] = { some_price, 1425 };
state.update_book(book);
state.advance_time(std::chrono::seconds(40));
// Algo does not increase exposure after trail_seconds
REQUIRE(state.algo().exposed_qty() == Quantity(250));
REQUIRE(state.algo().exposed_qty() == Quantity(450));
}