Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Inconsistant use of StaticAssets between research and back test

I just noticed that there is a slight difference of using StaticAssets between research and back test. In research, if I define something like:
my_etfs = StaticAssets(symbols(['SPY'])) It works fine. When I copy the same to back test, it complains about the argument not being string type. If I remove the square bracket, then it works in back test but not in research.

Anyone in Q comment on this?

2 responses

I came across this tonight and found an answer in another thread: https://www.quantopian.com/posts/error-arguments-must-be-strings

The culprit here is an inconsistency in the symbols method when used in a notebook vs in the IDE environment. The StaticAssets filter works the same in both.

Below are links to the definitions in the two environments. The notebook (ie research environment) version expects a single argument symbols which can be either a string or an iterable of strings (ie a bracketed list). The algo (ie IDE environment) version expects multiple arguments which can only be strings and is defined in the method with the variable arguments definition *args.

https://www.quantopian.com/docs/api-reference/research-api-reference#quantopian.research.symbols
https://www.quantopian.com/docs/api-reference/algorithm-api-reference#quantopian.algorithm.symbols

So, what to do? I find the best approach is to use the StaticSids filter rather than StaticAssets(https://www.quantopian.com/docs/api-reference/pipeline-api-reference#quantopian.pipeline.filters.StaticSids) . This helps in two ways. First, the parameters are just integers and therefore the syntax is the same in all environments. The code below will work identically in the IDE and in notebooks. Whether you have one security or many, always put the integer SIDs in a list (ie in brackets).

# 8554 and 24 are the asset IDs for SPY and AAPL respectively  
spy_filter = StaticSids([8554])  
spy_and_aapl_filter = StaticSids([8554, 24]) 

Second, this approach is preferable because the SID will only ever refer to a single security. However, there are situations where a specific ticker symbol can refer to several securities over time (eg FOX has been used by three separate companies over the years). Using the SID ensures one is always referring to the same security and not inadvertently another one.

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.