Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c15f83c85 | ||
|
|
f9dfb04fca | ||
|
|
680b19b6fb | ||
|
|
f790b8f59b | ||
|
|
fbed8e5428 | ||
|
|
524f3be25a | ||
|
|
9823b44083 | ||
|
|
30feda72bb |
No files matched your search
@@ -146,9 +146,10 @@ namespace mbts.spark {
|
||||
//
|
||||
ProprietaryRiskLimits remove_secs(ProprietaryRiskLimits prlimits) {
|
||||
var sec_key_set = new HashSet<uint>(security_keys);
|
||||
for (int i = 0; i < prlimits.SecurityLimits.Count; i++) {
|
||||
if (sec_key_set.Contains(prlimits.SecurityLimits[i].SecurityKey))
|
||||
for (int i = 0; i < prlimits.SecurityLimits.Count;) {
|
||||
if (sec_key_set.Contains(prlimits.SecurityLimits[i].SecurityKey)) {
|
||||
prlimits.SecurityLimits.RemoveAt(i);
|
||||
} else i++;
|
||||
}
|
||||
return prlimits;
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace mbts.spark {
|
||||
public override string man_page { get; } = string.Empty;
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.EnableHedging;
|
||||
leg_tup.leg_params.SendHedge is null || leg_tup.leg_params.SendHedge.Val;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) =>
|
||||
leg_tup.leg_params.EnableHedging = value;
|
||||
|
||||
public override bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) =>
|
||||
!leg_tups.Any(lt => lt.leg_params.EnableHedging);
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
|
||||
if (leg_tup.leg_params.SendHedge is null)
|
||||
leg_tup.leg_params.SendHedge = new bts.spark.NullableBoolean();
|
||||
leg_tup.leg_params.SendHedge.Val = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class LeanOffsetTicksModel : RowModelBase<int> {
|
||||
public override string display_name { get; } = "Lean Offset Ticks";
|
||||
public override string help_text { get; } = "Improvement (in ticks) to the lean market";
|
||||
public override string man_page { get; } = string.Empty;
|
||||
|
||||
public override int get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams?.LeanOffsetTicks ?? 0;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, int value) {
|
||||
if (leg_tup.leg_params.QuoteParams is null)
|
||||
leg_tup.leg_params.QuoteParams = new bts.spark.QuoteParams();
|
||||
leg_tup.leg_params.QuoteParams.LeanOffsetTicks = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,9 +223,10 @@ namespace mbts.spark {
|
||||
_quantity_model,
|
||||
_price_mult_model,
|
||||
is_quote_model,
|
||||
//new EnableHedgeModel(), //TAHA_SPREADER
|
||||
new EnableHedgeModel(), //TAHA_SPREADER
|
||||
new HedgeRatioModel(),
|
||||
//new MinLeanQtyModel(), //TAHA_SPREADER
|
||||
new LeanOffsetTicksModel(),
|
||||
//new QuoteHiddenModel(),
|
||||
new QuoteQueueHolderModel(),
|
||||
new MarketDataTypeModel(),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using mbts;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
@@ -89,6 +90,9 @@ namespace bts.shell.risk_management {
|
||||
_view = new RiskManagementControl { DataContext = _vm };
|
||||
}
|
||||
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
_menu_display_vm.safe_bind_to_view(parent_view);
|
||||
|
||||
static SparkMenuDisplayVM _init_menu_display_vm(SparkMenuDisplaySettings settings) {
|
||||
var vm = new SparkMenuDisplayVM();
|
||||
vm.load_from(settings);
|
||||
|
||||
@@ -15,7 +15,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Controls;
|
||||
@@ -50,7 +49,7 @@ namespace bts.shell.risk_management {
|
||||
IComparer<RiskLimitsVM> _row_comparer;
|
||||
IDisposable _import_limits_op;
|
||||
ImmutableDictionary<AccountSecurityKey, RiskLimitsVM> _dirty_rows = ImmutableDictionary<AccountSecurityKey, RiskLimitsVM>.Empty;
|
||||
ImmutableDictionary<AccountSecurityKey, RiskLimitsVM> _imported_row_map = ImmutableDictionary<AccountSecurityKey, RiskLimitsVM>.Empty;
|
||||
Dictionary<AccountSecurityKey, RiskLimitsVM> _imported_row_map = new Dictionary<AccountSecurityKey, RiskLimitsVM>();
|
||||
Dictionary<AccountSecurityKey, RiskLimitsVM> _row_cache = new Dictionary<AccountSecurityKey, RiskLimitsVM>();
|
||||
|
||||
public RiskManagementVM(IObservable<TableUpdate<AccountSecurityRiskLimits, AccountSecurityKey>> data_source, IObservable<IReadOnlyList<AccountTuple>> accounts_source) {
|
||||
@@ -172,6 +171,7 @@ namespace bts.shell.risk_management {
|
||||
f.filter_changed += _refresh_filter_changed.execute;
|
||||
return Disposable.Create(() => f.filter_changed -= _refresh_filter_changed.execute);
|
||||
}).ToList();
|
||||
_accounts_vm.selected_item_changed += on_selected_account_changed;
|
||||
_dispose = Disposable.Create(
|
||||
ObservableAutoWrapper.connect_item_hooks(rows, subscribe_row_changes),
|
||||
accounts_source.OnDispatcher().Subscribe(on_accounts),
|
||||
@@ -264,6 +264,7 @@ namespace bts.shell.risk_management {
|
||||
// if row is already here, it must be an import
|
||||
// overwrite the import with the persisted row (this probably won't happen in practice)
|
||||
rows.RemoveSorted(row, row_comparer);
|
||||
_imported_row_map.Remove(lim.key);
|
||||
}
|
||||
var new_row = RiskLimitsVM.create_persisted(lim);
|
||||
_row_cache[lim.key] = new_row;
|
||||
@@ -293,6 +294,16 @@ namespace bts.shell.risk_management {
|
||||
rows.Move(old_index, new_index);
|
||||
}
|
||||
}
|
||||
|
||||
void on_selected_account_changed() {
|
||||
foreach (var ir in _imported_row_map.Values) {
|
||||
if (ir.account_key == selected_account?.id) {
|
||||
rows.InsertOrReplaceSorted(ir, row_comparer);
|
||||
} else {
|
||||
rows.RemoveSorted(ir, row_comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event Action selected_rows_changed;
|
||||
@@ -398,12 +409,13 @@ namespace bts.shell.risk_management {
|
||||
res = res.with(security: sec_md.security);
|
||||
if (string.IsNullOrEmpty(res.account_name) && accounts.TryGetFirst(a => a?.id == res.account_key, out var acc))
|
||||
res = res.with(account: acc);
|
||||
if (_row_cache.TryGetValue(res.key, out var old_row))
|
||||
rows.RemoveSorted(old_row, row_comparer);
|
||||
var new_row = RiskLimitsVM.create_placeholder(res);
|
||||
if (_row_cache.TryGetValue(res.key, out var row)) {
|
||||
rows.RemoveSorted(row, row_comparer);
|
||||
}
|
||||
_row_cache[res.key] = new_row;
|
||||
rows.InsertSorted(new_row, row_comparer);
|
||||
_imported_row_map[res.key] = new_row;
|
||||
if (new_row.account_key == selected_account?.id)
|
||||
rows.InsertSorted(new_row, row_comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,15 @@ namespace bts.collections {
|
||||
list.Insert(i < 0 ? ~i : i, value);
|
||||
}
|
||||
|
||||
public static void InsertOrReplaceSorted<T>(this IList<T> list, T item, IComparer<T> comparer) {
|
||||
int i = CollectionHelper.binary_search(list, item, comparer);
|
||||
if (i < 0) {
|
||||
list.Insert(~i, item);
|
||||
} else {
|
||||
list[i] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool RemoveSorted<T>(this IList<T> list, T item, IComparer<T> comparer) {
|
||||
int i = CollectionHelper.binary_search(list, item, comparer);
|
||||
if (i < 0)
|
||||
|
||||
@@ -37,6 +37,14 @@ public:
|
||||
double size_multiplier() const { return _leg_contract.quantity(); }
|
||||
double tick_size() const { return _leg_contract.security().contract_spec().low_tick(); }
|
||||
bool is_active_quoting() const {return _leg_params.is_active_quoting();}
|
||||
bool send_hedge() const {
|
||||
// for backwards compat, if its unset, then hedges are sent
|
||||
return !_leg_params.has_send_hedge() || _leg_params.send_hedge().val();
|
||||
}
|
||||
// if both quoting and hedging are turned off, this results false, else true
|
||||
bool is_active_trading() const{
|
||||
return is_active_quoting() || send_hedge();
|
||||
}
|
||||
bool is_net_change() const{
|
||||
return _price_calc==bts::api::SyntheticContract::PRICECALC_NET_CHANGE;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,8 @@ bool SingleLegQuoter::accept_modifications() const {
|
||||
_worker->state() == QuoterState::WORKING;
|
||||
}
|
||||
void SingleLegQuoter::_incorporate_other_leg_fill (size_t, Quantity hedge_reduction){
|
||||
_price_quantity_state.add_hedged_reduction (hedge_reduction);
|
||||
if(_this_leg_data.send_hedge())
|
||||
_price_quantity_state.add_hedged_reduction (hedge_reduction);
|
||||
}
|
||||
void SingleLegQuoter::_compute_quote(
|
||||
Quantity target_qty,
|
||||
|
||||
@@ -79,6 +79,8 @@ void SpreaderBookkeepingData::total_fills (Quantity& out_quantity,
|
||||
double avg_price = 0.0;
|
||||
double fills = std::numeric_limits<double>::max();
|
||||
for (const SpreaderLegData& leg_data : _leg_data){
|
||||
if(!leg_data.leg_property_data().is_active_trading())
|
||||
continue;
|
||||
Quantity leg_fill_qty; Price leg_fill_price;
|
||||
leg_data.total_fills(leg_fill_qty, leg_fill_price);
|
||||
double leg_normalized_qty = static_cast<double>(leg_fill_qty.value()) /
|
||||
|
||||
@@ -727,6 +727,7 @@ public:
|
||||
Quantity hedge_qty;
|
||||
compute_driver(quote_target,quote_leg_data,hedge_leg_data,hedge_leg_book,
|
||||
hedge_price,hedge_qty,quote_qty);
|
||||
hedge_price = Price(offset_driver_price(hedge_price.value(),hedge_leg_data));
|
||||
double out_price = (target_spread_price.value() - hedge_price.value() * hedge_leg_data.price_multiplier())/quote_leg_data.price_multiplier();
|
||||
out_price = bts::securities::raw_round_to_quote_price (out_price, quote_leg_data.tick_size(), quote_leg_data.trading_side());
|
||||
quote_price = Price(out_price);
|
||||
@@ -784,6 +785,15 @@ public:
|
||||
out_driver_vector[idx].set (hedge_price, hedge_qty, quote_qty);
|
||||
}
|
||||
}
|
||||
static double offset_driver_price (double driver_price,
|
||||
const LegPropertyData& driver_lp){
|
||||
int offset_ticks = driver_lp.leg_params().quote_params().lean_offset_ticks();
|
||||
double offset_price = offset_ticks * driver_lp.tick_size();
|
||||
if(driver_lp.trading_side() == api::Side::SIDE_BUY)
|
||||
return driver_price + offset_price;
|
||||
else
|
||||
return driver_price - offset_price;
|
||||
}
|
||||
// computes the quoting price from the leg drivers
|
||||
// ie (spreader_price - sum (price_mult * price))/quoting_leg_mult
|
||||
static Price compute_quoting_price_from_drivers(Price target_spread_price,
|
||||
@@ -794,8 +804,11 @@ public:
|
||||
size_t n_legs = driver_vector.size();
|
||||
double sum = 0;
|
||||
for (size_t idx = 0; idx < n_legs; idx++)
|
||||
if (idx != quoting_leg_index)
|
||||
sum += driver_vector[idx].driver_price().value() * spreader.get_leg_data (idx).price_multiplier();
|
||||
if (idx != quoting_leg_index){
|
||||
double driver_price = driver_vector[idx].driver_price().value();
|
||||
driver_price = offset_driver_price(driver_price,spreader.get_leg_data(idx));
|
||||
sum += driver_price * spreader.get_leg_data(idx).price_multiplier();
|
||||
}
|
||||
double rv = (target_spread_price.value() - sum)/quoting_leg_data.price_multiplier();
|
||||
rv = bts::securities::raw_round_to_quote_price (rv, quoting_leg_data.tick_size(), quoting_leg_data.trading_side());
|
||||
return Price(rv);
|
||||
|
||||
+7
-3
@@ -16,10 +16,14 @@ void HedgerStartStateWorker::on_transition (){
|
||||
void HedgerStartStateWorker::init (Price price,
|
||||
Quantity quantity){
|
||||
_hedger->_price_quantity_state.re_init(price,quantity);
|
||||
if(quantity.value() > 0){
|
||||
_hedger->_place_order (price, quantity);
|
||||
_hedger->transform_to_WAITING_FOR_FIRST_ACK ();
|
||||
if(_hedger->_leg_property_data.send_hedge()){
|
||||
if(quantity.value() > 0){
|
||||
_hedger->_place_order (price, quantity);
|
||||
_hedger->transform_to_WAITING_FOR_FIRST_ACK ();
|
||||
}
|
||||
}
|
||||
else
|
||||
_hedger->cancel_hedge();
|
||||
}
|
||||
void HedgerStartStateWorker::on_order_update(const SpreaderChildOrderState&){
|
||||
bts_assert_msg (false, "HedgerStartStateWorker::on_order_update "
|
||||
|
||||
@@ -19,6 +19,9 @@ message QuantityMeasure
|
||||
message NullableQuantity{
|
||||
uint32 quantity = 10;
|
||||
}
|
||||
message NullableBoolean{
|
||||
bool val = 10;
|
||||
}
|
||||
// /*************************************************************************************************/
|
||||
// /*************************************************************************************************/
|
||||
// /*************************************Spreader Parameters*****************************************/
|
||||
@@ -46,7 +49,8 @@ message LegSpreaderParams
|
||||
PreHedgeParams pre_hedge_params = 50;
|
||||
PostHedgeParams post_hedge_params = 60;
|
||||
MarketDataType market_data_type = 70;
|
||||
//reserve LegMarketDataCalculation leg_md_calc = 80;
|
||||
//reserve LegMarketDataCalculation leg_md_calc = 80;
|
||||
NullableBoolean send_hedge = 90;
|
||||
}
|
||||
|
||||
// /*************************************************************************************************
|
||||
@@ -76,6 +80,8 @@ message QuoteParams
|
||||
uint32 n_queue_holder_orders=2000;
|
||||
// this is the show quantity on the quoter order
|
||||
NullableQuantity show_quantity = 2010;
|
||||
int32 lean_offset_ticks = 2020;
|
||||
QuoteTimeBasedThrottle time_based_throttle = 2030;
|
||||
}
|
||||
|
||||
/*************************************Quote MuteZone***********************************
|
||||
@@ -134,7 +140,10 @@ message QuoteInsideMarketDistanceThrottle
|
||||
{
|
||||
uint32 on_toward_distance = 10;
|
||||
}
|
||||
|
||||
message QuoteTimeBasedThrottle{
|
||||
uint32 delay_to_run = 10;
|
||||
uint32 delay_to_improve = 20;
|
||||
}
|
||||
/*************************************Quote RepriceThrottled (unused)*******************************
|
||||
(Stellar's sensitivity)
|
||||
This parameter defines regions (wrt their distance from the inside market)
|
||||
|
||||
Reference in new issue
Block a user