Added microscope for a closer look!
This commit is contained in:
1 parent
212f2a3d36
commit
0dcb3d3dfd
5 files changed
+100
-34
No files matched your search
@@ -6,6 +6,7 @@ using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.co2;
|
||||
using mbts.co2;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace bts.history{
|
||||
class MarketQueries{
|
||||
@@ -138,26 +139,7 @@ namespace bts.history{
|
||||
if(MarketQueriesHelper.intersects(b2_e.TimeRange,tr))
|
||||
rv.Add(Tuple.Create(b1_e, b2_e));
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void align_2_bookseries(
|
||||
BookSeries bser_1,
|
||||
BookSeries bser_2,
|
||||
Action<BookEntry, BookEntry> on_book){
|
||||
align_bookseries_fast(l => on_book(l.ElementAt(0),
|
||||
l.ElementAt(1)),
|
||||
bser_1, bser_2);
|
||||
}
|
||||
public static void align_3_bookseries(
|
||||
BookSeries bser_1,
|
||||
BookSeries bser_2,
|
||||
BookSeries bser_3,
|
||||
Action<BookEntry, BookEntry, BookEntry> on_book){
|
||||
align_bookseries_fast(l => on_book(l.ElementAt(0),
|
||||
l.ElementAt(1),
|
||||
l.ElementAt(2)),
|
||||
bser_1, bser_2, bser_3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void align_bookseries_fast(
|
||||
Action<IEnumerable<BookEntry>> on_book,
|
||||
@@ -191,6 +173,23 @@ namespace bts.history{
|
||||
}
|
||||
}
|
||||
|
||||
// finds book updates bw (and including) msg seq no's
|
||||
public static IEnumerable<BookEntry> find_in_range (BookSeries bser,
|
||||
UInt32 seq_1,
|
||||
UInt32 seq_2){
|
||||
return bser.book_entries().Where(b => b.PBook.MsgSeqNum >= seq_1 &&
|
||||
b.PBook.MsgSeqNum <= seq_2);
|
||||
}
|
||||
|
||||
// finds book updates bw (and including) times
|
||||
public static IEnumerable<BookEntry> find_in_range (BookSeries bser,
|
||||
Timestamp t1,
|
||||
Timestamp t2){
|
||||
return bser.book_entries().Where(b =>
|
||||
MarketQueriesHelper.compare(BookSeries.timestamp(b.PBook),t1) >= 0 &&
|
||||
MarketQueriesHelper.compare(BookSeries.timestamp(b.PBook),t2) <= 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using mbts.config;
|
||||
using bts.config;
|
||||
using bts.api.orderman;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace bts.history{
|
||||
class Microscope{
|
||||
enum Actions{
|
||||
Book,
|
||||
Trade,
|
||||
Order
|
||||
}
|
||||
// looks deeper into the data for
|
||||
// 1. book updates for <contract,date>* bw msg seq no's
|
||||
// 2. book updates for <contract,date>* bw t1 and t2
|
||||
// 3. book turn stats
|
||||
// 4. trades
|
||||
// 5. orders
|
||||
//(writes output to csv that can be plotted in some cases)
|
||||
public Microscope(HistoricalDataOptions hd_options){
|
||||
Console.WriteLine("Miscroscope:Hit key to continue:"); Console.ReadKey();
|
||||
//book,symbol,date,contract,m1,m2
|
||||
string[] args = hd_options.algo_params.Split(',');
|
||||
if (Actions.Book.ToString().ToLower()==args[0].ToLower()){
|
||||
string symbol = args[1];
|
||||
DateTime dt = DateTime.Parse(args[2]);
|
||||
string contract = args[3];
|
||||
UInt32 m1 = UInt32.Parse(args[4]),
|
||||
m2 = UInt32.Parse(args[5]);
|
||||
BookSeries bser = MarketQueriesHelper.get_book_state(symbol,
|
||||
contract,
|
||||
dt);
|
||||
var books = MarketQueries.find_in_range(bser,m1,m2);
|
||||
foreach (BookEntry b in books)
|
||||
Console.WriteLine(MarketQueriesHelper.book_entry_to_csv(b));
|
||||
}
|
||||
}
|
||||
|
||||
public void analyze(){
|
||||
}
|
||||
|
||||
private static void _analyze_book(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -97,13 +97,15 @@ namespace bts.history{
|
||||
_compare_seq_no (coex.ElementAt(6),3,4); //1035
|
||||
_compare_seq_no (coex.ElementAt(7),4,4); //1050
|
||||
|
||||
MarketQueries.align_2_bookseries(
|
||||
bser_1,
|
||||
bser_2,
|
||||
(b1, b2) => {
|
||||
MarketQueries.align_bookseries_fast(
|
||||
l => {
|
||||
var b1 = l.ElementAt(0);
|
||||
var b2 = l.ElementAt(1);
|
||||
var r = MarketQueriesHelper.intersection_type(b1.TimeRange, b2.TimeRange);
|
||||
Log.assert(r == TimerangeIntersection.INTERSECTION);
|
||||
});
|
||||
},
|
||||
bser_1,
|
||||
bser_2);
|
||||
}
|
||||
|
||||
public static void test_random_intersection(){
|
||||
@@ -124,11 +126,13 @@ namespace bts.history{
|
||||
bser_2 = cons_series(200,2,15,10),
|
||||
bser_3 = cons_series(400,2,15,5);
|
||||
var res = new List<Tuple<BookEntry,BookEntry,BookEntry>>();
|
||||
MarketQueries.align_3_bookseries(
|
||||
MarketQueries.align_bookseries_fast(
|
||||
l => res.Add(Tuple.Create(l.ElementAt(0),
|
||||
l.ElementAt(1),
|
||||
l.ElementAt(2))),
|
||||
bser_1,
|
||||
bser_2,
|
||||
bser_3,
|
||||
(b1,b2,b3) => res.Add(Tuple.Create(b1,b2,b3)));
|
||||
bser_3);
|
||||
_verify_intersection(bser_1,bser_2,bser_3,res);
|
||||
// random data
|
||||
int n_rnd_tests = 10;
|
||||
@@ -137,11 +141,13 @@ namespace bts.history{
|
||||
bser_2 = cons_series(100,3,23,null);
|
||||
bser_3 = cons_series(100,5,31,null);
|
||||
res = new List<Tuple<BookEntry,BookEntry,BookEntry>>();
|
||||
MarketQueries.align_3_bookseries(
|
||||
MarketQueries.align_bookseries_fast(
|
||||
l => res.Add(Tuple.Create(l.ElementAt(0),
|
||||
l.ElementAt(1),
|
||||
l.ElementAt(2))),
|
||||
bser_1,
|
||||
bser_2,
|
||||
bser_3,
|
||||
(b1,b2,b3) => res.Add(Tuple.Create(b1,b2,b3)));
|
||||
bser_3);
|
||||
_verify_intersection(bser_1,bser_2,bser_3,res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace bts.history{
|
||||
// date, output_file, spreaders
|
||||
public SpreaderTickSniperAnalyzer(HistoricalDataOptions hd_options){
|
||||
Console.WriteLine("Hit key to continue:"); Console.ReadKey();
|
||||
//SanityTest.run_tests();
|
||||
SanityTest.run_tests();
|
||||
string[] args = hd_options.algo_params.Split(',');
|
||||
Log.assert(args.Count()==2||args.Count()==3);
|
||||
DateTime dt;
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace bts.history
|
||||
static ManualResetEvent _quit = new ManualResetEvent(false);
|
||||
public static int Run(HistoricalDataOptions o)
|
||||
{
|
||||
Console.WriteLine(o.ToString());
|
||||
Console.WriteLine(o.ToString());
|
||||
if ("sniper".Equals (o.algo_type))
|
||||
{
|
||||
Console.WriteLine("Analyzing sniper");
|
||||
@@ -118,7 +118,13 @@ namespace bts.history
|
||||
sa.analyze();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ("microscope".Equals (o.algo_type))
|
||||
{
|
||||
Console.WriteLine("Starting miscroscope");
|
||||
Microscope m = new Microscope(o);
|
||||
m.analyze();
|
||||
return 0;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(o.replayend) && !string.IsNullOrEmpty(o.replaystart) &&
|
||||
!string.IsNullOrEmpty(o.replaysymbol) )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user