getting TradingDistribution data into algo
This commit is contained in:
1 parent
f07fd7044f
commit
9de3d80891
13 files changed
+61
-39
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include "lib/orderman/actors/order_manager/ChildOrder.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderServices.h"
|
||||
#include "lib/api/public/ServiceContext.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_utils.h"
|
||||
#include "lib/orderman/orders/PreActivationOrderServices.h"
|
||||
#include "lib/orderman/orders/algo/IAlgoOrder.h"
|
||||
@@ -354,6 +355,11 @@ orderman::OrderOpResult AlgoWrapperOrder::on_cancel() {
|
||||
return {};
|
||||
}
|
||||
|
||||
const bts::api::ServiceContext& AlgoWrapperOrder::get_shared_service_context() const {
|
||||
static bts::api::ServiceContext context;
|
||||
return context;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// IBeforeLaunchAlgoServices
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
@@ -65,6 +65,7 @@ class AlgoWrapperOrder : public Order,
|
||||
void complete() override;
|
||||
void update_fill_state(Quantity total_fills, Price last_price) override;
|
||||
void set_ladder_visibility (bool is_visibile) override;
|
||||
const bts::api::ServiceContext& get_shared_service_context() const override;
|
||||
|
||||
// Private
|
||||
struct ReportStateGuard;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "lib/orderman/orders/algo/IBeforeLaunchAlgoServices.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api { class ServiceContext; }
|
||||
namespace orderman {
|
||||
|
||||
class IAlgoServices : public IBeforeLaunchAlgoServices {
|
||||
@@ -104,6 +105,7 @@ class IAlgoServices : public IBeforeLaunchAlgoServices {
|
||||
|
||||
// Update this algos's filled quantity and last price
|
||||
virtual void update_fill_state(Quantity total_fills, Price last_price) = 0;
|
||||
virtual const api::ServiceContext& get_shared_service_context() const = 0;
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -97,21 +97,14 @@ void ArrivalPriceAlgo::update_params()
|
||||
algo().terminate_error("Invalid volume dist params, terminating");
|
||||
return;
|
||||
}
|
||||
if(!volume_estimator().update_params(algo().definition().custom_def().arrival().volume_distribution()))
|
||||
{
|
||||
algo().terminate_error("Algo needs volume mean and variance overrides temporarily, terminating");
|
||||
return;
|
||||
}
|
||||
volume_estimator().update_params(algo().definition().custom_def().arrival().volume_distribution());
|
||||
if (!algo().definition().custom_def().arrival().has_price_distribution())
|
||||
{
|
||||
algo().terminate_error("Invalid price dist params, terminating");
|
||||
return;
|
||||
}
|
||||
if(!price_estimator().update_params(algo().definition().custom_def().arrival().price_distribution()))
|
||||
{
|
||||
algo().terminate_error("Algo needs price mean and variance overrides temporarily, terminating");
|
||||
return;
|
||||
}
|
||||
price_estimator().update_params(algo().definition().custom_def().arrival().price_distribution());
|
||||
|
||||
me->lambda = algo().definition().custom_def().arrival().risk_threshold();
|
||||
me->lambda = 1e-6 * pow(1.0, me->lambda);
|
||||
me->atmvol = price_estimator().price_vol_estimate();
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#include "lib/orderman/orders/algo/algo_orders/bluex/PriceEstimator.h"
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/api/services/HistoricalDataService.pb.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
using namespace history;
|
||||
|
||||
struct PriceEstimator::PImpl
|
||||
{
|
||||
Quantity running_volume = Quantity(0);
|
||||
PriceDistribution price_distribution;
|
||||
TradingDistribution trading_distribution;
|
||||
double realized_mean = 0.0;
|
||||
double realized_vol = 0.0;
|
||||
};
|
||||
@@ -49,16 +52,19 @@ void PriceEstimator::on_ticker(SecurityKey, const TradeVector& vec)
|
||||
me->realized_mean /= r;
|
||||
}
|
||||
|
||||
bool PriceEstimator::update_params(const api::orderman::PriceDistribution& pd)
|
||||
bool PriceEstimator::ready() const
|
||||
{
|
||||
return me->price_distribution.price_time_horizon_days() > 0 && me->trading_distribution.volume_total() > 0;
|
||||
}
|
||||
|
||||
void PriceEstimator::update_params(const api::orderman::PriceDistribution& pd)
|
||||
{
|
||||
me->price_distribution = pd;
|
||||
|
||||
if (me->price_distribution.price_mean_override() <= 0.0 ||
|
||||
me->price_distribution.price_vol_override() <= 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PriceEstimator::update_distribution(const history::TradingDistribution& td)
|
||||
{
|
||||
me->trading_distribution = td;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace history { class TradingDistribution; }
|
||||
namespace api {
|
||||
namespace orderman {
|
||||
class PriceDistribution;
|
||||
}
|
||||
namespace orderman { class PriceDistribution; }
|
||||
}
|
||||
namespace orderman {
|
||||
|
||||
@@ -18,7 +17,9 @@ public:
|
||||
PriceEstimator();
|
||||
~PriceEstimator();
|
||||
|
||||
bool update_params(const api::orderman::PriceDistribution&);
|
||||
bool ready() const;
|
||||
void update_params(const api::orderman::PriceDistribution&);
|
||||
void update_distribution(const history::TradingDistribution& td);
|
||||
void on_ticker(SecurityKey, const TradeVector& vec);
|
||||
|
||||
Price price_mean_estimate() const;
|
||||
|
||||
@@ -66,6 +66,7 @@ struct Slicer::PImpl
|
||||
|
||||
VolumeEstimator volume_estimator;
|
||||
PriceEstimator price_estimator;
|
||||
std::unique_ptr<bts::history::TradingDistribution> trading_distribution;
|
||||
};
|
||||
OrderAggression& Slicer::aggression()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orders/algo/IAlgoOrder.h"
|
||||
#include "lib/api/services/HistoricalDataService.pb.h"
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
|
||||
namespace bts {
|
||||
|
||||
@@ -87,11 +87,7 @@ void VWAPAlgo::update_params()
|
||||
algo().terminate_error("Invalid volume dist params, terminating");
|
||||
return;
|
||||
}
|
||||
if(!volume_estimator().update_params(algo().definition().custom_def().vwap().volume_distribution()))
|
||||
{
|
||||
algo().terminate_error("Algo needs volume mean and variance overrides temporarily, terminating");
|
||||
return;
|
||||
}
|
||||
volume_estimator().update_params(algo().definition().custom_def().vwap().volume_distribution());
|
||||
}
|
||||
|
||||
void VWAPAlgo::compute_first_generation(Price&, Quantity& size)
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
#include "lib/orderman/orders/algo/algo_orders/bluex/VolumeEstimator.h"
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/api/services/HistoricalDataService.pb.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace api::orderman;
|
||||
using namespace history;
|
||||
|
||||
struct VolumeEstimator::PImpl
|
||||
{
|
||||
VolumeDistribution volume_distribution;
|
||||
TradingDistribution trading_distribution;
|
||||
Quantity running_volume = Quantity(0);
|
||||
};
|
||||
|
||||
@@ -28,16 +31,19 @@ void VolumeEstimator::on_ticker(SecurityKey, const TradeVector& vec)
|
||||
me->running_volume = Quantity( std::max(me->running_volume.value(), t.total_volume.value()) );
|
||||
}
|
||||
|
||||
bool VolumeEstimator::update_params(const api::orderman::VolumeDistribution& vd)
|
||||
bool VolumeEstimator::ready() const
|
||||
{
|
||||
return me->volume_distribution.volume_time_horizon_days() > 0 && me->trading_distribution.volume_total() > 0;
|
||||
}
|
||||
|
||||
void VolumeEstimator::update_params(const api::orderman::VolumeDistribution& vd)
|
||||
{
|
||||
me->volume_distribution = vd;
|
||||
|
||||
if (me->volume_distribution.volume_mean_override() <= 0.0 ||
|
||||
me->volume_distribution.volume_variance_override() <= 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void VolumeEstimator::update_distribution(const history::TradingDistribution& td)
|
||||
{
|
||||
me->trading_distribution = td;
|
||||
}
|
||||
|
||||
Quantity VolumeEstimator::day_volume_estimate() const
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace history { class TradingDistribution; }
|
||||
namespace api {
|
||||
namespace orderman {
|
||||
class VolumeDistribution;
|
||||
}
|
||||
namespace orderman { class VolumeDistribution; }
|
||||
}
|
||||
namespace orderman {
|
||||
|
||||
@@ -18,7 +17,9 @@ public:
|
||||
VolumeEstimator();
|
||||
~VolumeEstimator();
|
||||
|
||||
bool update_params(const api::orderman::VolumeDistribution&);
|
||||
bool ready() const;
|
||||
void update_params(const api::orderman::VolumeDistribution&);
|
||||
void update_distribution(const history::TradingDistribution&);
|
||||
void on_ticker(SecurityKey, const TradeVector& vec);
|
||||
|
||||
Quantity day_volume_estimate() const;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "lib/md/relay/RelayRecorder.h"
|
||||
#include "catch/catch.hpp"
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/api/public/ServiceContext.h"
|
||||
#include "lib/orderman/orderman_utils/Book.h"
|
||||
#include "lib/orderman/orders/algo/ChildTemplate.h"
|
||||
#include "lib/logging/logging.h"
|
||||
@@ -504,6 +505,12 @@ void AlgoTestDriverBase::complete() {
|
||||
me->state = AlgoState::COMPLETED;
|
||||
}
|
||||
void AlgoTestDriverBase::set_ladder_visibility(bool) { /* whatever, ok */ }
|
||||
const api::ServiceContext& AlgoTestDriverBase::get_shared_service_context() const
|
||||
{
|
||||
bts_assert(false);
|
||||
static api::ServiceContext context;
|
||||
return context;
|
||||
}
|
||||
void AlgoTestDriverBase::update_fill_state(Quantity q, Price p) { me->fill_state = { q, p }; }
|
||||
|
||||
}}}//namespace
|
||||
@@ -146,6 +146,7 @@ private:
|
||||
void complete() override;
|
||||
void set_ladder_visibility(bool) override;
|
||||
void update_fill_state(Quantity , Price) override;
|
||||
const api::ServiceContext& get_shared_service_context() const override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user