honing in
This commit is contained in:
1 parent
73cfa17791
commit
fed7ca1ff3
11 files changed
+317
-347
No files matched your search
@@ -11,6 +11,7 @@ using MongoDB.Bson.Serialization;
|
||||
using bts.co2;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
using System.Collections.Generic;
|
||||
using mbts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
@@ -76,15 +77,81 @@ namespace bts.history
|
||||
IMongoQueryable<H> res = coll.AsQueryable();
|
||||
Expression<Func<H, bool>> timeexpr = null;
|
||||
if(use_sending_time)
|
||||
timeexpr = (H h) => h.sending_time >= begin && h.sending_time <= end;
|
||||
timeexpr = (H h) => h.sending_time >= begin && h.sending_time <= end;
|
||||
else
|
||||
timeexpr = (H h) => h.transact_time >= begin && h.transact_time <= end;
|
||||
res = res.Where( timeexpr );
|
||||
return res;
|
||||
}
|
||||
|
||||
//so I can get into a local linq through the jupyter nb
|
||||
public static IEnumerable<T> local<T>(IMongoQueryable<T> q)
|
||||
{
|
||||
return q.AsEnumerable<T>();
|
||||
}
|
||||
|
||||
public static IEnumerable<TopBookMessage> create_synthetic_top(IEnumerable<TopBookMessage>[] datastream,
|
||||
double[] ratio, double[] price_mult = null)
|
||||
{
|
||||
if(price_mult == null)
|
||||
price_mult = ratio;
|
||||
|
||||
TopBookMessage[] valcache = new TopBookMessage[datastream.Length];
|
||||
bool go = false; bool once = false;
|
||||
do
|
||||
{
|
||||
for(int i = 0; i < datastream.Length; i++)
|
||||
{
|
||||
go |= datastream[i].GetEnumerator().MoveNext();
|
||||
if(go)
|
||||
{
|
||||
valcache[i] = datastream[i].GetEnumerator().Current;
|
||||
if(once) //we have a value for all legs
|
||||
{
|
||||
double bid = 0.0, ask = 0.0; uint bsize = uint.MaxValue, asize = uint.MaxValue;
|
||||
for(int z = 0; z < valcache.Length; z++)
|
||||
{
|
||||
double r = ratio[z];
|
||||
double p = price_mult[z];
|
||||
var b = valcache[z].Bid;
|
||||
var a = valcache[z].Ask;
|
||||
if(r > 0.0)
|
||||
{
|
||||
//you receive the bid price for each buy leg if you sell
|
||||
bid += b.price() * p;
|
||||
bsize = Math.Min(bsize, (uint)(b.Size / r));
|
||||
|
||||
//you pay the ask price for each buy leg if you buy
|
||||
ask += a.price() * p;
|
||||
asize = Math.Min(asize, (uint)(a.Size / r));
|
||||
}
|
||||
else //sell this leg, look at bid for bid
|
||||
{
|
||||
//you pay ask price for each sell leg if you sell
|
||||
bid += a.price() * p;
|
||||
bsize = Math.Min(bsize, (uint)(a.Size / r));
|
||||
|
||||
//you receive bid price for each sell leg if you buy
|
||||
ask += b.price() * p;
|
||||
asize = Math.Min(asize, (uint)(b.Size / r));
|
||||
}
|
||||
}
|
||||
var bi = IntPrice.from_double(bid, 7);
|
||||
var ai = IntPrice.from_double(ask, 7);
|
||||
yield return new TopBookMessage {
|
||||
Bid = new PriceSizeMessage { Size = bsize, Mantissa = bi.mantissa, Exponent = bi.exponent },
|
||||
Ask = new PriceSizeMessage { Size = asize, Mantissa = ai.mantissa, Exponent = ai.exponent }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
while(go);
|
||||
}
|
||||
|
||||
public IEnumerable<OrderOrFill> run_algo(IAlgo algo, IFillModel fill_model, uint latency,
|
||||
IEnumerable<HistoryRow> datastream)
|
||||
Dictionary< string, IEnumerable<HistoryRow> > datastream)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user