roundtrip

This commit is contained in:
Kevin Darby committed 2019-12-11 18:07:33 -05:00
1 parent 5e6fe7282d
commit 0f1c81eb48
20 files changed
+158 -263

No files matched your search

@@ -13,6 +13,7 @@ namespace bts.history
{
bool is_completed();
void reset();
void set_param(string name, string val);
void process_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage curr_book,
MarketDataIncrementalRefresh packet);
@@ -21,13 +22,12 @@ namespace bts.history
IFillModel fill_model { get; }
}
abstract partial class AlgoBase : IAlgo
abstract public partial class AlgoBase : IAlgo
{
public readonly Guid guid = Guid.NewGuid();
public ulong order_key { get; private set;}
public string[] security_list { get; private set; }
public Bucket bucket { get; private set;}
public Action<FillEntry> on_fill;
public Action<OrderStatus> on_status;
@@ -36,12 +36,11 @@ namespace bts.history
readonly protected SortedDictionary< string, Func<MDEntry, OrderIDEntry, bool> > _filter = new SortedDictionary<string, Func<MDEntry, OrderIDEntry, bool>>();
protected AlgoBase(IFillModel fill_model, Bucket bucket, string[] security_list)
protected AlgoBase(IFillModel fill_model, string[] security_list)
{
on_fill = new Action<FillEntry>(f => {});
on_status = new Action<OrderStatus>(s => {});
this._fill_model = fill_model;
this.bucket = bucket;
this.security_list = security_list;
}
@@ -134,7 +133,7 @@ namespace bts.history
}
protected abstract void do_cancel(Timestamp asof);
internal class Handle : IEquatable<Handle>
public class Handle : IEquatable<Handle>
{
readonly AlgoBase _algo;
public Handle(AlgoBase algo)
@@ -6,13 +6,28 @@ using System.Reflection;
namespace bts.history
{
public class AlgoFactory
{
static public IAlgo algo_factory(System.Type t, IFillModel fill_model,
string[] security_list, string algo_params = null)
{
return AlgoBase.algo_factory(t, fill_model, security_list, algo_params);
}
static public void set_algo_params(IAlgo inst, string algo_params)
{
AlgoBase.set_algo_params((AlgoBase) inst, algo_params);
}
static public void set_algo_params(IAlgo inst, IEnumerable<string> param)
{
AlgoBase.set_algo_params((AlgoBase)inst, param);
}
}
abstract partial class AlgoBase
{
static public AlgoBase algo_factory(System.Type t, IFillModel fill_model,
string[] security_list, string algo_params = null)
{
AlgoBase inst = inst = (AlgoBase)Activator.CreateInstance(t, BindingFlags.NonPublic, null,
new object[] { fill_model, fill_model.bucket, security_list }, System.Globalization.CultureInfo.CurrentCulture );
AlgoBase inst = inst = (AlgoBase)Activator.CreateInstance(t, fill_model, security_list);
if(algo_params != null)
set_algo_params(inst, algo_params);
@@ -61,7 +61,7 @@ namespace bts.history
var path = DataDownloader.data_path(_tradedate.Date);
new FileInfo(path).Directory.Create();
_fs = new StreamWriter(
File.Open(path + $"/{_symbol}_{_securitytype}_{algo.GetType().Name}_{algo.bucket.LowerBound.ToString("0") }_trades.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite) );
File.Open(path + $"/{_symbol}_{_securitytype}_{algo.GetType().Name}_{algo.fill_model.bucket.LowerBound.ToString("0") }_trades.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite) );
}
void do_stats()
@@ -6,7 +6,7 @@ using Google.Protobuf.WellKnownTypes;
namespace bts.history
{
abstract class CompositeBase<Child, Hedge> : AlgoBase
public abstract class CompositeBase<Child, Hedge> : AlgoBase
where Hedge : AlgoBase
{
protected List<Handle> _children = new List<Handle>();
@@ -34,7 +34,7 @@ namespace bts.history
}
}
}
protected CompositeBase(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list)
public CompositeBase(IFillModel fill_model, string[] security_list) : base(fill_model, security_list)
{
}
@@ -89,9 +89,9 @@ namespace bts.history
protected virtual void on_child_status(Handle child, OrderStatus stat) { }
}
abstract class CompositeAlgo<Child> : CompositeBase<Child, NullAlgo>
public abstract class CompositeAlgo<Child> : CompositeBase<Child, NullAlgo>
{
protected CompositeAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public CompositeAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
public override bool is_completed()
{
@@ -123,14 +123,14 @@ namespace bts.history
foreach (var child in _children)
child?.algo.process_book(security_desc, security_key, current_book, working_book, packet);
}
}
}
abstract class CompositeHedgeAlgo<Child, Hedge> : CompositeBase<Child, Hedge>
public abstract class CompositeHedgeAlgo<Child, Hedge> : CompositeBase<Child, Hedge>
where Hedge : AlgoBase
{
protected int _payupcount;
protected Dictionary<Handle, Hedge> _hedges = new Dictionary<Handle, Hedge>();
protected CompositeHedgeAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) {}
public CompositeHedgeAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) {}
protected virtual bool are_hedges_out()
{
@@ -8,11 +8,11 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class CoverAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
public class CoverAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
where Child : AlgoBase
where Hedge : AlgoBase
{
protected CoverAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public CoverAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
//algo state
private MarketDataIncrementalRefresh _packet;
@@ -6,7 +6,7 @@ using mbts.co2;
namespace bts.history
{
class JoinAlgo<Child> : CompositeAlgo<Child>
public class JoinAlgo<Child> : CompositeAlgo<Child>
where Child : AlgoBase
{
enum AlgoState
@@ -25,7 +25,7 @@ namespace bts.history
int _turncount, _pilecount;
(int, int) _piq;
protected JoinAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public JoinAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
//algo parameters
public bool initial_pile { get; set; } = false;
public bool should_chase { get; set; } = true;
@@ -138,7 +138,7 @@ namespace bts.history
{
if(_state == AlgoState.Joined || _state == AlgoState.WaitingForJoin)
{
Log.Testing.info("deploy_join_function " + this.bucket.UpperBound);
Log.Testing.info("deploy_join_function ");
if(_child == null)
{
@@ -8,7 +8,7 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class LeanAlgo<Child> : CompositeAlgo<Child>
public class LeanAlgo<Child> : CompositeAlgo<Child>
where Child : AlgoBase
{
enum AlgoState
@@ -26,7 +26,7 @@ namespace bts.history
co2.BookMessage _snapshot, _currentbook;
int _payupcount;
protected LeanAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public LeanAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
//algo parameters
public double lean_factor { get; set; } = 3.0;
public uint lean_quantity { get; set; } = 0;
@@ -115,7 +115,7 @@ namespace bts.history
//this should precipitate a fill
_child.update(packet.timestamp(), newprice);
Log.Testing.info($"payup_function {this.bucket.UpperBound} ");
Log.Testing.info($"payup_function ");
}
}
}
@@ -5,9 +5,9 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class LimitOrder : AlgoBase
public class LimitOrder : AlgoBase
{
protected LimitOrder(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public LimitOrder(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
protected OrderEntry _myorder;
OrderStatus _status;
@@ -5,9 +5,9 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class MarketOrder : LimitOrder
public class MarketOrder : LimitOrder
{
protected MarketOrder(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public MarketOrder(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
{
@@ -11,7 +11,7 @@ using mbts.co2;
namespace bts.history
{
class NativeAlgo : CompositeAlgo<AlgoBase>
public class NativeAlgo : CompositeAlgo<AlgoBase>
{
readonly Dictionary<ulong, api.orderman.OrderState> _order_key_vs_state = new Dictionary<ulong, api.orderman.OrderState>();
api.Side _myside;
@@ -35,8 +35,8 @@ namespace bts.history
MessageParser<api.orderman.OrderState> _stateparser = new MessageParser<api.orderman.OrderState>(() => new api.orderman.OrderState());
MessageParser<api.orderman.Fill> _fillparser = new MessageParser<api.orderman.Fill>(() => new api.orderman.Fill());
public NativeAlgo(IFillModel fill_model, Bucket bucket, string[] security_list,
api.orderman.OrderDefinition def) : base(fill_model, bucket, security_list)
public NativeAlgo(IFillModel fill_model, string[] security_list,
api.orderman.OrderDefinition def) : base(fill_model, security_list)
{
_def = def;
unsafe
@@ -150,7 +150,7 @@ namespace bts.history
if(native != IntPtr.Zero)
{
AlgoTestNativeMethods.destroy_algo(native); //TODO, boolean
var child = new NativeAlgo(_fill_model, bucket, this.security_list, def);
var child = new NativeAlgo(_fill_model, this.security_list, def);
hookup_child(child, this.security_list, def.Side, price, size, _myasof, order_key);
// var handle = this.hookup_child(child, security_list, def.Side, price, size, _myasof, null, null, order_key);
// _children.Add(handle);
@@ -6,9 +6,9 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class NullAlgo : AlgoBase
public class NullAlgo : AlgoBase
{
protected NullAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public NullAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
public override bool is_completed() => true;
public override object report() { return string.Empty; }
@@ -8,7 +8,7 @@ using mbts.co2;
namespace bts.history
{
class RoundTripAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
public class RoundTripAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
where Child : AlgoBase
where Hedge : AlgoBase
{
@@ -30,7 +30,7 @@ namespace bts.history
private MarketDataIncrementalRefresh _packet;
protected RoundTripAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public RoundTripAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
//algo parameters
public double lean_factor { get; set; } = 1.0;
public int profit_ticks { get; set; } = 1;
+3 -3
View File
@@ -6,7 +6,7 @@ using mbts.co2;
namespace bts.history
{
class TopAlgo<Child> : CompositeAlgo<Child>
public class TopAlgo<Child> : CompositeAlgo<Child>
where Child : AlgoBase
{
enum AlgoState
@@ -23,7 +23,7 @@ namespace bts.history
co2.BookMessage _currentbook;
int _topcount;
protected TopAlgo(IFillModel fill_model, Bucket bucket, string[] security_list) : base(fill_model, bucket, security_list) { }
public TopAlgo(IFillModel fill_model, string[] security_list) : base(fill_model, security_list) { }
//algo parameters
public double top_factor { get; set; } = 1.0;
public uint top_quantity { get; set; } = 0;
@@ -86,7 +86,7 @@ namespace bts.history
void cancel_top_function(MarketDataIncrementalRefresh packet, string security_desc, object param)
{
Log.assert(_state == AlgoState.CancelRequested || _state == AlgoState.Done);
Log.Testing.info("cancel_top_function " + this.bucket.UpperBound);
Log.Testing.info("cancel_top_function ");
_child.cancel(packet.timestamp());
_state = AlgoState.Done;
@@ -8,35 +8,35 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class JoinCoverLean : CoverAlgo<JoinAlgo<TopAlgo<LimitOrder>>, LeanAlgo<LimitOrder>>
public class JoinCoverLean : CoverAlgo<JoinAlgo<TopAlgo<LimitOrder>>, LeanAlgo<LimitOrder>>
{
protected JoinCoverLean(IFillModel fill_model, Bucket bucket, string[] security_list)
: base(fill_model, bucket, security_list)
public JoinCoverLean(IFillModel fill_model, string[] security_list)
: base(fill_model, security_list)
{
}
}
class PegCoverLean : CoverAlgo<JoinAlgo<TopAlgo<LimitOrder>>, LeanAlgo<LimitOrder>>
public class PegCoverLean : CoverAlgo<JoinAlgo<TopAlgo<LimitOrder>>, LeanAlgo<LimitOrder>>
{
protected PegCoverLean(IFillModel fill_model, Bucket bucket, string[] security_list)
: base(fill_model, bucket, security_list)
public PegCoverLean(IFillModel fill_model, string[] security_list)
: base(fill_model, security_list)
{
this.set_param(nameof(JoinAlgo<LimitOrder>.initial_pile), true.ToString());
}
}
class RoundTrip : RoundTripAlgo<LimitOrder, LeanAlgo<LimitOrder>>
public class RoundTrip : RoundTripAlgo<LimitOrder, LeanAlgo<LimitOrder>>
{
protected RoundTrip(IFillModel fill_model, Bucket bucket, string[] security_list)
: base(fill_model, bucket, security_list)
public RoundTrip(IFillModel fill_model, string[] security_list)
: base(fill_model, security_list)
{
}
}
class TWAP : NativeAlgo
public class TWAP : NativeAlgo
{
protected TWAP(IFillModel fill_model, Bucket bucket, string[] security_list)
: base(fill_model, bucket, security_list, build_def())
public TWAP(IFillModel fill_model, string[] security_list)
: base(fill_model, security_list, build_def())
{
}
static api.orderman.OrderDefinition build_def()
@@ -12,7 +12,7 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
public delegate void OnMarketTrade(MarketDataIncrementalRefresh md);
interface IOrderBook
public interface IOrderBook
{
string security_desc { get; }
uint security_key { get; }
@@ -32,7 +32,6 @@ namespace bts.history
OrderEntry insert_my_order(OrderEntry order);
OrderEntry change_my_order(Timestamp asof, ulong order_id, double price, uint size = uint.MinValue);
bool cancel_my_order(Timestamp asof, ulong my_order_id);
void validate_new_queue(AlgoBase algo, MarketDataIncrementalRefresh current_book_packet, Func<MDEntry, OrderIDEntry, bool> filter);
void match_our_trades(MarketDataIncrementalRefresh md);
void match_crosses(Timestamp ts);
MBOBook mbo_book {get;}
@@ -184,11 +183,6 @@ namespace bts.history
{
return _mbo.cancel_my_order(asof, my_order_id);
}
public void validate_new_queue(AlgoBase algo, MarketDataIncrementalRefresh current_book_packet, Func<MDEntry, OrderIDEntry, bool> filter)
{
_mbo.validate_new_queue(algo, current_book_packet, filter);
}
public void match_our_trades(MarketDataIncrementalRefresh md)
{
@@ -9,7 +9,7 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class FIFOModel : IFillModel
public class FIFOModel : IFillModel
{
IDictionary<string, MBOBook> _books = new Dictionary<string, MBOBook>();
@@ -11,7 +11,7 @@ using MathNet.Numerics.Statistics;
namespace bts.history
{
class MBOBook
public class MBOBook
{
public string security_desc { get; private set; }
@@ -53,26 +53,6 @@ namespace bts.history
this.security_desc = security_desc;
}
public void validate_new_queue(AlgoBase algo, MarketDataIncrementalRefresh current_book_packet, Func<MDEntry, OrderIDEntry, bool> filter)
{
foreach (var entry in current_book_packet.MdEntries)
{
if (!filter(entry, null))
continue;
if (entry.MdPriceLevel == 1 && entry.MdEntryType == MDEntryType.Bid)
{
var mbo = get_mbo(Utils.same_side(entry.MdEntryType));
Log.assert(mbo.TryGetValue(entry.MdEntryPx, out QueueType q));
//at times the crossed orders take a few lines to get deleted from queue.
if (q.Where(x => x.Value.side == api.Side.Sell).Count() > (current_book_packet.OrderIdEntries.Count + current_book_packet.MdEntries.Count))
Log.Testing.warn("q should be empty");
if (algo.bucket.LowerBound == 0 && q.Count > 1)
Log.Testing.warn("q should be empty");
}
}
}
public (int, int) get_my_piq(ulong orderid)
{
int piq = 0, count = 0;
@@ -62,6 +62,7 @@
"using MongoDB.Driver.Linq;\n",
"using Google.Protobuf.WellKnownTypes;\n",
"using static bts.history.Query;\n",
"using MathNet.Numerics.Statistics;\n",
"using mbts.co2;\n"
]
},
@@ -100,13 +101,32 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = new DateTime(2019, 11, 25, 14, 0, 0);\n",
"var end = new DateTime(2019, 11, 25, 23, 59, 59);\n",
"var c1t = q.timeseries<HistoryRow>(c1, begin, end).OrderBy(x => x.sending_time);\n",
"var c2t = q.timeseries<HistoryRow>(c2, begin, end).OrderBy(x => x.sending_time);\n",
"var c3t = q.timeseries<HistoryRow>(c3, begin, end).OrderBy(x => x.sending_time);\n",
"\n",
"var c1f = local(c1t);\n",
"var c2f = local(c2t);\n",
"var c3f = local(c3t);"
]
},
{
"cell_type": "code",
"execution_count": 6,
@@ -115,95 +135,43 @@
},
"outputs": [],
"source": [
"var c1t = q.timeseries<HistoryRow>(c1, new DateTime(2019, 11, 25, 14,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));\n",
"var c2t = q.timeseries<HistoryRow>(c2, new DateTime(2019, 11, 25, 14,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));\n",
"var c3t = q.timeseries<HistoryRow>(c3, new DateTime(2019, 11, 25, 14 ,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));"
"//display(c1t.Count());\n",
"//display(c2t.Count());\n",
"//display(c3t.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"880191"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"515525"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"313000"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"display(c1t.Count());\n",
"display(c2t.Count());\n",
"display(c3t.Count());\n"
"var fill_model = new FIFOModel(new Bucket(20_000, 20_001));\n",
"var security_list = new [] {\"ZNH0\",\"ZNZ9-ZNH0\", \"ZNZ9\"};\n",
"//quotes the last leg\n",
"var algo = AlgoFactory.algo_factory(typeof(RoundTrip), fill_model, security_list,\n",
" \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,1,-1\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"var fill_model = new FIFOModel(20);\n",
"var algo = AlgoBase.algo_factory()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>SecurityDesc</th><th>Book</th><th>TopBook</th><th>Trade</th><th>Order</th></tr></thead><tbody><tr><td>0</td><td>2019-11-25 00:00:00Z</td><td>2019-11-25 19:00:00Z</td><td>2019-11-25 19:00:00Z</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>9955014</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574708400, Nanos: 47819600 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574708400, Nanos: 47703400 }</td><td>ZNH0</td><td>{ bts.co2.BookMessage: Bids: [ { bts.co2.PriceSizeMessage: Mantissa: 129578125000, Exponent: -9, Size: 1114 }, { bts.co2.PriceSizeMessage: Mantissa: 129562500000, Exponent: -9, Size: 2349 }, { bts.co2.PriceSizeMessage: Mantissa: 129546875000, Exponent: -9, Size: 2129 }, { bts.co2.PriceSizeMessage: Mantissa: 129531250000, Exponent: -9, Size: 3452 }, { bts.co2.PriceSizeMessage: Mantissa: 129515625000, Exponent: -9, Size: 1822 }, { bts.co2.PriceSizeMessage: Mantissa: 129500000000, Exponent: -9, Size: 1940 }, { bts.co2.PriceSizeMessage: Mantissa: 129484375000, Exponent: -9, Size: 2178 }, { bts.co2.PriceSizeMessage: Mantissa: 129468750000, Exponent: -9, Size: 1869 }, { bts.co2.PriceSizeMessage: Mantissa: 129453125000, Exponent: -9, Size: 1959 }, { bts.co2.PriceSizeMessage: Mantissa: 129437500000, Exponent: -9, Size: 2074 } ], Asks: [ { bts.co2.PriceSizeMessage: Mantissa: 129593750000, Exponent: -9, Size: 1479 }, { bts.co2.PriceSizeMessage: Mantissa: 129609375000, Exponent: -9, Size: 2141 }, { bts.co2.PriceSizeMessage: Mantissa: 129625000000, Exponent: -9, Size: 2139 }, { bts.co2.PriceSizeMessage: Mantissa: 129640625000, Exponent: -9, Size: 2071 }, { bts.co2.PriceSizeMessage: Mantissa: 129656250000, Exponent: -9, Size: 1817 }, { bts.co2.PriceSizeMessage: Mantissa: 129671875000, Exponent: -9, Size: 2216 }, { bts.co2.PriceSizeMessage: Mantissa: 129687500000, Exponent: -9, Size: 2034 }, { bts.co2.PriceSizeMessage: Mantissa: 129703125000, Exponent: -9, Size: 1950 }, { bts.co2.PriceSizeMessage: Mantissa: 129718750000, Exponent: -9, Size: 1896 }, { bts.co2.PriceSizeMessage: Mantissa: 129734375000, Exponent: -9, Size: 1952 } ] }</td><td>{ bts.co2.TopBookMessage: Bid: { bts.co2.PriceSizeMessage: Mantissa: 129578125000, Exponent: -9, Size: 1114 }, Ask: { bts.co2.PriceSizeMessage: Mantissa: 129593750000, Exponent: -9, Size: 1479 } }</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"var z9f = z9.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var h0f = h0.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var spreadf = spread.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var z9t = z9f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var h0t = h0f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var spreadt = spreadf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var stream = run_algo<HistoryRow>(algo, bts.api.Side.Undefined, 0.0, 10, security_list, \n",
" new[] {c2f, c3f, c1f}, 500);\n",
"\n",
"display(h0f.Take(1));\n",
"display(stream.Take(500));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -234,33 +202,18 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{z9t, h0t, spreadt}, new[] {1.0, -1.0, -1.0}, new[] {1.0, -1.0, -1.0}, \n",
" x => x.TopBook.Bid.price() > 0.0 || x.TopBook.Ask.price() < 0.0, \n",
" (legs, synth)=> new TopReport<GetTopOfBook>(legs, synth));"
]
"source": []
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</th><th>sending_time</th><th>transact_time</th><th>bidsize</th><th>bid</th><th>ask</th><th>asksize</th><th>legbids</th><th>legasks</th></tr></thead><tbody><tr><td>0</td><td>11851041</td><td>2019-11-25 22:54:30.667725</td><td>2019-11-25 22:54:30.667299</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851041 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851041 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>1</td><td>11851042</td><td>2019-11-25 22:54:30.668019</td><td>2019-11-25 22:54:30.667773</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851042 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851042 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>2</td><td>11851042</td><td>2019-11-25 22:54:30.668019</td><td>2019-11-25 22:54:30.667773</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851042 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851042 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>3</td><td>11851043</td><td>2019-11-25 22:54:30.668036</td><td>2019-11-25 22:54:30.667774</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851043 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851043 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>4</td><td>11851043</td><td>2019-11-25 22:54:30.668036</td><td>2019-11-25 22:54:30.667774</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851043 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851043 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>5</td><td>11851044</td><td>2019-11-25 22:54:30.668054</td><td>2019-11-25 22:54:30.667777</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851044 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851044 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>6</td><td>11851044</td><td>2019-11-25 22:54:30.668054</td><td>2019-11-25 22:54:30.667777</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851044 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851044 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>7</td><td>11851045</td><td>2019-11-25 22:54:30.668078</td><td>2019-11-25 22:54:30.667779</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851045 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851045 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>8</td><td>11851045</td><td>2019-11-25 22:54:30.668078</td><td>2019-11-25 22:54:30.667779</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851045 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851045 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>9</td><td>11851046</td><td>2019-11-25 22:54:30.668091</td><td>2019-11-25 22:54:30.667782</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851046 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851046 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>10</td><td>11851046</td><td>2019-11-25 22:54:30.668091</td><td>2019-11-25 22:54:30.667782</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851046 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851046 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>11</td><td>11851047</td><td>2019-11-25 22:54:30.668105</td><td>2019-11-25 22:54:30.667787</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851047 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851047 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>12</td><td>11851047</td><td>2019-11-25 22:54:30.668105</td><td>2019-11-25 22:54:30.667787</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851047 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851047 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>13</td><td>11851048</td><td>2019-11-25 22:54:30.668137</td><td>2019-11-25 22:54:30.667789</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851048 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851048 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>14</td><td>11851048</td><td>2019-11-25 22:54:30.668137</td><td>2019-11-25 22:54:30.667789</td><td>193</td><td>-Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(synth.Take(10000).OrderBy(x => x.sending_time));\n",
"//display(synth.Take(10000).OrderBy(x => x.sending_time));\n",
"//Console.WriteLine(synth.Take(10).Count());"
]
},
@@ -62,6 +62,7 @@
"using MongoDB.Driver.Linq;\n",
"using Google.Protobuf.WellKnownTypes;\n",
"using static bts.history.Query;\n",
"using MathNet.Numerics.Statistics;\n",
"using mbts.co2;\n"
]
},
@@ -100,13 +101,32 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"var begin = new DateTime(2019, 11, 25, 14, 0, 0);\n",
"var end = new DateTime(2019, 11, 25, 23, 59, 59);\n",
"var c1t = q.timeseries<HistoryRow>(c1, begin, end).OrderBy(x => x.sending_time);\n",
"var c2t = q.timeseries<HistoryRow>(c2, begin, end).OrderBy(x => x.sending_time);\n",
"var c3t = q.timeseries<HistoryRow>(c3, begin, end).OrderBy(x => x.sending_time);\n",
"\n",
"var c1f = local(c1t);\n",
"var c2f = local(c2t);\n",
"var c3f = local(c3t);"
]
},
{
"cell_type": "code",
"execution_count": 6,
@@ -115,95 +135,43 @@
},
"outputs": [],
"source": [
"var c1t = q.timeseries<HistoryRow>(c1, new DateTime(2019, 11, 25, 14,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));\n",
"var c2t = q.timeseries<HistoryRow>(c2, new DateTime(2019, 11, 25, 14,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));\n",
"var c3t = q.timeseries<HistoryRow>(c3, new DateTime(2019, 11, 25, 14 ,0, 0), new DateTime(2019, 11, 25, 23, 59, 59));"
"//display(c1t.Count());\n",
"//display(c2t.Count());\n",
"//display(c3t.Count());\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"880191"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"515525"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"313000"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"display(c1t.Count());\n",
"display(c2t.Count());\n",
"display(c3t.Count());\n"
"var fill_model = new FIFOModel(new Bucket(20_000, 20_001));\n",
"var security_list = new [] {\"ZNH0\",\"ZNZ9-ZNH0\", \"ZNZ9\"};\n",
"//quotes the last leg\n",
"var algo = AlgoFactory.algo_factory(typeof(RoundTrip), fill_model, security_list,\n",
" \"size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,1,-1\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"var fill_model = new FIFOModel(20);\n",
"var algo = AlgoBase.algo_factory()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>trade_date</th><th>sending_time</th><th>transact_time</th><th>TradeDate</th><th>MsgSeqNum</th><th>SendingTime</th><th>TransactTime</th><th>SecurityDesc</th><th>Book</th><th>TopBook</th><th>Trade</th><th>Order</th></tr></thead><tbody><tr><td>0</td><td>2019-11-25 00:00:00Z</td><td>2019-11-25 19:00:00Z</td><td>2019-11-25 19:00:00Z</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574640000, Nanos: 0 }</td><td>9955014</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574708400, Nanos: 47819600 }</td><td>{ Google.Protobuf.WellKnownTypes.Timestamp: Seconds: 1574708400, Nanos: 47703400 }</td><td>ZNH0</td><td>{ bts.co2.BookMessage: Bids: [ { bts.co2.PriceSizeMessage: Mantissa: 129578125000, Exponent: -9, Size: 1114 }, { bts.co2.PriceSizeMessage: Mantissa: 129562500000, Exponent: -9, Size: 2349 }, { bts.co2.PriceSizeMessage: Mantissa: 129546875000, Exponent: -9, Size: 2129 }, { bts.co2.PriceSizeMessage: Mantissa: 129531250000, Exponent: -9, Size: 3452 }, { bts.co2.PriceSizeMessage: Mantissa: 129515625000, Exponent: -9, Size: 1822 }, { bts.co2.PriceSizeMessage: Mantissa: 129500000000, Exponent: -9, Size: 1940 }, { bts.co2.PriceSizeMessage: Mantissa: 129484375000, Exponent: -9, Size: 2178 }, { bts.co2.PriceSizeMessage: Mantissa: 129468750000, Exponent: -9, Size: 1869 }, { bts.co2.PriceSizeMessage: Mantissa: 129453125000, Exponent: -9, Size: 1959 }, { bts.co2.PriceSizeMessage: Mantissa: 129437500000, Exponent: -9, Size: 2074 } ], Asks: [ { bts.co2.PriceSizeMessage: Mantissa: 129593750000, Exponent: -9, Size: 1479 }, { bts.co2.PriceSizeMessage: Mantissa: 129609375000, Exponent: -9, Size: 2141 }, { bts.co2.PriceSizeMessage: Mantissa: 129625000000, Exponent: -9, Size: 2139 }, { bts.co2.PriceSizeMessage: Mantissa: 129640625000, Exponent: -9, Size: 2071 }, { bts.co2.PriceSizeMessage: Mantissa: 129656250000, Exponent: -9, Size: 1817 }, { bts.co2.PriceSizeMessage: Mantissa: 129671875000, Exponent: -9, Size: 2216 }, { bts.co2.PriceSizeMessage: Mantissa: 129687500000, Exponent: -9, Size: 2034 }, { bts.co2.PriceSizeMessage: Mantissa: 129703125000, Exponent: -9, Size: 1950 }, { bts.co2.PriceSizeMessage: Mantissa: 129718750000, Exponent: -9, Size: 1896 }, { bts.co2.PriceSizeMessage: Mantissa: 129734375000, Exponent: -9, Size: 1952 } ] }</td><td>{ bts.co2.TopBookMessage: Bid: { bts.co2.PriceSizeMessage: Mantissa: 129578125000, Exponent: -9, Size: 1114 }, Ask: { bts.co2.PriceSizeMessage: Mantissa: 129593750000, Exponent: -9, Size: 1479 } }</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td></tr></tbody></table>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"var z9f = z9.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var h0f = h0.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"var spreadf = spread.Where(x => x.Book != null && x.Book.Bids.Count > 0 && x.Book.Asks.Count > 0);\n",
"\n",
"var z9t = z9f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var h0t = h0f.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var spreadt = spreadf.AsEnumerable().Select(x => new GetTopOfBook(x)).OrderBy(x => x.sending_time);\n",
"var stream = run_algo<HistoryRow>(algo, bts.api.Side.Undefined, 0.0, 10, security_list, \n",
" new[] {c2f, c3f, c1f}, 500);\n",
"\n",
"display(h0f.Take(1));\n",
"display(stream.Take(500));\n",
"//display(z9f.Take(1));"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -234,33 +202,18 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"var synth = create_synthetic_top( new []{z9t, h0t, spreadt}, new[] {1.0, -1.0, -1.0}, new[] {1.0, -1.0, -1.0}, \n",
" x => x.TopBook.Bid.price() > 0.0 || x.TopBook.Ask.price() < 0.0, \n",
" (legs, synth)=> new TopReport<GetTopOfBook>(legs, synth));"
]
"source": []
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table><thead><tr><th><i>index</i></th><th>seq_num</th><th>sending_time</th><th>transact_time</th><th>bidsize</th><th>bid</th><th>ask</th><th>asksize</th><th>legbids</th><th>legasks</th></tr></thead><tbody><tr><td>0</td><td>11851041</td><td>2019-11-25 22:54:30.667725</td><td>2019-11-25 22:54:30.667299</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851041 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851041 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>1</td><td>11851042</td><td>2019-11-25 22:54:30.668019</td><td>2019-11-25 22:54:30.667773</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851042 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851042 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>2</td><td>11851042</td><td>2019-11-25 22:54:30.668019</td><td>2019-11-25 22:54:30.667773</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851042 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851042 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>3</td><td>11851043</td><td>2019-11-25 22:54:30.668036</td><td>2019-11-25 22:54:30.667774</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851043 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851043 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>4</td><td>11851043</td><td>2019-11-25 22:54:30.668036</td><td>2019-11-25 22:54:30.667774</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851043 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851043 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>5</td><td>11851044</td><td>2019-11-25 22:54:30.668054</td><td>2019-11-25 22:54:30.667777</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851044 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851044 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>6</td><td>11851044</td><td>2019-11-25 22:54:30.668054</td><td>2019-11-25 22:54:30.667777</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851044 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851044 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>7</td><td>11851045</td><td>2019-11-25 22:54:30.668078</td><td>2019-11-25 22:54:30.667779</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851045 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851045 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>8</td><td>11851045</td><td>2019-11-25 22:54:30.668078</td><td>2019-11-25 22:54:30.667779</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851045 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851045 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>9</td><td>11851046</td><td>2019-11-25 22:54:30.668091</td><td>2019-11-25 22:54:30.667782</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851046 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851046 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>10</td><td>11851046</td><td>2019-11-25 22:54:30.668091</td><td>2019-11-25 22:54:30.667782</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851046 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851046 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>11</td><td>11851047</td><td>2019-11-25 22:54:30.668105</td><td>2019-11-25 22:54:30.667787</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851047 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851047 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>12</td><td>11851047</td><td>2019-11-25 22:54:30.668105</td><td>2019-11-25 22:54:30.667787</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851047 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851047 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>13</td><td>11851048</td><td>2019-11-25 22:54:30.668137</td><td>2019-11-25 22:54:30.667789</td><td>193</td><td>-0.0390625</td><td>-0.0078125</td><td>60</td><td>11851048 482 129.531250 |11851040 156 129.593750 |11850702 60 -0.054688 |</td><td>11851048 72 129.531250 |11851040 193 129.625000 |11850702 14833 -0.054688 |</td></tr><tr><td>14</td><td>11851048</td><td>2019-11-25 22:54:30.668137</td><td>2019-11-25 22:54:30.667789</td><td>193</td><td>-Line truncated
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"display(synth.Take(10000).OrderBy(x => x.sending_time));\n",
"//display(synth.Take(10000).OrderBy(x => x.sending_time));\n",
"//Console.WriteLine(synth.Take(10).Count());"
]
},
+4 -3
View File
@@ -152,8 +152,8 @@ namespace bts.history
});
}
public IEnumerable<OrderOrFill> run_algo<T>(IAlgo algo, api.Side side, double price, uint size,
string[] security_list, IEnumerable<T>[] datastream, int framelimit = int.MaxValue)
static public IEnumerable<OrderOrFill> run_algo<T>(IAlgo algo, api.Side side, double price, uint size,
string[] security_list, IEnumerable<T>[] datastream, int framelimit = int.MaxValue)
where T : class, IHasBook, IHasTrade, IHasMBO, IHasTimestamp
{
var comparer = Comparer<Timestamp>.Create((x, y) => x.compare(y));
@@ -163,7 +163,7 @@ namespace bts.history
(h, f) => q.Add(f.timestamp, new OrderOrFill(f)), (h,s) => q.Add(s.last_change, new OrderOrFill(s)) );
int count = 0;
return stream_data(datastream, (T[] valcache, int min) =>
var ienum = stream_data<T,OrderOrFill> (datastream, (T[] valcache, int min) =>
{
if(count++ > framelimit)
throw new InvalidOperationException();
@@ -188,6 +188,7 @@ namespace bts.history
q.Clear();
return vals;
});
return ienum;
}
}