bug in stacker for 3 length

This commit is contained in:
Kevin Darby committed 2020-01-02 15:34:27 -05:00
1 parent 68b37ccfc8
commit 1939c9c3c0
4 files changed
+35 -46

No files matched your search

@@ -13,14 +13,22 @@ namespace bts.history
double _myprice;
public StackerAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
public double profit_ticks { get; set; } = 1.0;
public double[] tick_size { get; set; }
public uint stack_length { get; set; } = 2;
double _tick_size;
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
{
_myside = side;
_myprice = price;
_handles = new Handle[this.stack_length];
for (int i = 0; i < this.security_list.Length; i++)
{
if(this.security_list[i] == security_list[0])
_tick_size = tick_size[i];
}
if(this.stack_length <= 1)
throw new NotSupportedException("StackerAlgo must have stack_length > 1");
for(int i = 0; i < this.stack_length; i++)
@@ -28,12 +36,12 @@ namespace bts.history
if(side == api.Side.Buy)
{
var h = _handles[i] = this.create<Child>();
h.launch(security_list, side, price - i * this.profit_ticks, size, asof);
h.launch(security_list, side, price - i * _tick_size, size, asof);
}
else
{
var h = _handles[i] = this.create<Child>();
h.launch(security_list, side, price + i * this.profit_ticks, size, asof);
h.launch(security_list, side, price + i * _tick_size, size, asof);
}
}
}
@@ -49,12 +57,12 @@ namespace bts.history
double px = _myprice;
if(better)
{
double tick = (_myside == api.Side.Buy ? this.profit_ticks : -this.profit_ticks);
while(Math.Abs(price - px) > this.profit_ticks / 10.0)
double tick = (_myside == api.Side.Buy ? _tick_size : -_tick_size);
while(Math.Abs(price - px) > _tick_size / 10.0)
{
px += tick;
var mover = _handles[_handles.Length - 1];
for(int j = 1; j < _handles.Length; j++)
for(int j = _handles.Length-1; j >= 1; j--)
_handles[j] = _handles[j-1];
_handles[0] = mover;
mover.update(asof, px, size);
@@ -66,8 +74,8 @@ namespace bts.history
}
else
{
double tick = (_myside == api.Side.Buy ? -this.profit_ticks : this.profit_ticks);
while (Math.Abs(price - px) > this.profit_ticks / 10.0)
double tick = (_myside == api.Side.Buy ? -_tick_size : _tick_size);
while (Math.Abs(price - px) > _tick_size / 10.0)
{
var mover = _handles[0];
for (int j = 0; j < _handles.Length-1; j++)
@@ -181,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {
"scrolled": true
},
@@ -204,14 +204,14 @@
"var price = 0.0; //dont' care on peg\n",
"var sz = 100u;\n",
"var algo_results = algo_results<PegCoverLean, HistoryRow>(sink, fill_model, algo_params, \n",
" bts.api.Side.Sell, price, sz, \n",
" bts.api.Side.Buy, price, sz, \n",
" security_list, //must match below\n",
" new[] {spdf}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -222,7 +222,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 12,
"metadata": {
"scrolled": true
},
@@ -230,7 +230,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th>avg_buy_price</th><th>avg_sell_price</th><th>total_buy_size</th><th>total_sell_size</th><th>pnl</th><th>num_buys</th><th>num_sells</th></tr></thead><tbody><tr><td>-0.08505704365079364</td><td>-0.08562127976190476</td><td>1260</td><td>1260</td><td>-0.7109375</td><td>433</td><td>343</td></tr></tbody></table>"
"<table><thead><tr><th>avg_buy_price</th><th>avg_sell_price</th><th>total_buy_size</th><th>total_sell_size</th><th>pnl</th><th>num_buys</th><th>num_sells</th></tr></thead><tbody><tr><td>-0.08705357142857141</td><td>-0.0884821428571429</td><td>700</td><td>700</td><td>-1.0000000000000426</td><td>245</td><td>404</td></tr></tbody></table>"
]
},
"metadata": {},
@@ -239,7 +239,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017821, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:01.068508300Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:01.068458300Z&quot;, order_side: Sell, order_status: Working, order_price: -0.0625, order_size: 100, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017821, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:14.317108Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:14.317058Z&quot;, order_side: Sell, order_status: Working, order_price: -0.0625, order_size: 99, order_filled: 1 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:00:14.317108Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:00:14.317058Z&quot;, order_id: 1017821, security_desc: ZNZ9-ZNH0, fill_side: Sell, fill_price: -0.0625, fill_size: 1, fill_id: 846792514696, total_traded: 2, num_orders: 0, tag: FIFO, bsize: 28773, bid: -0.0703125, ask: -0.0625, asize: 238261 }</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017823, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:14.317158Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:14.317108Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 1, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017821, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:22.335367800Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:22.335317800Z&quot;, order_side: Sell, order_status: Working, order_price: -0.0625, order_size: 98, order_filled: 1 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:00:22.335367800Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:00:22.335317800Z&quot;, order_id: 1017821, security_desc: ZNZ9-ZNH0, fill_side: Sell, fill_price: -0.0625, fill_size: 1, fill_id: 846792514696, total_traded: 2, num_orders: 0, tag: FIFO, bsize: 28774, bid: -0.0703125, ask: -0.0625, asize: 237283 }</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017825, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:22.335417800Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:22.335367800Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 1, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017821, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:32.182706700Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:32.182656700Z&quot;, order_side: Sell, order_status: Working, order_price: -0.0625, order_size: 97, order_filled: 1 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:00:32.182706700Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:00:32.182656700Z&quot;, order_id: 1017821, security_desc: ZNZ9-ZNH0, fill_side: Sell, fill_price: -0.0625, fill_size: 1, fill_id: 846792514696, total_traded: 3, num_orders: 0, tag: FIFO, bsize: 28774, bid: -0.0703125, ask: -0.0625, asize: 239981 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017827, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:32.182756700Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:32.182706700Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 1, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017821, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:37.759419700Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:37.759369700Z&quot;, order_side: Sell, order_status: Working, order_price: -0.0625, order_size: 96, order_filled: 1 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:00:37.759419700Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:00:37.759369700Z&quot;, order_id: 1017821, security_desc: ZNZ9-ZNH0, fill_side: Sell, fill_price: -0.0625, fill_size: 1, fill_id: 846792514696, total_traded: 1, num_orders: 0, tag: FIFO, bsize: 28426, bid: -0.0703125, ask: -0.0625, asize: 240330 }</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1017829, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:37.759469700Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:37.759419700Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 1, order_filled: 0 }</td><td>&lt;nuLine truncated
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:00:01.068508300Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:00:01.068458300Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 100, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:01:25.126882700Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:01:25.126832700Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 98, order_filled: 2 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:01:25.126882700Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:01:25.126832700Z&quot;, order_id: 1000745, security_desc: ZNZ9-ZNH0, fill_side: Buy, fill_price: -0.0703125, fill_size: 2, fill_id: 846794730500, total_traded: 6, num_orders: 0, tag: FIFO, bsize: 28876, bid: -0.0703125, ask: -0.0625, asize: 240376 }</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:02:38.628549800Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:02:38.628499800Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 97, order_filled: 1 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:02:38.628549800Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:02:38.628499800Z&quot;, order_id: 1000745, security_desc: ZNZ9-ZNH0, fill_side: Buy, fill_price: -0.0703125, fill_size: 1, fill_id: 846794730500, total_traded: 4, num_orders: 0, tag: FIFO, bsize: 28859, bid: -0.0703125, ask: -0.0625, asize: 256543 }</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:02:48.944973600Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:02:48.944923600Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 55, order_filled: 42 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:02:48.944973600Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:02:48.944923600Z&quot;, order_id: 1000745, security_desc: ZNZ9-ZNH0, fill_side: Buy, fill_price: -0.0703125, fill_size: 42, fill_id: 846794730500, total_traded: 200, num_orders: 0, tag: 2 FIFOCorrected 2671, bsize: 28854, bid: -0.0703125, ask: -0.0625, asize: 256541 }</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:03:27.628810100Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:03:27.628760100Z&quot;, order_side: Buy, order_status: Working, order_price: -0.0703125, order_size: 53, order_filled: 2 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:03:27.628810100Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:03:27.628760100Z&quot;, order_id: 1000745, security_desc: ZNZ9-ZNH0, fill_side: Buy, fill_price: -0.0703125, fill_size: 2, fill_id: 846794730500, total_traded: 6, num_orders: 0, tag: FIFO, bsize: 32039, bid: -0.0703125, ask: -0.0625, asize: 256737 }</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000745, security_desc: ZNZ9-ZNH0, order_sending_time: &quot;2019-11-27T14:04:38.654405800Z&quot;, order_TRANSACT_time: &quot;2019-11-27T14:04:38.654355800Z&quot;, order_side: Buy, order_status: Completed, order_price: -0.0703125, order_size: 0, order_filled: 53 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:04:38.654405800Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:04:38.654355800Z&quot;, order_id: 1000745, security_desc: ZNZ9-ZNH0, fill_side: Buy, fill_price: -0.0703125, fill_size: 53, fill_id: 846794730500, total_traded: 504, num_orders: 0, tag: 2 FIFOCorrected 2458 1000745 FULLFILL , bsize: 33337, bid: -0.0703125, ask: -0.0625, asize: 256698 }</td></tr><tr><td>11</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_sending_time: &quot;2019-11-27T14:23:46.868744900Z&quot;, fill_TRANSACT_time: &quot;2019-11-27T14:23:46.868694900Z&quot;, order_id: 1000751, security_desc: ZNZ9-ZNH0, fill_side: Sell, fill_price: -0.0625, fill_size: 2, fill_id: 782, total_traded: 2664, num_orders: 83, tag: PRORATA 48270 , bsize: 542847, bid: -0.0703125, ask: -0.0625, asize: 48270 }</td></tr><tr><td>12</td><td>&lt;null&gt;</td><td>{ bts.history.Display+FillDisplay: fill_seLine truncated
]
},
"metadata": {},
@@ -189,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 17,
"metadata": {
"scrolled": true
},
@@ -208,17 +208,17 @@
"//var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
"//var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
"var security_list = new [] {\"ZNZ9\",\"ZNZ9-ZNH0\", \"ZNH0\"};\n",
"var algo_params = \"tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125\";\n",
"var algo_params = \"tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125;stack_length=3\";\n",
"var qty = 20u;\n",
"var algo_results = algo_results<StackSpreader, HistoryRow>(sink, fill_model, algo_params, \n",
" bts.api.Side.Sell, 0.0, qty, \n",
" bts.api.Side.Undefined, 0.0, qty, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -228,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 19,
"metadata": {
"scrolled": true
},
@@ -236,7 +236,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th>avg_buy_price</th><th>avg_sell_price</th><th>total_buy_size</th><th>total_sell_size</th><th>pnl</th><th>num_buys</th><th>num_sells</th></tr></thead><tbody><tr><td>64.73437499999999</td><td>129.47916666666666</td><td>120</td><td>60</td><td>0.6250000000009095</td><td>34</td><td>18</td></tr></tbody></table>"
"<table><thead><tr><th>avg_buy_price</th><th>avg_sell_price</th><th>total_buy_size</th><th>total_sell_size</th><th>pnl</th><th>num_buys</th><th>num_sells</th></tr></thead><tbody><tr><td>64.7265625</td><td>129.4609375</td><td>80</td><td>40</td><td>0.3125</td><td>26</td><td>13</td></tr></tbody></table>"
]
},
"metadata": {},
@@ -245,7 +245,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.507092800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.507087800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.507092800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.507087800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.510621200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.510616200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.783796900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.783791900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.783796900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.783791900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.860445900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.860440900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.326631200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.326626200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.326631200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.326626200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.384269700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.384264700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.596691900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.596686900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.596691900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.596686900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:03:10.773160200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:03:10.773155200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4453125, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:03:10.773160200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:03:10.773155200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 20, order_filled: 0 }</td><td>&lt;Line truncated
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000181, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.46875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000185, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000182, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000185, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000182, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000185, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000182, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000185, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000182, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.484375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Sell, order_status: Working, order_price: 129.5, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>14</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000183,Line truncated
]
},
"metadata": {},
@@ -189,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 20,
"metadata": {
"scrolled": true
},
@@ -208,17 +208,17 @@
"//var security_list = new [] {\"ZNZ9\",\"ZNH0\"};\n",
"//var algo_params = \"size=10;tick_size=0.015625,0.015625;hedge_factors=1,-1;profit_ticks=0\";\n",
"var security_list = new [] {\"ZNZ9\",\"ZNZ9-ZNH0\", \"ZNH0\"};\n",
"var algo_params = \"tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125\";\n",
"var algo_params = \"tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,-1,-1;profit_ticks=0.0078125;stack_length=2\";\n",
"var qty = 20u;\n",
"var algo_results = algo_results<StackSpreader, HistoryRow>(sink, fill_model, algo_params, \n",
" bts.api.Side.Sell, 0.0, qty, \n",
" bts.api.Side.Undefined, 0.0, qty, \n",
" security_list, //must match below\n",
" new[] {z9f, spdf, h0f}, latency_iceberg);"
]
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -228,30 +228,11 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th>avg_buy_price</th><th>avg_sell_price</th><th>total_buy_size</th><th>total_sell_size</th><th>pnl</th><th>num_buys</th><th>num_sells</th></tr></thead><tbody><tr><td>64.73437499999999</td><td>129.47916666666666</td><td>120</td><td>60</td><td>0.6250000000009095</td><td>34</td><td>18</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>order</th><th>fill</th></tr></thead><tbody><tr><td>0</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.010541Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.010536Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>1</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.507092800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.507087800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>2</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.507092800Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.507087800Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>3</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.510621200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.510616200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>4</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.783796900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.783791900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>5</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.783796900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.783791900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>6</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:00.860445900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:00.860440900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>7</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.326631200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.326626200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>8</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.326631200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.326626200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>9</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.384269700Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.384264700Z&quot;, order_side: Buy, order_status: Working, order_price: 129.421875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>10</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.596691900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.596686900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4296875, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>11</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:00:01.596691900Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:00:01.596686900Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4375, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>12</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000872, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:03:10.773160200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:03:10.773155200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.4453125, order_size: 20, order_filled: 0 }</td><td>&lt;null&gt;</td></tr><tr><td>13</td><td>{ bts.history.Display+OrderDisplay: order_id: 1000871, security_desc: ZNH0, order_sending_time: &quot;2019-11-25T14:03:10.773160200Z&quot;, order_TRANSACT_time: &quot;2019-11-25T14:03:10.773155200Z&quot;, order_side: Buy, order_status: Working, order_price: 129.453125, order_size: 20, order_filled: 0 }</td><td>&lt;Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"var pnl = algo_pnl(algo_results_cached);\n",
"display(pnl);\n",