def get_feed_stats(df: dd) -> Dict[str, Union[int, Any]]: """Calculate and print some statistics relating to the data feed""" stats = { 'num_total_msgs': get_total(df), 'num_trades': Statistics.get_reason_count('filled', df), 'num_cancel': Statistics.get_reason_count('canceled', df), 'num_received': Statistics.get_type_count('received', df), 'num_open': Statistics.get_type_count('open', df), 'num_done': Statistics.get_type_count('done', df), 'num_match': Statistics.get_type_count('match', df), 'num_change': Statistics.get_type_count('change', df), 'avg_trade_price': Statistics.get_mean('price', DataSplitter.get_trades(df)), 'std_dev_trade_price': Statistics.get_std_dev('price', DataSplitter.get_trades(df)) } return stats
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 __fetch_real_prices(self): df = DataLoader().load_feed(self.config.real_root, self.sim_st, self.sim_st + timedelta(seconds=self.config.simulation_window), self.config.product) trades_df = DataSplitter.get_trades(df) trades_df['time'] = DataUtils().get_times_in_seconds_after_start(trades_df['time']) trades_df['price'].iloc[0] = DataUtils().get_first_non_nan(trades_df['price']) return trades_df[['time', 'price']]
def load_split_data(real_root, start_time, end_time, product): feed_df = DataLoader().load_feed(real_root, start_time, end_time, product) feed_df = DataSplitter.get_product(product, feed_df) orders_df = DataSplitter.get_orders(feed_df) trades_df = DataSplitter.get_trades(feed_df) cancels_df = DataSplitter.get_cancellations(feed_df) return orders_df, trades_df, cancels_df
def graph_order_cancel_relative_price_distribution(self, feed_df): trades_df = DataSplitter.get_trades(feed_df) cancels_df = DataSplitter.get_cancellations(feed_df) self.graph_relative_price_distribution(trades_df, cancels_df)
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")