fixed qty calc for N legged
This commit is contained in:
1 parent
e0a8dc62c4
commit
f8d25bf305
2 files changed
+27
-21
No files matched your search
@@ -247,6 +247,7 @@ public:
|
||||
out_quantity = Quantity(cum_quantity_u);
|
||||
out_price = Price(book_depth[last_nonzero_level].price());
|
||||
}
|
||||
bts_assert(out_quantity.value() <= target_quantity.value());
|
||||
}
|
||||
// CRITICAL PATH (for hedging)
|
||||
// travserses the book to locate the target_price, and find the qty at the
|
||||
@@ -486,6 +487,7 @@ public:
|
||||
// corresponds to s1 * N / s2 size on l1 (target).
|
||||
// so if we get an N lot fill in l2, we send a hedge on l1
|
||||
// sized s1 * N / s2
|
||||
////////////////////////general functions
|
||||
static double get_equivelant_size (const LegPropertyData& source_leg, Quantity source_leg_quantity,
|
||||
const LegPropertyData& target_leg)
|
||||
{
|
||||
@@ -493,7 +495,7 @@ public:
|
||||
rv = std::round(rv);
|
||||
return rv;
|
||||
}
|
||||
// given the quantity of the spreader order, determines the quality
|
||||
// given the quantity of the spreader order, determines the quantity
|
||||
// of the leg
|
||||
static double get_leg_quantity_from_spreader_quantity(const LegPropertyData& leg, Quantity spreader_order_quantity)
|
||||
{
|
||||
@@ -501,6 +503,18 @@ public:
|
||||
rv = std::round (rv);
|
||||
return rv;
|
||||
}
|
||||
// finds the average weighted price and total quantity
|
||||
// from 2 prices and qty's pair
|
||||
static void compute_average_price (Price base_price, Quantity base_qty, Price inc_price, Quantity inc_qty,
|
||||
Price& out_avg_price, Quantity& out_total_qty)
|
||||
{
|
||||
out_total_qty = Quantity(base_qty.value() + inc_qty.value());
|
||||
if (out_total_qty.value() == 0)
|
||||
out_avg_price = Price(0);
|
||||
else
|
||||
out_avg_price = Price((base_price.value() * base_qty.value() + inc_price.value() * inc_qty.value())/out_total_qty.value());
|
||||
}
|
||||
////////////////////////2 legged spreads
|
||||
// calculates the computed price and quantity for a quoting
|
||||
// leg given the data for the other leg
|
||||
static void compute_price_quantity_2_legs(Price target_spread_price, Quantity this_leg_target_quantity,
|
||||
@@ -533,6 +547,7 @@ public:
|
||||
out_hedge_price_d = bts::securities::raw_round_to_quote_price (out_hedge_price_d, hedge_leg.tick_size(), hedge_leg.trading_side());
|
||||
out_hedge_price = Price(out_hedge_price_d);
|
||||
}
|
||||
////////////////////////N legged case
|
||||
static void compute_quoting_price_size_n_legs (Price target_spread_price,
|
||||
Quantity quoting_leg_target_quantity,
|
||||
size_t quoting_leg_index,
|
||||
@@ -553,25 +568,25 @@ public:
|
||||
}
|
||||
// given a target quantity for the quoting leg, fills
|
||||
// in the driver for each of the other legs that can
|
||||
// "drive" the quoting leg
|
||||
// "drive" the quoting leg, and puts them in out_driver_vector
|
||||
static void compute_drivers(Quantity quoting_leg_target_quantity,
|
||||
size_t quoting_leg_index,
|
||||
const ISpreaderManager& spreader,
|
||||
std::vector<QuoterLegDriverData>& driver_vector)
|
||||
std::vector<QuoterLegDriverData>& out_driver_vector)
|
||||
{
|
||||
const LegPropertyData& quoting_leg_data = spreader.get_leg_data (quoting_leg_index);
|
||||
size_t n_legs = driver_vector.size();
|
||||
size_t n_legs = out_driver_vector.size();
|
||||
for (size_t idx = 0; idx < n_legs; idx++)
|
||||
if (idx != quoting_leg_index)
|
||||
{
|
||||
const bts::orderman::Book& driver_leg_book = spreader.get_book(idx);
|
||||
const LegPropertyData& driver_leg_data = spreader.get_leg_data(idx);
|
||||
Price driver_price; Quantity driver_quantity;
|
||||
const LegPropertyData& driver_leg_data = spreader.get_leg_data(idx);
|
||||
double driver_effective_mult = std::abs(driver_leg_data.leg_params().quote_params().lean_quantity_ratio() * driver_leg_data.size_multiplier() / quoting_leg_data.size_multiplier());
|
||||
double driver_target_quantity = quoting_leg_target_quantity.value() * driver_effective_mult;
|
||||
Price driver_price; Quantity driver_quantity;
|
||||
SpreaderUtils::traverse_depth_for_quantity(driver_leg_book, SpreaderUtils::invert_side (driver_leg_data.trading_side()), Quantity(driver_target_quantity), driver_price, driver_quantity);
|
||||
Quantity quoting_leg_calc_quantity = Quantity (std::round(driver_quantity.value() / driver_effective_mult));
|
||||
driver_vector[idx].set (driver_price, driver_quantity, quoting_leg_calc_quantity);
|
||||
out_driver_vector[idx].set (driver_price, driver_quantity, quoting_leg_calc_quantity);
|
||||
}
|
||||
}
|
||||
// computes the quoting price from the leg drivers
|
||||
@@ -597,7 +612,7 @@ public:
|
||||
static Quantity compute_quoting_quantity_from_drivers (size_t quoting_leg_index,
|
||||
const std::vector<QuoterLegDriverData>& driver_vector)
|
||||
{
|
||||
Quantity rv(0);
|
||||
Quantity rv(std::numeric_limits<uint32_t>::max());
|
||||
size_t n_legs = driver_vector.size();
|
||||
for (size_t idx = 0; idx < n_legs; idx++)
|
||||
if (idx != quoting_leg_index)
|
||||
@@ -611,16 +626,7 @@ public:
|
||||
{
|
||||
out_hedge_price = Price(bts::securities::raw_round_to_quote_price (driver_price.value(), hedge_leg.tick_size(), hedge_leg.trading_side()));
|
||||
out_hedge_quantity = Quantity (get_equivelant_size (quote_filled_leg, quote_fill_quantity, hedge_leg));
|
||||
}
|
||||
static void compute_average_price (Price base_price, Quantity base_qty, Price inc_price, Quantity inc_qty,
|
||||
Price& out_avg_price, Quantity& out_total_qty)
|
||||
{
|
||||
out_total_qty = Quantity(base_qty.value() + inc_qty.value());
|
||||
if (out_total_qty.value() == 0)
|
||||
out_avg_price = Price(0);
|
||||
else
|
||||
out_avg_price = Price((base_price.value() * base_qty.value() + inc_price.value() * inc_qty.value())/out_total_qty.value());
|
||||
}
|
||||
}
|
||||
/**********************************************************************/
|
||||
/**************************debugging helpers***************************/
|
||||
/**********************************************************************/
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@ namespace orderman {
|
||||
class QuoterLegDriverData
|
||||
{
|
||||
public:
|
||||
// leg_price and leg_quantity are the price and quantity
|
||||
// that can drive a quoter_leg_quantity sized order in
|
||||
// the quoting leg
|
||||
// driver_price and driver_quantity are the price and quantity
|
||||
// in the hedging (or driver) leg that can drive a quoter_leg_quantity
|
||||
// sized order in the quoting leg
|
||||
Price driver_price;
|
||||
Quantity driver_quantity;
|
||||
Quantity quoter_leg_quantity;
|
||||
|
||||
Reference in new issue
Block a user