From 590ca3892d21601d133e14598ca4fa7905bfdfe9 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 8 Dec 2020 18:24:36 -0600 Subject: [PATCH] compute_synthetic_book was multiplying leg prices by their qty twice This is a pre-emptive bug fix, as the method has only been fed synths with leg quantities +/-1. --- src/lib/md/IntPrice.h | 3 +++ .../sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/md/IntPrice.h b/src/lib/md/IntPrice.h index 73689cb45..3c35a6a11 100644 --- a/src/lib/md/IntPrice.h +++ b/src/lib/md/IntPrice.h @@ -87,6 +87,9 @@ class IntPrice { _exponent = temp._exponent; return *this; } + IntPrice operator -() { + return IntPrice(-_mantissa, _exponent); + } IntPrice operator * (const IntPrice& other) const { return op(other, [](int64_t m1, int64_t m2) { return m1 * m2; }); } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp index 1e73e0f9b..fe5900f17 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp @@ -116,11 +116,16 @@ void compute_synthetic_book( legs[i].curr_level_qty_used += MDP3Quantity(limiting_factor); auto marginal_cost = md::INT_NAN; for (auto& l : legs) { + // The book's prices have already been multiplied by abs(leg_qty); + // Subtract the leg's cost if qty is negative, otherwise add it + // to the synthetic's marginal cost. + auto lcost = l.curr_price(); + if (l.leg_qty.value() < 0) + lcost = -lcost; if (marginal_cost.is_nan()) - marginal_cost = l.curr_price() * l.leg_qty.value(); + marginal_cost = lcost; else - marginal_cost = - marginal_cost + l.curr_price() * l.leg_qty.value(); + marginal_cost += lcost; } dest.emplace_back(marginal_cost, MDP3Quantity(limiting_factor)); }