I tweaked Quandl's Python API to just build the query url so it could be passed into the fetcher. It should work with any dataset they have. You will still need to make your own pre/post functions to adjust any of the formatting.
Enjoy!
I tweaked Quandl's Python API to just build the query url so it could be passed into the fetcher. It should work with any dataset they have. You will still need to make your own pre/post functions to adjust any of the formatting.
Enjoy!
Great stuff but does this protect against look ahead bias? (Looking up data in a back test for a given back test data before they are publicly available.)
That is a good question. Quandl data is time series data, the fetcher will treat it as a DataFrame source and only make the bars <= the current bar available to tests so the issue would be the integrity of the original data coming from Quandl and not so much the backtest itself. I would use the pre_func and post_func with the fetcher to make sure the data has the correct index. My understanding is that Quandl only aggregates data from other sources and doesn't alter it so the time series data should be dependable.
I would check out their API for details.
David, thanks for sharing! This looks great.
For anyone who is curious: there is indeed potential to introduce look ahead bias in your algo. If you're fetching daily data while running an algo in minute mode, then the the daily data row will be fetched at the beginning of the day, instead of the end of day. To guard against the bias, you need to use the post_func function.
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.
That is true, Quandl data is usually daily at best, an earnings report will have the same timestamp regardless of if it was released before or after trading hours. If anybody knows a data source with times and dates for things like earnings reports I would like to try integrating it to be used with Quandl data. It would have to be free and preferably a site with an export feature so the data doesn't need to be scraped from HTML.
Perhaps Quandl can add this data to their DB. This will be more convenient than getting it from some other place.
Does anyone have an example of a post_func function to adjust fetcher data by one day, to correct for the lookahead bias?
Hi Richard,
I think you can do something like this as a post_func:
def time_lag(df):
# using pandas' tshift to lag the index by 1 business day
df = df.tshift(1, freq='b')
return df
Let me know if that is too simple for your use case though. --Jess
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.
Hi, David
I want to call several Chinese stocks from Quandl using my strategy in the Backtest. Can you combine your post with my strategy to allow me to download multiple Chinese stocks and test the performance? Thanks!
The stocks I want to fetch into the algo are :
000023.SZ
000020.SZ
000019.SZ
000018.SZ
000014.SZ
000011.SZ
000010.SZ
000008.SZ
All these stocks have data set in Quandl. Thanks!
line 80 = QuandlRequest() <---- is this the line where we insert our api authentication key...?? in the enclose bracket?? if no where do we insert in your sample.
@QIFENG WU
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
There was a runtime error on line 49.