def test_compare_order_metrics(self): sim_root = self.config.sim_root + self.sim_st.date().isoformat( ) + "/" + self.sim_st.time().isoformat() + "/" all_sims = DataLoader().load_sim_data(sim_root) all_sim_limit_orders = list( map(lambda sim: DataSplitter.get_limit_orders(sim[0].compute()), all_sims)) all_sim_market_orders = list( map(lambda sim: DataSplitter.get_market_orders(sim[0].compute()), all_sims)) all_sim_trades = list(map(lambda sim: sim[1].compute(), all_sims)) all_sim_cancels = list(map(lambda sim: sim[2].compute(), all_sims)) feed_df = DataLoader().load_feed( self.config.real_root, self.sim_st, self.sim_st + timedelta(seconds=self.config.simulation_window), self.config.product) real_orders = DataSplitter.get_orders(feed_df) real_limit_orders = DataSplitter.get_limit_orders(real_orders) real_market_orders = DataSplitter.get_market_orders(real_orders) real_trades = DataSplitter.get_trades(feed_df) real_trades['size'] = pd.to_numeric(real_trades['remaining_size']) real_cancels = DataSplitter.get_cancellations(feed_df) real_cancels['size'] = pd.to_numeric(real_cancels['remaining_size']) print("Order Buy/Sell limit metrics") Evaluation.compare_order_metrics(real_limit_orders, all_sim_limit_orders) print("Order Buy/Sell market metrics") Evaluation.compare_order_metrics(real_market_orders, all_sim_market_orders) print("Cancel metrics") Evaluation.compare_order_metrics(real_cancels, all_sim_cancels) print("Trade metrics") Evaluation.compare_metrics(real_trades, all_sim_trades)
def test_get_orders_per_minute(self): product = "LTC-USD" root = "/Users/jamesprince/project-data/data/consolidated-feed/" st = datetime.datetime(2018, 5, 17, 0, 0, 0) et = datetime.datetime(2018, 5, 17, 23, 59, 59) feed_df = DataLoader.load_feed(root + product + "/", st, et, product) orders = DataSplitter.get_orders(feed_df) limit_orders = DataSplitter.get_limit_orders(orders) print( str(len(limit_orders)) + " total limit orders per day for " + product) print( str(len(limit_orders) / (24 * 60)) + " limit orders per minute (on average) for " + product)
def test_orders_per_minute_windowed(self): product = "LTC-USD" root = "/Users/jamesprince/project-data/data/consolidated-feed/" st = datetime.datetime(2018, 5, 17, 0, 0, 0) et = datetime.datetime(2018, 5, 17, 23, 59, 59) feed_df = DataLoader.load_feed(root + product + "/", st, et, product) orders = DataSplitter.get_orders(feed_df) limit_orders = DataSplitter.get_limit_orders(orders) market_orders = DataSplitter.get_market_orders(orders) trades = DataSplitter.get_trades(feed_df) cancels = DataSplitter.get_cancellations(feed_df) print("Total limit orders: " + str(len(limit_orders))) print("Total market orders: " + str(len(market_orders))) print("Total trades: " + str(len(trades))) print("Total cancels: " + str(len(cancels))) # total_vol = trades['remaining_size'].sum() # print("Total traded volume: " + str(total_vol)) window_minutes = 60 step_minutes = 5 times = [] num_limit_orders = [] num_market_orders = [] num_trades = [] num_cancels = [] traded_vols = [] for i in range(0, int((24 * 60) / step_minutes - 1)): window_st = st + datetime.timedelta(seconds=i * step_minutes * 60) window_et = window_st + datetime.timedelta(seconds=window_minutes * 60) limit_orders_this_window = DataSplitter.get_between( limit_orders, window_st, window_et) market_orders_this_window = DataSplitter.get_between( market_orders, window_st, window_et) trades_this_window = DataSplitter.get_between( trades, window_st, window_et) cancels_this_window = DataSplitter.get_between( cancels, window_st, window_et) times.append(window_st) num_limit_orders.append(len(limit_orders_this_window)) num_market_orders.append(len(market_orders_this_window)) num_trades.append(len(trades_this_window)) num_cancels.append(len(cancels_this_window)) # vol_this_window = trades_this_window['remaining_size'].sum() # traded_vols.append(vol_this_window) Statistics.plot_metric_daily_comparison(times, num_limit_orders, num_cancels, "LTC-USD", st, step_minutes, window_minutes, "Limit Orders", "Cancels") Statistics.plot_metric_daily(times, num_limit_orders, "LTC-USD", st, step_minutes, window_minutes, "Limit Orders") Statistics.plot_metric_daily(times, num_market_orders, "LTC-USD", st, step_minutes, window_minutes, "Market Orders") Statistics.plot_metric_daily(times, num_trades, "LTC-USD", st, step_minutes, window_minutes, "Trades") Statistics.plot_metric_daily(times, num_cancels, "LTC-USD", st, step_minutes, window_minutes, "Cancels") Statistics.plot_metric_daily(times, traded_vols, "LTC-USD", st, step_minutes, window_minutes, "Traded Volume")