Hold the currency with the higher interest rate against the one with the lower rate, and charge or credit the swap every night the position is open, with the weekend's three nights on the day your broker books them. Carry earns slowly and loses quickly when risk appetite turns, so a backtest needs the nightly swap, a realistic spread and a period that includes a carry unwind such as 2008.
How carry earns
A long AUD/JPY position borrows yen and holds Australian dollars. When Australian rates are higher, the account is credited the difference each night, less the broker's markup. That nightly swap is the strategy's income; the exchange rate is its risk.
- Income. Roughly the rate differential, accrued daily. A 4% gap on a position worth $100,000 is about $11 a night.
- Risk. High-yield currencies tend to fall sharply in sell-offs, as AUD/JPY did by over 40% in 2008. Years of swap can go in weeks.
What the backtest must get right
- Swap per night, by direction. Long and short get different rates, and with a markup both sides can pay. Use your broker's swap table, not the central bank rates.
- The triple night. FX settles two days forward, so the weekend's interest is booked on one weekday, usually Wednesday, at three times the normal rate.
- Rates change. Swap follows central bank rates. A carry backtest over years needs the swap history, or at least the rate differential by month.
- Spread. Exotic high-yield pairs carry wide spreads, which a carry trade pays on every rebalance.
How Reamer Research handles it
Reamer Research charges swap once each time the bars cross into a new date, from a rate per unit for each weekday, Sunday to Saturday, set per pair through ticker_config. A long position pays the rate and a short receives it, so a negative rate credits a long carry position. The night is keyed by the day the position is held over, so a Wednesday rate three times the others books the weekend there. This class holds long carry while a trend filter agrees:
import reamer_research as rr
class CarryWithTrend:
lookback = 100
units = 100_000 # one standard lot
def on_bar(self, d):
if d.close[0] == 0:
return None
uptrend = d.close[-1] > d.close.mean()
if d.position() == 0 and uptrend:
return rr.buy_market(self.units)
if d.position() > 0 and not uptrend:
return rr.close_position()
credit = -0.011 # yen per unit per night: about ¥1,100 a lot, long receives
AUDJPY = dict(swap_per_unit=[0, credit, credit, 3 * credit, credit, credit, 0],
spread=0.02)
result = rr.backtest(CarryWithTrend, {'AUDJPY': 'data/AUDJPY_daily.bin'},
ticker_config={'AUDJPY': AUDJPY},
initial_capital=2_000_000, leverage=20) # a yen account
print(f'net {result.net_pnl:.0f}, of which swap {-result.total_swap_cost:.0f}')
The list runs Sunday to Saturday. With bars only on weekdays, the Friday-to-Monday crossing is booked under Friday at the normal rate, and Wednesday's triple rate covers the weekend, as brokers book it. Prices, capital and swap here are in yen, so the account is a yen account; for another account currency, convert them, or take swap_per_unit from the broker's table in account terms. A 4% rate gap on one lot worth about ¥10 million is about ¥1,100 a night, the credit above. total_swap_cost is the run's total, negative when swap was earned. The rule works as an on_bar(data) function or as an object configured with the pair's rates.
For rates that change over time, run the history in pieces with start and end, one per rate regime, or carry the differential as exogenous data and size the position from it.
Limits to know
- One swap table per pair per run. Rate changes over a long history go in as separate runs or as exogenous data.
- A long pays exactly what a short receives. A broker's markup on both sides is set by giving each direction its own run, or by using the rate for the side you trade.
- Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to check a month of swap bookings; a basket of pairs over years needs a licence.
A $20 month includes the full kit, so you can test carry on your own FX data and swap tables and cancel if it does not fit.