Calculating FX total returns in Python

Calculating FX total returns in Python

If you want a train, you have to build a train track. It doesn't matter, if it's a steam train or bullet train, or any other train. It's a prerequisite. No track kind of implies the train can't run. Obviously, each train needs a different type of track, but ultimately the principle is the same in how the track works (admittedly, if it's a maglev train then perhaps not).

When it comes to developing trading strategies in financial markets, there are many to choose from, whether it's trend, stat-arb, carry, value, high frequency and so on. The key similarity is that in all of these, we are trying to optimize the trades we do in some way to generate P&L. Ok, that's not exactly rocket science. But before we even begin to understand the P&L of a trading strategy, we need to understand the total returns. The total returns are another way of saying, if we were to buy an asset and hold it what would our P&L be? It's our train track, and our trading strategy is the train being driven along that track! Once we have that, we can use this time series, to understand the P&L of a more active trading strategy. There are of course also factors we need to account for to, to generate a realistic P&L, such as transaction costs (especially important for higher frequency strategies and when we trade more illiquid assets).

Unfortunately, the P&L is usually not simply a matter of looking at changes in the spot price. If we look at the total returns of an FX spot position, we also need to take into account the carry, the rate differential between the base and terms currency. If we try to backtest an FX carry basket, but just use the spot return (and not the total returns), our simulated P&L will be totally unrealistic. If a backtest is totally unrealistic, and we try running it with real cash, we will likely face an unpleasant surprise.

As we start looking at more complicated products, such as FX forwards we need to be able to reprice the contract every day...

To read the rest of the article on the Cuemacro website, please click here!

Is it also possible to backtest Crypto within finmarketpy?

Like
Reply

It's a real hassle to calculate total returns for FX (and indeed many other asset classes) and it's something that ends up getting replicated in fund after fund.. so thought it was worth open sourcing some Python code to do the job for FX spot, forwards + options! I'm also looking to add more total returns for other assets, if I can get some help with it.

Like
Reply

To view or add a comment, sign in

More articles by Saeed Amen

  • Neudata London March 2026

    A decade ago, I liked burgers, and a decade on, well, I still like burgers. However, one thing that has changed greatly…

    4 Comments
  • It's five to eleven

    Whenever I travel somewhere, I like to read books about the place I'm visiting. It helps in way to provide some context…

    3 Comments
  • TradeTech FX USA 2026

    Over recent years, the finance community in Miami has grown, given that a number of hedge funds have opened up large…

    1 Comment
  • AI coding is like making a burger with sugar

    Have you ever had a burger, and then noticed something is kind of off. You’re hunting for the reason.

    3 Comments
  • Hundreds of quant papers from #QuantLinkADay in 2025

    I tweet a lot (from @saeedamenfx and at BlueSky at @saeedamenfx.bsky.

  • QuantMinds London 2025

    "Are you on mute?" is perhaps the most succinct catchphrase which most comprehensively describes the post-covid…

    5 Comments
  • What would you have said?

    I recently went back to Imperial College. Whilst, I've been back many times since I graduated, this was the first time…

    8 Comments
  • Quant Strats London 2025

    Quant Strats has been a feature of the quant calendar for a number of years. I went to my first event recently after a…

    2 Comments
  • WBS Training Palermo Conference 2025

    Italy is made up of twenty regions, each of which is very different from another, from Veneto to Lazio to Puglia. Two…

    1 Comment
  • Gelato and accurate financial data

    I've been subscribing to the FT for many years. Primarily, I read it to keep track of financial markets.

    1 Comment

Others also viewed

Explore content categories