Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Short-term treasury as an asset

I was wondering if there is a way to use short-term treasury (e.g. 1month or 3month) yield in algo.

For example, when I decrease the portfolio weight to zero (no investment in equities), the portfolio return becomes zero, which is equivalent to holding cash. Instead, I think it'd be cool if there is an option that I could invest in short-term US treasuries. To be more general, if I invest x(%) in equities, 100-x(%) is automatically invested in the treasuries.

One way is to use bond ETFs, and this is pretty straightforward because they are "price" data.
However, I'd like to know if there is a way to trade an asset using its "yield" data (such as in US treasury case).
If it is possible, I can trade any asset which has only return data not price data.

(ps) Is it possible to generate ETF-like data from US treasury rate data? I'm trying to find out the relationship, but it wasn't easy as I thought.

Best,

7 responses

Index data is available, but Quantopian does not make them available to us. I see no reason why. Please consider it a feature request.

A good way to do it would be to create a class named Index as a subclass of Asset, like Equity, that exposes price and volume data, but throws an error (with an informative error message, not just "Something went wrong") on attempts to place an order.

Absent that, a workaround for us is to use Fetcher to get index data from eg. Yahoo Finance.

Some Treasury yields are available as HTML, with the current level embedded as text:

Daily historical Treasury Bill Rates (4-week, 13-week, 26-week, and 52-week):

Thanks for your reply. My question was more related to how to incorporate yield data into algorithms.
(Data source is not one of my concerns actually.)

I thought that treasury yield is more like "return" rather than "price". Bond ETF index is more like "price", so it is easy to use.

This is why I thought it'd be hard to use plain U.S. treasury yield; because Quantopian algo will treat it as "price".. Maybe I completely misunderstood what the yield data represent.

The price of a stock or ETF, the level of an index, the yield of a bond, the temperature outside the office building at a coffee plantation, and an average interest rate on 15-year mortgages, are all floating-point numbers. There is no need for Quantopian infrastructure code to differentiate between them. As long as you get your data[security] bars, you should know what the real nature of data[security].price is (as well as that the security is the source of a stream of numbers in time, usually but not necessarily a security). You (as a financial analyst) should then know what to do with this, and (as a programmer) should be able to express it in code.

Maybe I misunderstood what you were trying to ask.

One way to use bond yield data would be to vary the target proportion of stocks vs. bonds in your portfolio with the yields: when bond yields increase, you should shift some of your stock positions to bonds, and vice versa. You could use one stock and one bond ETF, eg. SPY and TLT, or have several stocks and/or ETFs and several bond ETFs (you can't trade infividual bonds on Quantopian), with fixed proportions within each part, equal or not.