Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trouble with 500 securities limit

Is there anything we have to activate to increase the security limit to 500? When I try to run the code below (S&P 500), I get the error "SyntaxError: more than 255 arguments."

def initialize(context):  
    context.stock = symbols('A','AA','AAL','AAP','AAPL','ABBV','ABC','ABT','ACE','ACN','ADBE','ADI','ADM','ADP','ADS','ADSK','ADT','AEE','AEP','AES','AET','AFL','AGN','AIG','AIV','AIZ','AKAM','ALL','ALLE','ALTR','ALXN','AMAT','AME','AMG','AMGN','AMP','AMT','AMZN','AN','ANTM','AON','APA','APC','APD','APH','ARG','AVB','AVGO','AVY','AXP','AZO','BA','BAC','BAX','BBBY','BBT','BBY','BCR','BDX','BEN','BF_B','BHI','BIIB','BK','BLK','BLL','BMY','BRCM','BRK_B','BSX','BWA','BXP','C','CA','CAG','CAH','CAM','CAT','CB','CBG','CBS','CCE','CCI','CCL','CELG','CERN','CF','CHK','CHRW','CI','CINF','CL','CLX','CMA','CMCS_A','CME','CMG','CMI','CMS','CNP','CNX','COF','COG','COH','COL','COP','COST','CPB','CRM','CSC','CSCO','CSX','CTAS','CTL','CTSH','CTXS','CVC','CVS','CVX','D','DAL','DD','DE','DFS','DG','DGX','DHI','DHR','DIS','DISC_A','DISC_K','DLPH','DLTR','DNB','DO','DOV','DOW','DPS','DRI','DTE','DUK','DVA','DVN','EA','EBAY','ECL','ED','EFX','EIX','EL','EMC','EMN','EMR','ENDP','EOG','EQIX','EQR','EQT','ES','ESRX','ESS','ESV','ETFC','ETN','ETR','EW','EXC','EXPD','EXPE','F','FAST','FB','FCX','FDX','FE','FFIV','FIS','FISV','FITB','FLIR','FLR','FLS','FMC','FOSL','FOXA','FSLR','FTI','FTR','GAS','GD','GE','GGP','GILD','GIS','GLW','GM','GMCR','GME','GNW','GOOG_L','GPC','GPS','GRMN','GS','GT','GWW','HAL','HAR','HAS','HBAN','HBI','HCA','HCBK','HCN','HCP','HD','HES','HIG','HOG','HON','HOT','HP','HPQ','HRB','HRL','HRS','HSIC','HSP','HST','HSY','HUM','IBM','ICE','IFF','INTC','INTU','IP','IPG','IR','IRM','ISRG','ITW','IVZ','JBHT','JCI','JEC','JNJ','JNPR','JOY','JPM','JWN','K','KEY','KHC','KIM','KLAC','KMB','KMI','KMX','KO','KORS','KR','KSS','KSU','L','LB','LEG','LEN','LH','LLL','LLTC','LLY','LM','LMT','LNC','LOW','LRCX','LUK','LUV','LVLT','LYB','M','MA','MAC','MAR','MAS','MAT','MCD','MCHP','MCK','MCO','MDLZ','MDT','MET','MHFI','MHK','MJN','MKC','MLM','MMC','MMM','MNK','MNST','MO','MON','MOS','MPC','MRK','MRO','MS','MSFT','MSI','MTB','MU','MUR','MYL','NAVI','NBL','NDAQ','NEE','NEM','NFLX','NFX','NI','NKE','NLSN','NOC','NOV','NRG','NSC','NTAP','NTRS','NUE','NVDA','NWL','NWSA','O','OI','OKE','OMC','ORCL','ORLY','OXY','PAYX','PBCT','PBI','PCAR','PCG','PCL','PCLN','PCP','PDCO','PEG','PEP','PFE','PFG','PG','PGR','PH','PHM','PKI','PLD','PLL','PM','PNC','PNR','PNW','POM','PPG','PPL','PRGO','PRU','PSA','PSX','PVH','PWR','PX','PXD','PYPL','QCOM','QRVO','R','RAI','RCL','REGN','RF','RHI','RHT','RIG','RL','ROK','ROP','ROST','RRC','RSG','RTN','SBUX','SCG','SCHW','SE','SEE','SHW','SIAL','SIG','SJM','SLB','SLG','SNA','SNDK','SNI','SO','SPG','SPLS','SRCL','SRE','STI','STJ','STT','STX','STZ','SWK','SWKS','SWN','SYK','SYMC','SYY','T','TAP','TDC','TE','TEL','TGNA','TGT','THC','TIF','TJX','TMK','TMO','TRIP','TROW','TRV','TSCO','TSN','TSO','TSS','TWC','TWX','TXN','TXT','TYC','UA','UHS','UNH','UNM','UNP','UPS','URBN','URI','USB','UTX','V','VAR','VFC','VIAB','VLO','VMC','VNO','VRSN','VRTX','VTR','VZ','WAT','WBA','WDC','WEC','WFC','WFM','WHR','WM','WMB','WMT','WRK','WU','WY','WYN','WYNN','XEC','XEL','XL','XLNX','XOM','XRAY','XRX','XYL','YHOO','YUM','ZBH','ZION','ZTS')

def handle_data(context, data):  
    pass  
2 responses

Joe, I suspect that SyntaxError is being caused by passing more than 255 arguments to the symbols() function.

I would recommend against hard coding your stock universe to be honest. You run the risk of introducing look ahead bias. For example, you're including SIG which was added to the index this past month and therefore excluding (potentially) underperforming former members.

An alternative approach has been explored in threads like this one: https://www.quantopian.com/posts/simulating-s-and-p-500-russel-1000-russell-3000-in-research

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.

The symbols() call can be split into two calls, each with less than 255 arguments, and the results can be concatenated into a single variable