Back to Community
Error: Arguments must be strings.

I wrote a function that takes stock symbols as strings and returns a dataframe, but I get an error that says Arguments must be strings. The information (symbols_arr) I'm passing through this function are Strings, but I still get the same error. The function is called get_RC()

from quantopian.algorithm import attach_pipeline, pipeline_output
import quantopian.algorithm as algo
from quantopian.research import prices, symbols, returns
import quantopian.optimize as opt
from quantopian.pipeline import Pipeline
from quantopian.algorithm import run_pipeline

...........................

def get_RC(x):
STOCK = x
start_date = date.today() + datetime.timedelta(-16)
start_date = start_date.strftime('%Y-%m-%d')
end_date = date.today() + datetime.timedelta(-1)
end_date = end_date.strftime('%Y-%m-%d')

    STOCK_dates = prices(  
        assets=symbols(STOCK),  
        start=start_date,  
        end=end_date,  
        frequency='daily')

    STOCK_dates = pd.DataFrame([STOCK_dates])  
    STOCK_dates = STOCK_dates.transpose()

    trading_days_arr = STOCK_dates.index.strftime('%Y-%m-%d')  

.............

for i in range(0, len(symbols_arr)):
data = get_RC(symbols_arr[i])
if data['5-day RCA'][-1] > data['10-day RCA'][-1] and data['5-day RCA'][-2] < data['10-day RCA'][-2]:
tradables.append(data)
tradables_symbols.append(symbols_arr[i])

3 responses

Could you attach the notebook which is causing the error? Use the dropdown menu in the upper right corner of the reply box. This makes troubleshooting much easier. In this case I wasn't able to re-create the error using just the code as pasted above.

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.

Hey Dan, thanks for the reply. The function works perfectly in my notebook, but when run in the algo it malfunctions. Attached is the algo copied into a notebook. Thank you so much for your help.

Loading notebook preview...
Notebook previews are currently unavailable.

The symbols method in research is a bit more flexible than the symbols method in the IDE. In the IDE one cannot pass a variable to the symbols method. Therefore, a statement such as the following is invalid in the IDE

stock_symbol = 'IBM'  
stock_prices = prices(  
            assets=symbols(stock_symbol),  
            start=start_date,  
            end=end_date,  
            frequency='daily')

The symbols method must be called like this

symbols('IBM')

The typical approach is to not work with the stock symbols as strings but rather work with the associated equity objects. That get's around the need to ever use the symbols method. The only reason one ever uses this method is to start with a stock symbol and find the associated equity object. The equity objects are the index of the outputted pipeline dataframe. There is no need find them. There is also no need to convert them to strings, save them, and then use the symbols method to convert those strings back to equity objects. Simply store the equity objects and use them. All the Quantopian methods really prefer to use equity objects so generally there is no need to ever store or manipulate the associated stock symbol.

Hope that helps.