diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs index 827f02fdb..1c130986d 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/MarketQueries.cs @@ -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 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 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> on_book, @@ -191,6 +173,23 @@ namespace bts.history{ } } + // finds book updates bw (and including) msg seq no's + public static IEnumerable 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 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 } } \ No newline at end of file diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/Microscope.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/Microscope.cs new file mode 100644 index 000000000..c3b6b0a2e --- /dev/null +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/Microscope.cs @@ -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 * bw msg seq no's + // 2. book updates for * 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(){ + + } + + } +} \ No newline at end of file diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SanityTests.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SanityTests.cs index 2cd48a6c4..0a6df4a56 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SanityTests.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SanityTests.cs @@ -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>(); - 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>(); - 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); } } diff --git a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs index d2b778c6e..0d50bb860 100644 --- a/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs +++ b/src/client/sparkcmd/Cmd/Historical/StaticAnalysis/SpreaderTickSniperAnalyzer.cs @@ -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; diff --git a/src/client/sparkcmd/Cmd/HistoricalDataCommand.cs b/src/client/sparkcmd/Cmd/HistoricalDataCommand.cs index e660f6c22..3183f7168 100644 --- a/src/client/sparkcmd/Cmd/HistoricalDataCommand.cs +++ b/src/client/sparkcmd/Cmd/HistoricalDataCommand.cs @@ -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) ) {