def get_daily_close(self): grouped_trade_price_last = self.matched_orders[["DateTime", self.active_fill_price_col]].groupby( pd.Grouper(key="DateTime", freq='B' ), sort=False ).last() grouped_trade_price_last["DateTime"] = grouped_trade_price_last.index grouped_trade_price_last.reset_index(drop=True, inplace = True) grouped_trade_price_last.rename(columns={self.active_fill_price_col: "price"}, inplace = True) return timemethods.date_time_to_sim_time(grouped_trade_price_last)
def get_relative_trade_price_range(self, timewindow): grouped_trade_price = self.matched_orders[["DateTime", self.active_fill_price_col]].groupby( pd.Grouper(key="DateTime", freq=timewindow)) grouped_trade_price_max = grouped_trade_price.max() grouped_trade_price_min = grouped_trade_price.min() rel_range = (grouped_trade_price_max - grouped_trade_price_min) / grouped_trade_price_min rel_range["DateTime"] = rel_range.index rel_range.reset_index(drop=True, inplace = True) rel_range.rename(columns={self.active_fill_price_col: "rel_range"}, inplace = True) return timemethods.date_time_to_sim_time(rel_range)
def _get_resampled_data_by_active_agent_name(self, agent_name, col_name,sample_freq): unsampled_data = self.get_active_agent_data(agent_name) unsampled_data = unsampled_data[["DateTime", col_name]] #select the col we are interested in unsampled_data = unsampled_data.groupby(["DateTime"]).agg({"DateTime" : "last",col_name:"sum"}) # sum any duplicates resampled_data = unsampled_data.groupby(pd.Grouper(key="DateTime", freq='B' ), sort=False ).resample(sample_freq ,on = "DateTime",).sum().reset_index(level = 0, drop= True) resampled_data["DateTime"] = resampled_data.index resampled_data = resampled_data.rename(columns={col_name: agent_name}) return timemethods.date_time_to_sim_time(resampled_data)
def get_last_traded_price(self, timewindow): grouped_trade_price_last = self.matched_orders[["DateTime", self.active_fill_price_col]].groupby( pd.Grouper(key="DateTime", freq='B' ), sort = False ).resample(timewindow, on = "DateTime" ).last().reset_index(level=0, drop = True) grouped_trade_price_last["DateTime"] = grouped_trade_price_last.index grouped_trade_price_last.reset_index(drop=True, inplace = True) grouped_trade_price_last.rename(columns={self.active_fill_price_col: "price"}, inplace = True) return timemethods.date_time_to_sim_time(grouped_trade_price_last)
def get_volume_to_side_by_agent(matched_orders, agent_name, side,sample_freq = "1T"): vol_to_side = matched_orders[(matched_orders["active_agent"].str.contains(agent_name)) & (matched_orders[" active_side"] == side)][ ["DateTime", " passive_fillQty"]].groupby(pd.Grouper(key="DateTime",freq = 'B')).resample(sample_freq,on = "DateTime",).sum().reset_index(level=0, drop=True) vol_to_side["DateTime"] = vol_to_side.index return timemethods.date_time_to_sim_time(vol_to_side)