I have two datasets for buy and sell orders on a trading platform which look like this:
buy[45:50,]
NO SECCODE BUYSELL TIME ORDERNO ACTION PRICE VOLUME TRADENO TRADEPRICE
45 7880 SU25077RMFS7 B 1e+08 7880 1 98.4001 250 NA NA
46 7976 SU24018RMFS2 B 1e+08 7976 1 101.9989 4 NA NA
47 8314 SU52001RMFS3 B 1e+08 8314 1 94.6000 200 NA NA
48 8607 SU29009RMFS6 B 1e+08 8607 1 101.4000 22 NA NA
49 8735 SU29009RMFS6 B 1e+08 8735 1 101.4000 2 NA NA
50 8915 SU26206RMFS1 B 1e+08 8915 1 91.0002 225 NA NA
and
sell[45:50,]
NO SECCODE BUYSELL TIME ORDERNO ACTION PRICE VOLUME TRADENO TRADEPRICE
45 18767 SU26215RMFS2 S 100004130 13929 1 77.7410 6 NA NA
46 18831 SU26205RMFS3 S 100004156 13959 1 84.4680 3 NA NA
47 30345 SU26211RMFS1 S 100009446 19505 1 82.1999 7 NA NA
48 48387 SU24018RMFS2 S 100015879 3865 2 101.9989 4 2516559570 101.9989
49 54854 SU26212RMFS9 S 100019214 8920 0 77.2499 58 NA NA
50 55493 SU26212RMFS9 S 100019734 31671 1 74.6999 58 NA NA
I need to find all matches in PRICE by comparing all rows in "buy" with all rows in "sell". For example, the PRICE in the row 46 i the first dataset coincides with the PRICE in the row 48 in the second one. The expected output is the dataframe combining the corresponding rows into single row, i.e., making one row out of row 46 from the first dataset and row 48 from the second one (to be honest, it doesn't even matter to me how the output will look like, I just need to find the TIME and PRICE for the corresponding orders).
I've tried something like
d <- data[data$PRICE %in% intersect (sell$PRICE, buy$PRICE),]
where data
includes both "buy" and "sell" orders, but it doesn't work. As I understand, match
and find.matches
compare only the corresponding rows, but I need to compare all rows from "buy" with all rows from "sell".
My apologies if someone already asked something like this, but I couldn't find a similar question.