Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Adding treasury constant and bill

Hello,

I want to back test a strategy by comparing both "10 year treasury constant maturity rate" and "3 month treasury bill".
Anyone knows how get the values?

Thanks in advanced.

6 responses

Hi Karl Mun,

Thanks, but what i need to know is how to get the values at a specific time in Quantopian.
Any example commands?

Hi Karl. Yes, i am trying to feed the values into the Quantopian research algorithm to backtest a strategy.

I googled and managed to find some ideas on how to get the rate values.
Unfortunately, it doesn't give me the rate. All i get is "float64".

Can someone please assist?

from quantopian.pipeline.data.quandl import fred_dgs10

def initialize (context):  
    schedule_function(monthly, date_rules.month_start(), time_rules.market_open())

def monthly(context, data):  
    print(fred_dgs10.value)  

I've searched endlessly for the answer to this question -- anyone find anything on this yet?

The Federal Reserve (FRED) offers a plethora of financial data free of charge to download including the 10-Year Treasury Constant Maturity Rate and the 3-Month Treasury Bill: Secondary Market Rate. There is also a category on rate spreads which is interesting. This is the definitive source for all US monetary data.

So, how to use it on the Quantopian platform? There are several steps:

  • Find the data and download it to your local computer
  • Open the downloaded file and append a column filled with the text 'SPY' then save the file as a CSV.
  • Upload the file to Quantopian as a 'self serve' dataset
  • Import and use the uploaded dataset just like any other dataset

First, find the data you are interested in. Search or browse the FRED site and get to the specific data page. All the pages have about the same format with two text entry fields to enter the begin and end dates for the data to display and a chart showing the actual data. In the upper right corner there is a button titled DOWNLOAD. Once you have your dates selected, click that button. There are several formats to download the data. I usually choose CSV. The file will download locally onto your computer.

Next, open the file using your favorite spreadsheet app such as Excel, Numbers, or Google Sheets. The data will typically have just two columns. One is a date and the other is the associated data. You may want to rename the data column to be something more 'user friendly'. The default name is often a bit cryptic. Then, insert a new column. Title the column 'SYMBOL' and fill the entire column with the text 'SPY'. This is required to 'map' your data to a specific equity (in this case SPY). There's more on this in the documentation.

Once the file is in the proper format, upload it to Quantopian and it will become our own private dataset.

Finally, import the dataset into an algo or notebook to access the data via pipeline.

There are instructions on how to upload and import 'self serve' datasets in the documentation and also in this post.

Any custom data can be imported and used in Quantopian this way. It's easiest to not use the 'live' mode for self serve data. Stick to a fixed set of historical data. However, it is possible to configure a dataset which will constantly update but I'll save that for later.

Hope this helps.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.