Introduction
Recent market volatility has prompted hundreds of discussions into potential causes of the market dip. One theory was the unwinding of the Yen Carry Trade. In this “micro-study” we'll explore the yen carry trade and watch its unwinding on the latest month's data.
Micro-studies are a new, easily digestible, short-story format of quant research we'll be testing over the next 2 months looking to repeat market phenomena and potential strategies around them. Our goal is to implement a micro-study in less than 20 lines, showcasing the raw power of what you can do with QuantConnect.
Background
The currency trade borrows from a low interest rate currency (Yen) and invests it in a higher interest rate assets such as US Treasuries. US bonds offer a safe, low volatility investment so investors could apply significant leverage on the trade. This leverage is often described as a loan.
As the Yen was also slowly devaluing (e.g. 2023: 140 Yen/$1 USD → 2024: 160 Yen/USD), it was also becoming cheaper to repay the loans, making the trade more attractive. On paper, this made the position appear like a trending asset that was also paying 4% dividends.
For the first time in years, Japanese authorities decided to increase the interest rate from 0% to 0.25%. The theories were many funds decided to repay their loans and close out the trade, causing billions of dollars in Yen re-purchases and rapid strengthening the yen within a 2 week period.
Implementation
To implement this strategy on QuantConnect, we'll use the USDJPY FX pair and the BIL US T-Bill ETF.
- We used $1M USD collateral starting cash, and aimed to trade $80M in total holdings.
self.set_cash(1_000_000) # 1M usd = 141M Yen Jan 1 2024.
2. We added the assets and specified a very high leverage to model the large cash loans the funds will be taking on the investment. Both assets are a liquid and low volatility so would likely be permitted significant buying power. Raw data normalization mode was used so yield payments were deposited as cash we could use to service the loan.
self.add_equity("BIL", Resolution.DAILY, leverage=100, data_normalization_mode=DataNormalizationMode.RAW)
self.add_forex("USDJPY", Resolution.DAILY, leverage=100)
3. To trade, we scheduled an event and set equal holdings of USDJPY (modeling our loan and purchase of Yen), and BIL - a liquid yield paying ETF that invests in US treasuries. QuantConnect models FX trading with a cashbook, so this trade would appear as +$40M USD and -Y5.6B Yen. An accompanying $40M position was opened on the ETF, BIL.
def trade(self):
if not self.portfolio.invested:
self.set_holdings("BIL", 40)
self.set_holdings("USDJPY", 40)
self._interest_payment = -40_000_000 * (0.0025/12) # USD
# deduct interest
self.portfolio.cash_book['USD'].add_amount(self._interest_payment)
To model the interest on the loan we used the 0.25% interest rate multiplied by the USD currency loan value. This modeled serving the loan repayments without growing the principle of the loan. No risk control was added to the strategy for illustrative purposes.
Conclusion
The Yen Carry Trade is a very simple, but highly leveraged strategy capitalizing on the disparity in interest rates and devaluation of the Yen. With a simple framework we could model the trade on the QuantConnect platform, and likely have executed the trade through partner brokerages. For the majority of 2024 it had a Sharpe ratio of 16. In the last 4 weeks it has experienced a 60% drawdown.
Significant improvements could be made to control risk such as pulling in our news feeds to monitor for central bank decisions, or adding a simple trailing stoploss.
James thomas
Hello. its nice simple illustration of the potential of the carry trade thanks for posting.
One small point - when i try this with other currency pairs e.g. USDEUR or USDAUD (simply by swapping the symbols) the code doesnt seem to work as the data needs warming up first. It's probably not too much to fix, but unclear why it works for USDJPY but not others.
USDEUR: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data.
Jared Broad
In OANDA the ticker is EURUSD not USDEUR, so you'd need to invert the direction as well (short vs long the fx).
One note about this demonstration - if your buying power comes with a high interest rate it may negate the interest earned from the trade. LEAN doesn't model the interest on the margin loan at the moment but we've added it to the todo so we can improve this demonstration.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Kevin Stoll
We had to build a small lookup table for the algos to consume for this purpose. Our broker lists their rates on the website, but doesn't expose them via API. We just monitor daily and update as needed. If there's a more elegant solution, I'm listening :D
Jared Broad
That's a good work around for now! We will make a default one anchored +1% from the US Treasury Rate - the issue for tracking it is here. We have it implemented for Binance but will take a day's work to make it apply generally.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jared Broad
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!