Merge branch 'vwap2' of bitbucket.org:bluetradesys/spark into vwap

This commit is contained in:
Kevin Darby committed 2020-02-24 09:49:47 -05:00
commit ba3bcb7dd0
16 files changed
+277 -124

No files matched your search

@@ -691,7 +691,7 @@
<TextBlock VerticalAlignment="Center" >Tick Offset</TextBlock>
<c:HelpButton Margin="{StaticResource Margin.LP1}" ToolTip="How many ticks off the inside market to deploy the order, this guards against crossing the market inadventently" />
</StackPanel>
<c:TickUpDownUInt x:Name="PART_TickOffsetOnDeploy_TickUpDownUInt" Grid.Column="2" Value="{Binding tick_offset_on_deploy}"/>
<c:TickUpDownInt x:Name="PART_TickOffsetOnDeploy_TickUpDownUInt" Grid.Column="2" Value="{Binding tick_offset_on_deploy}"/>
<uag:AlgoPickerNodeView
x:Name="PART_Child_AlgoPickerNodeView"
Grid.Row="2"
+8 -8
View File
@@ -246,6 +246,7 @@ message SplitterOrderDefinition {
uint32 max_order_qty = 1;
uint32 exposed_qty = 2;
bool disable_exposed = 4;
// uint32 target_qty = 3;
CustomOrderDefinition child = 10;
}
@@ -297,21 +298,20 @@ message VolumeDuration {
}
message OrderAggression {
enum ScheduleMode
enum UpgradeMode
{
TacticalThenAggressive = 0;
AggressiveOnly = 1;
AggressiveOnly = 0;
TacticalAndAggressive = 1;
}
ScheduleMode schedule_mode = 10;
UpgradeMode upgrade_mode = 10;
// default = 0, time in periods which to let unexecuted size remain in the tactical channel
uint32 extra_tactical_slices = 15;
uint32 extra_slices = 15;
// default = 0, 0 - 99 be no more than X% of the market, 0.0 means no cap
uint32 max_participation_pct = 20;
// default = 0.0, price at which you will take liquidity regardless of other parameters, 0.0 means there is no iwouldprice
double i_would_price = 30;
// default = 0, 0 - 100 vary size +/- quantity_variance percent, 0 means don't vary the size
uint32 quantity_variance = 40;
uint32 max_child_quantity = 50;
uint32 quantity_variance = 40;
}
message DistributionParameters {
// default = 20, historical volume distribution time horizon
@@ -352,7 +352,7 @@ message ArrivalPriceOrderDefinition {
double adaptivity = 60;
CustomOrderDefinition tactical_child = 200;
CustomOrderDefinition aggressive_child = 210;
CustomOrderDefinition aggressive_child = 210;
}
message VolumeSliceOrderDefinition {
VolumeDuration duration = 10;
@@ -72,6 +72,9 @@ OrderOpResult SplitterAlgo::do_before_launch(IBeforeLaunchAlgoServices& ibl) {
void SplitterAlgo::do_launch(IAlgoServices& ias) {
me->algo = &ias;
me->target_qty = ias.quantity().value();
if(ias.definition().custom_def().splitter().disable_exposed())
me->exposed_qty = ias.quantity().value();
// launches initial child orders
sync_orders();
}
@@ -87,6 +90,8 @@ void SplitterAlgo::do_update(const api::orderman::Update& update) {
me->clip = splitter.max_order_qty();
}
me->exposed_qty = splitter.exposed_qty();
if(splitter.disable_exposed())
me->exposed_qty = update.quantity();
if (splitter.has_child()) {
update_child_template(algo());
@@ -14,6 +14,8 @@ namespace splitter {
exposed_qty
-- The total quantity we want visible on the exchange.
-- This will typically be higher than the quantity which helps capture fills in pro-rata algorithms
disable_exposed
-- if false, exposed_qty acts as above, if true exposed_qty is set to overall qty
price, quantity
-- Common to all orders.
-- Splitter is filled when it reaches (or exceeds) quantity not exposed_qty
@@ -11,6 +11,7 @@
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/datetime.h"
#include "lib/utils/helper_macros.h"
#include <math.h>
#include <google/protobuf/util/time_util.h>
@@ -26,6 +27,8 @@ struct ArrivalPriceAlgo::PImpl
double s0 = 0.0;
double atmvol = 0.0;
double adaptivity = 0.0;
double tick = 0.0;
uint32_t passive_quantity = 0u;
};
void ArrivalPriceAlgo::on_book(SecurityKey k, const Book& b)
@@ -39,9 +42,13 @@ ArrivalPriceAlgo::~ArrivalPriceAlgo() {}
OrderOpResult ArrivalPriceAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
Slicer::do_before_launch(serv);
const auto& def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_arrival());
me->tick = std::min(serv.security().contract_spec().low_tick(),
serv.security().contract_spec().high_tick());
// Validate the algo part of the definition
auto &algo = def.custom_def().arrival();
if (!algo.has_tactical_child() || !algo.has_aggressive_child())
@@ -59,11 +66,7 @@ OrderOpResult ArrivalPriceAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv
auto achild_def = def;
*achild_def.mutable_custom_def() = def.custom_def().arrival().aggressive_child();
aggressive_template() = &(serv.make_child_template(achild_def));
auto mchild_def = def;
mchild_def.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(mchild_def));
aggressive_template() = &(serv.make_child_template(achild_def));
}
const auto& sec = serv.security();
const std::string& symbol = sec.symbol();
@@ -109,6 +112,8 @@ void ArrivalPriceAlgo::update_params()
}
duration().CopyFrom(algo().definition().custom_def().arrival().duration());
aggression().CopyFrom(algo().definition().custom_def().arrival().aggression());
if(aggression().max_participation_pct() <= 0 || aggression().max_participation_pct() > 80)
algo().terminate_error("Invalid max participation pct");
if (!algo().definition().custom_def().arrival().has_distribution_params())
{
@@ -118,8 +123,8 @@ void ArrivalPriceAlgo::update_params()
volume_estimator().update_params(algo().definition().custom_def().arrival().distribution_params());
price_estimator().update_params(algo().definition().custom_def().arrival().distribution_params());
me->lambda = algo().definition().custom_def().arrival().risk_threshold();
me->lambda = 1e-6 * pow(1.0, me->lambda);
double risk = algo().definition().custom_def().arrival().risk_threshold();
me->lambda = 1e-3 * pow(10.0, risk);
me->atmvol = price_estimator().price_vol_estimate();
me->adaptivity = algo().definition().custom_def().arrival().adaptivity() + 1.0;
}
@@ -134,17 +139,52 @@ bool ArrivalPriceAlgo::check_generation_advance()
return adv;
}
double ArrivalPriceAlgo::calc_eta()
double ArrivalPriceAlgo::compute_mid()
{
return 0.00025;
auto&& bid = last_book().side( api::SIDE_BUY )[0];
auto&& ask = last_book().side( api::SIDE_SELL )[0];
if(bid.size() > 0 && ask.size() > 0)
return (bid.price()*bid.size() + ask.price()*ask.size()) / (bid.size() + ask.size());
else if(bid.size() > 0)
return bid.price();
else if(ask.size() > 0)
return ask.price();
else
return os::nan();
}
double ArrivalPriceAlgo::calc_x1(double s0, double s1, double x0)
double ArrivalPriceAlgo::compute_cost(double qty, api::Side side)
{
uint32_t n = expected_generations();
uint32_t g = current_generation();
if(g < n)
double orig_qty = qty;
double cost = 0.0, basis = 0.0;
auto&& bookside = last_book().side( securities::other_side(side) );
for(auto& i : bookside)
{
if(i.size() > 0 && basis == 0.0)
basis = i.price() * orig_qty;
uint32_t trade = std::min(i.size(), (uint32_t)qty);
cost += trade * i.price();
qty -= trade;
if(qty <= 0.0)
{
bts_assert(qty == 0.0);
break;
}
}
basis -= me->tick * orig_qty;
double actual_cost = fabs(cost - basis);
if(qty > 0.0)
{
actual_cost = actual_cost * (orig_qty / qty);
bts_assert(orig_qty > qty);
}
return std::max(me->tick * orig_qty, actual_cost);
}
double ArrivalPriceAlgo::calc_x1(double s0, double s1, double x0, double cost, uint32_t generation)
{
uint32_t n = expected_generations();
if(generation < n)
{
//days
double order_time = ( end_time().seconds() - start_time().seconds() ) / 86400.0;
@@ -153,15 +193,17 @@ double ArrivalPriceAlgo::calc_x1(double s0, double s1, double x0)
order_time = deltat;
double time_factor = 365.0;
double sigma = s1*me->atmvol / sqrt(time_factor / deltat);
double eta = calc_eta();
double nn = algo().quantity().value() - total_filled().value();
//eta is in ($/share) / (share/period)
double eta = deltat * cost / nn;
double k = sqrt(fabs(me->lambda) * sigma * sigma / eta);
//=IF(B42<=N, U41*SINH(K42*(order_time-deltat*B42))/SINH(K42*(order_time-deltat*B41)),0)
double x1 = x0 * sinh(k * (order_time-deltat*g) ) / sinh(k * order_time-deltat*(g-1));
double x1 = x0 * sinh(k * (order_time-deltat*generation) ) / sinh(k * order_time-deltat*(generation-1));
double alpha = ::log(s1/s0) * s0 / time_factor;
if(algo().definition().side() == api::SIDE_BUY)
alpha = ::log(s0/s1) * s0 / time_factor;
double x_bar = me->adaptivity * alpha / (2.0 * me->lambda * sigma * sigma);
double alpha_correct = x_bar * ( 1.0 - ( sinh(k*(order_time-deltat*g) ) + sinh(k*deltat) ) / sinh( k * (order_time) ) );
double alpha_correct = x_bar * ( 1.0 - ( sinh(k*(order_time-deltat*generation) ) + sinh(k*deltat) ) / sinh( k * (order_time) ) );
//=-IF(B42<=N, AA42*(1-(SINH(K42*(order_time-deltat*B42))+SINH(K42*deltat))/SINH(K42*(order_time))),0)
double x1_adapt = std::min( std::max( alpha_correct + x1, 0.0), x0);
return x1_adapt;
@@ -170,25 +212,48 @@ double ArrivalPriceAlgo::calc_x1(double s0, double s1, double x0)
return x0;
}
void ArrivalPriceAlgo::compute_first_generation(Price&, Quantity& size)
void ArrivalPriceAlgo::compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(tactical_price);
UNUSED(tactical_quantity);
me->s0 = last_book().side(securities::other_side( algo().definition().side() ))[0].price();
double s1 = me->s0;
double x0 = algo().quantity().value();
double x1 = calc_x1(me->s0, s1, x0);
double trade = std::max(x0 - x1, 0.0);
size = Quantity( (uint32_t) trade);
compute_next_generation(price, size, tactical_price, tactical_quantity, aggressive_price, aggressive_quantity);
}
void ArrivalPriceAlgo::compute_next_generation(Price&, Quantity& size)
void ArrivalPriceAlgo::compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(tactical_price);
UNUSED(tactical_quantity);
double x00 = algo().quantity().value();
double s1 = last_book().side( securities::other_side(algo().definition().side()) )[0].price();
double x0 = algo().quantity().value() - total_sent().value();
double x1 = calc_x1(me->s0, s1, x0);
double x0 = x00 - total_sent().value();
auto side = algo().definition().side();
double cost = compute_cost(x00, side);
//compute the aggressive qty to do this slice optimizing between vol and true cost of bid offer
uint32_t g = current_generation();
double x1 = calc_x1(me->s0, s1, x0, cost, g);
double trade = std::max(x0 - x1, 0.0);
size = Quantity( (uint32_t)trade );
aggressive_quantity = Quantity( (uint32_t)trade );
aggressive_price = price;
//passively work the order we'll need from the next period
if(aggression().upgrade_mode() == OrderAggression::TacticalAndAggressive &&
g + 1 < expected_generations()) //these tactial order are going to upgrade
{
double x0_passive = x00 - total_sent().value() - aggressive_quantity.value();
double x1_passive = calc_x1(me->s0, s1, x0_passive, cost, g + 1);
double trade_passive = std::max(x0_passive - x1_passive, 0.0);
tactical_quantity = Quantity( (uint32_t)trade_passive );
tactical_price = price;
}
}
@@ -17,12 +17,18 @@ public:
protected:
void update_params() override;
void compute_first_generation(Price& price, Quantity& size) override;
void compute_next_generation(Price& price, Quantity& size) override;
void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
bool check_generation_advance() override;
double calc_eta();
double calc_x1(double s0, double s1, double x0);
double compute_mid();
double compute_cost(double qty, api::Side side);
double calc_x1(double s0, double s1, double x0, double cost, uint32_t generation);
protected:
struct PImpl;
@@ -8,6 +8,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/helper_macros.h"
namespace bts {
namespace orderman {
@@ -26,6 +27,7 @@ POVAlgo::~POVAlgo() {}
OrderOpResult POVAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
Slicer::do_before_launch(serv);
const auto& def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_pov());
@@ -46,11 +48,7 @@ OrderOpResult POVAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
auto achild_def = def;
*achild_def.mutable_custom_def() = def.custom_def().pov().aggressive_child();
aggressive_template() = &(serv.make_child_template(achild_def));
auto mchild_def = def;
mchild_def.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(mchild_def));
aggressive_template() = &(serv.make_child_template(achild_def));
}
return {};
}
@@ -94,22 +92,32 @@ bool POVAlgo::check_generation_advance()
return adv;
}
void POVAlgo::compute_first_generation(Price&, Quantity& size)
void POVAlgo::compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
auto today = volume_estimator().exchange_running_volume().value();
auto top = last_book().side( algo().definition().side() )[0].size();
double r = std::min( me->min_participation_pct, 99u) / 100.0;
r = 1.0 / (1.0 - r) - 1.0;
tactical_price = price;
int32_t qty = (int32_t) std::min(today*r, top*r);
if(qty > 0)
size = Quantity( std::min( (uint32_t)qty , algo().quantity().value() ) );
tactical_quantity = Quantity( std::min( (uint32_t)qty , algo().quantity().value() ) );
else
size = Quantity(0);
tactical_quantity = Quantity(0);
}
void POVAlgo::compute_next_generation(Price&, Quantity& size)
void POVAlgo::compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
auto today = volume_estimator().exchange_running_volume().value();
int32_t traded = today - me->last_exchange_volume;
if(traded > 0)
@@ -118,13 +126,14 @@ void POVAlgo::compute_next_generation(Price&, Quantity& size)
double r = std::min( me->min_participation_pct, 99u) / 100.0;
r = 1.0 / (1.0 - r) - 1.0;
int32_t qty = (int32_t)r*traded;
tactical_price = price;
if(qty > 0)
size = Quantity( std::min( (uint32_t)qty, algo().quantity().value() ) );
tactical_quantity = Quantity( std::min( (uint32_t)qty, algo().quantity().value() ) );
else
size = Quantity(0);
tactical_quantity = Quantity(0);
}
else
size = Quantity(0);
tactical_quantity = Quantity(0);
}
} // namespace orderman
@@ -16,8 +16,12 @@ public:
protected:
void update_params() override;
void compute_first_generation(Price& price, Quantity& size) override;
void compute_next_generation(Price& price, Quantity& size) override;
void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
bool check_generation_advance() override;
protected:
@@ -56,6 +56,14 @@ struct Slicer::PImpl
TradingDistributionStatus trading_distribution_status = TradingDistributionStatus::NotRequired;
};
OrderOpResult Slicer::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
auto def_copy = serv.definition();
def_copy.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(def_copy));
return {};
}
void Slicer::query_trading_distribution(IBeforeLaunchAlgoServices& serv, const std::string& symbol, api::SecurityType sectype, const std::string& secdesc,
const google::protobuf::Timestamp& begin, const google::protobuf::Timestamp& end,
uint dt_seconds)
@@ -364,19 +372,26 @@ OrderKey Slicer::send_child(Price price, Quantity size, Channel chan)
if(new_size >= 1)
size = Quantity( (uint32_t)new_size );
if(!validate_price_size(price, size))
return child_key;
return null_order_key();
}
if(aggression().max_participation_pct() > 0 && chan != Channel::Market)
//if we are going to pile too much into a tactical order, shave some out and make it aggressive
if(aggression().max_participation_pct() > 0 && aggression().max_participation_pct() < 100 && chan == Channel::Tactical)
{
auto side = algo().definition().side();
auto sz = me->last_book.side( side )[0].size();
double pct = aggression().max_participation_pct() / 100.0;
double new_size = std::min(pct*sz, (double)size.value());
if(new_size >= 0)
size = Quantity( (uint32_t)new_size);
double old_size = (double)size.value();
double new_size = std::min(pct*sz, old_size);
if(new_size >= 0 && new_size < old_size)
{
auto agg_size = (uint32_t)(old_size - new_size);
auto k = algo().launch_child(*me->aggressive_template, price, Quantity( agg_size ));
me->child_orders[k] = OrderDef{ k, me->generation, Channel::Aggressive };
me->total_sent = Quantity( me->total_sent.value() + agg_size);
size = Quantity( (uint32_t)new_size );
}
if(!validate_price_size(price, size))
return child_key;
return null_order_key();
}
LOG(OrderMan, Info, "Slicer launch child {} gen {} p {} s {} c {}", algo().order_key().value(), me->generation,
price.value(), size.value(), (int)chan);
@@ -466,16 +481,14 @@ void Slicer::first_generation()
{
bts_assert_msg(me->generation == 0, "generation 0");
Price price = algo().price();
Quantity size = algo().quantity();
compute_first_generation(price, size);
if(size.value() > 0)
{
if(me->aggression.schedule_mode() == OrderAggression::TacticalThenAggressive)
send_child(price, size, Channel::Tactical);
else
send_child(price, size, Channel::Aggressive);
}
Price price = algo().price(), tactical_price, aggressive_price;
Quantity size = algo().quantity(), tactical_size, aggressive_size;
compute_first_generation(price, size, tactical_price, tactical_size, aggressive_price, aggressive_size);
if(tactical_size.value() > 0)
send_child(tactical_price, tactical_size, Channel::Tactical);
if(aggressive_size.value() > 0)
send_child(aggressive_price, aggressive_size, Channel::Aggressive);
me->generation++;
}
@@ -489,35 +502,37 @@ void Slicer::next_generation()
}
auto child_orders_copy = me->child_orders;
auto upgrade_mode = me->aggression.upgrade_mode();
for(const auto& ch : child_orders_copy)
{
bts_assert_msg(me->generation >= ch.second.generation, fmt::format("incorrect generation {} {}", std::to_string(me->generation), std::to_string(ch.second.generation)) );
uint32_t age = me->generation - ch.second.generation;
if(age > me->aggression.extra_tactical_slices() + 1)
{
if(ch.second.channel == Channel::Tactical) //move to aggressive
if(age > me->aggression.extra_slices() + 1)
{
//move to aggressive
if(ch.second.channel == Channel::Tactical &&
upgrade_mode == OrderAggression::TacticalAndAggressive )
{
LOG(OrderMan, Info, "TimeSlicer upgrade child aggressive {} gen {} child {}", algo().order_key().value(), me->generation, ch.first);
upgrade_child(ch.first, Channel::Aggressive);
}
else if(ch.second.channel == Channel::Aggressive) //move to market
//move to market
else if(ch.second.channel == Channel::Aggressive &&
(upgrade_mode == OrderAggression::TacticalAndAggressive || upgrade_mode == OrderAggression::AggressiveOnly) )
{
LOG(OrderMan, Info, "TimeSlicer upgrade child market {} gen {} child {}", algo().order_key().value(), me->generation, ch.first);
upgrade_child(ch.first, Channel::Market);
}
}
}
//double price = me->last_book.side( algo().definition().side() )[0].price();
Price price = algo().price();
Quantity size = algo().quantity();
compute_next_generation(price, size);
if(size.value() > 0)
{
if(me->aggression.schedule_mode() == OrderAggression::TacticalThenAggressive)
send_child(price, size, Channel::Tactical);
else
send_child(price, size, Channel::Aggressive);
}
Price price = algo().price(), tactical_price, aggressive_price;
Quantity size = algo().quantity(), tactical_size, aggressive_size;
compute_next_generation(price, size, tactical_price, tactical_size, aggressive_price, aggressive_size);
if(tactical_size.value() > 0)
send_child(tactical_price, tactical_size, Channel::Tactical);
if(aggressive_size.value() > 0)
send_child(aggressive_price, aggressive_size, Channel::Aggressive);
me->generation++;
}
@@ -23,6 +23,7 @@ public:
Slicer();
~Slicer();
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &serv) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices&, OrderKey, ChildState) override;
void on_child_change(OrderKey, const ChildState&) override;
@@ -53,8 +54,12 @@ protected:
protected:
virtual void update_params() = 0;
virtual bool setup_schedule();
virtual void compute_first_generation(Price& price, Quantity& size) = 0;
virtual void compute_next_generation(Price& price, Quantity& size) = 0;
virtual void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) = 0;
virtual void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) = 0;
virtual void first_generation();
virtual void next_generation();
@@ -7,6 +7,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/helper_macros.h"
namespace bts {
namespace orderman {
@@ -23,6 +24,7 @@ TWAPAlgo::~TWAPAlgo() {}
OrderOpResult TWAPAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
Slicer::do_before_launch(serv);
const auto& def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_twap());
@@ -44,10 +46,6 @@ OrderOpResult TWAPAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
auto achild_def = def;
*achild_def.mutable_custom_def() = def.custom_def().twap().aggressive_child();
aggressive_template() = &(serv.make_child_template(achild_def));
auto mchild_def = def;
mchild_def.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(mchild_def));
}
return {};
}
@@ -81,18 +79,30 @@ void TWAPAlgo::update_params()
//next timer will pick this up
}
void TWAPAlgo::compute_first_generation(Price&, Quantity& size)
void TWAPAlgo::compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
size = Quantity( algo().quantity().value() / expected_generations() );
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
tactical_price = price;
tactical_quantity = Quantity( algo().quantity().value() / expected_generations() );
}
void TWAPAlgo::compute_next_generation(Price&, Quantity& size)
void TWAPAlgo::compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
int32_t sz = current_generation() * algo().quantity().value() / expected_generations() - total_sent().value();
tactical_price = price;
if(sz > 0)
size = Quantity(sz);
tactical_quantity = Quantity(sz);
else
size = Quantity(0);
tactical_quantity = Quantity(0);
}
@@ -16,8 +16,12 @@ public:
protected:
void update_params() override;
void compute_first_generation(Price& price, Quantity& size) override;
void compute_next_generation(Price& price, Quantity& size) override;
void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
protected:
struct PImpl;
@@ -8,6 +8,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/helper_macros.h"
namespace bts {
namespace orderman {
@@ -24,6 +25,7 @@ VWAPAlgo::~VWAPAlgo() {}
OrderOpResult VWAPAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
Slicer::do_before_launch(serv);
const auto& def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_vwap());
@@ -44,11 +46,7 @@ OrderOpResult VWAPAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
auto achild_def = def;
*achild_def.mutable_custom_def() = def.custom_def().vwap().aggressive_child();
aggressive_template() = &(serv.make_child_template(achild_def));
auto mchild_def = def;
mchild_def.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(mchild_def));
aggressive_template() = &(serv.make_child_template(achild_def));
}
return {};
}
@@ -89,21 +87,33 @@ void VWAPAlgo::update_params()
volume_estimator().update_params(algo().definition().custom_def().vwap().distribution_params());
}
void VWAPAlgo::compute_first_generation(Price&, Quantity& size)
void VWAPAlgo::compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
double ratio = volume_estimator().exchange_running_volume().value() / volume_estimator().day_volume_estimate().value();
ratio = std::min(1.0, ratio);
ratio = std::max(0.0, ratio);
size = Quantity( ratio * size.value() );
tactical_price = price;
tactical_quantity = Quantity( ratio * size.value() );
}
void VWAPAlgo::compute_next_generation(Price&, Quantity& size)
void VWAPAlgo::compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
//TODO predict this period based on prior
double ratio = volume_estimator().exchange_running_volume().value() / volume_estimator().day_volume_estimate().value();
ratio = std::min(1.0, ratio);
ratio = std::max(0.0, ratio);
size = Quantity( ratio * size.value() );
tactical_price = price;
tactical_quantity = Quantity( ratio * size.value() );
}
} // namespace orderman
@@ -16,8 +16,12 @@ public:
protected:
void update_params() override;
void compute_first_generation(Price& price, Quantity& size) override;
void compute_next_generation(Price& price, Quantity& size) override;
void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
protected:
struct PImpl;
@@ -8,6 +8,7 @@
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/helper_macros.h"
namespace bts {
namespace orderman {
@@ -24,6 +25,7 @@ VolumeSliceAlgo::~VolumeSliceAlgo() {}
OrderOpResult VolumeSliceAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
{
Slicer::do_before_launch(serv);
const auto& def = serv.definition();
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_vslice());
@@ -44,11 +46,7 @@ OrderOpResult VolumeSliceAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv)
auto achild_def = def;
*achild_def.mutable_custom_def() = def.custom_def().vslice().aggressive_child();
aggressive_template() = &(serv.make_child_template(achild_def));
auto mchild_def = def;
mchild_def.mutable_custom_def()->mutable_market();
market_template() = &(serv.make_child_template(mchild_def));
aggressive_template() = &(serv.make_child_template(achild_def));
}
return {};
}
@@ -83,18 +81,30 @@ void VolumeSliceAlgo::update_params()
}
void VolumeSliceAlgo::compute_first_generation(Price&, Quantity& size)
void VolumeSliceAlgo::compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
size = Quantity( algo().quantity().value() / expected_generations() );
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
tactical_price = price;
tactical_quantity = Quantity( algo().quantity().value() / expected_generations() );
}
void VolumeSliceAlgo::compute_next_generation(Price&, Quantity& size)
void VolumeSliceAlgo::compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity)
{
UNUSED(size);
UNUSED(aggressive_price);
UNUSED(aggressive_quantity);
tactical_price = price;
int32_t sz = current_generation() * algo().quantity().value() / expected_generations() - total_sent().value();
if(sz > 0)
size = Quantity(sz);
tactical_quantity = Quantity(sz);
else
size = Quantity(0);
tactical_quantity = Quantity(0);
}
} // namespace orderman
@@ -16,8 +16,12 @@ public:
protected:
void update_params() override;
void compute_first_generation(Price& price, Quantity& size) override;
void compute_next_generation(Price& price, Quantity& size) override;
void compute_first_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
void compute_next_generation(Price price, Quantity size,
Price& tactical_price, Quantity& tactical_quantity,
Price& aggressive_price, Quantity& aggressive_quantity) override;
protected:
struct PImpl;