Buy Currency Sell Currency Buy Amount Sell Amount
1. CHF USD 50000 61000
2. USD CHF 20999 20000
3. USD CHF 34000 30000
4. CHF AUD 400 356
5. AUD CHF 378 400
6. USD CHF 34000 30000
Hi, I am trying to solve a problem of matching FX trades. As seen above, the first line buy CHF 50000, can be reconciled by combining 2nd and 3rd, or 2nd and 6th trade. Trade 4 can be reconciled with trade 5. Hope you guys get the idea.
What I've worked out so far:
- try to take the unique currencies in buy column and check if they are present in sell column.
[i for i in df['Buy Currency'].unique() if i in df['Sell Currency'].unique()]
- check if Buy only has 1 type of currency. if true, continue to next loop.
assert len(set(df['Buy Currency'])) != 1
- check for exact match in Buy Amt and Sell Amt. In this case, 400 appears in both columns thus can be easily found.
[amt for amt in df['Buy Amount'].astype(int).tolist() if amt in df['Sell Amount'].astype(int).tolist()]
The part where I'm stuck is matching 1 buy trade with more than 1 sell trade. In addition, there can be more than 1 way of doing so, as illustrated in the first trade. Also tried using itertools.combinations
as seen in
Find all combinations of a list of numbers with a given sum, but I won't be able to verify if the combinations are same FX pairs.
Any help is greatly appreciated!