def does_cross_return(hdf): ccy = hdf.attrs['ccy'] ccy2 = hdf.attrs['ccy2'] cross_returns = [] bids = hdf['bid'][:] offers = hdf['offer'][:] bid_vol = hdf['bid_vol'][:] offer_vol = hdf['offer_vol'][:] min_vol = np.min([bid_vol, offer_vol], 0) t = hdf['t'][:] n = len(t) result = [] for cross in cross_info.find_crossed_markets_in_hdf(hdf): if cross.amt if cross.dur >= MIN_DUR: i = cross.end_idx end_bid = bids[i] end_offer = offers[i] future_idx = bisect.bisect_right(t, t[i] + FUTURE_HORIZON, i, n) future_vol_ok = min_vol[i:future_idx] >= cross.min_vol future_bid_ok = bids[i:future_idx] >= cross.bid future_offer_ok = offers[i:future_idx] >= cross.offer # CAVEAT: I'm assuming that if the cross stuck around for less than 50ms # we might have missed both sides if cross.dur > 50 and end_bid != cross.bid and end_offer == cross.offer: # bid uncrossed first returns = np.sum(future_bid_ok & future_vol_ok) # offer uncrossed first elif cross.dur > 50 and end_bid == cross.bid and end_offer != cross.offer: returns = np.sum(future_offer_ok & future_vol_ok) # both bid and offer changed else: # either the cross was shorter than 50ms or both prices changed # at the end returns = np.sum(future_bid_ok & future_offer_ok & future_vol_ok) print cross, "returns", returns, "times in", FUTURE_HORIZON / 1000.0, "seconds" result.append(returns > 0) return ccy, result def combine(all_amts, (ccy,amts)): all_amts.setdefault(ccy, []).extend(amts)
def cross_amounts(hdf): ccy = hdf.attrs['ccy'] amts = [cross.amt * cross.min_vol \ for cross in cross_info.find_crossed_markets_in_hdf(hdf) if MIN_DUR is None or cross.dur >= MIN_DUR] return ccy, amts
def cross_durations(hdf): ccy = hdf.attrs['ccy'] durs = [cross.dur for cross in cross_info.find_crossed_markets_in_hdf(hdf)] return ccy, durs
def cross_amounts(hdf): ccy = hdf.attrs['ccy'] amts = [cross.amt * cross.min_vol \ for cross in cross_info.find_crossed_markets_in_hdf(hdf) if MIN_DUR is None or cross.dur >= MIN_DUR] return ccy, amts