How calculate triangular arbitrage opportunities

Triangular arbitrage strategies

Triangular Arbitrage is a risk-free trading strategy that aims to exploit discrepancies in exchange rates between three different currencies in the foreign exchange market. The strategy involves three trades, exchanging an initial currency for a second, the second currency for a third, and finally the third currency back to the initial. If the final amount is higher than the initial, a profit is made.

Here's a simplified step-by-step breakdown:

  1. Start with a currency: For instance, USD.
  2. Exchange it for a second currency: Convert USD to EUR.
  3. Exchange the second currency for a third: Convert EUR to GBP.
  4. Exchange the third currency back to the initial: Convert GBP back to USD.

If, after these transactions, you end up with more USD than you started with, you've successfully executed a triangular arbitrage. The discrepancies that make this possible often exist for only short periods, so speed and timing are crucial for execution.

The calculation for the arbitrage_value depends on the sequence of trades (BUY/SELL) for the currency pairs involved. The sequence determines how you move through the currencies in the triangular arbitrage loop.

Let’s break down the sequences for the pairs AUDUSD, NZDUSD, and AUDNZD:

Triangular arbitrage calculation

… and so on for other sequences.

The idea is to start with one unit of a currency (e.g., 1 USD) and see how much of that same currency you end up with after completing the triangular arbitrage loop. If you end up with more than you started with (after accounting for transaction costs), there’s a potential arbitrage opportunity.

To implement this in code, you’d need to adjust the triangular_arbitrage_value function to account for the different sequences. You could add an additional parameter for the sequence or create separate functions for each sequence.

def triangular_arbitrage_value(pair1, buysell1, pair2, buysell2, pair3, buysell3):
    """
    Calculate the triangular arbitrage value based on the given pairs and their BUY/SELL sequences.

    Parameters:
    - pair1, pair2, pair3: Current prices of the currency pairs.
    - buysell1, buysell2, buysell3: 'BUY' or 'SELL' sequences for the respective pairs.

    Returns:
    - Arbitrage value
    """
    
    # Initialize the starting value
    value = 1.0
    
    # Process the first pair
    if buysell1 == 'BUY':
        value /= pair1
    elif buysell1 == 'SELL':
        value *= pair1

    # Process the second pair
    if buysell2 == 'BUY':
        value /= pair2
    elif buysell2 == 'SELL':
        value *= pair2

    # Process the third pair
    if buysell3 == 'BUY':
        value /= pair3
    elif buysell3 == 'SELL':
        value *= pair3

    return value

# Example usage:
pair1_price = 0.75  # Example price for AUDUSD
pair2_price = 1.07  # Example price for AUDNZD
pair3_price = 0.70  # Example price for NZDUSD

value = triangular_arbitrage_value(pair1_price, 'BUY', pair2_price, 'SELL', pair3_price, 'BUY')
print(f"Arbitrage Value: {value:.4f}")

# If the value is significantly greater than 1, there's a potential arbitrage opportunity.
if value > 1.01:  # 1.01 is used as a threshold to account for transaction costs and other fees.
    print("Potential arbitrage opportunity!")
else:
    print("No arbitrage opportunity.")

Leave a Reply

Your email address will not be published. Required fields are marked *