Back to Community
using a specific list of securities in pipeline

I want to use pipeline to rank securities by a custom factor but I want to limit the rank to a hand picked list of 27 securities.
When I run the code, I get "TypeError: unhashable type: 'list'." I understand that the list I'm using isn't formatted properly for the masking function to work but I don't know how to transform it.
Here is a sample of my code

    pipe.add(discount, 'disc')  
    loans = symbols('AFT', 'ARDC', 'ACP', 'BHL', 'FRA', 'BGT', 'BSL', 'BGX', 'BGB', 'EFT', 'EFF', 'EFR', 'EVF','ECC', 'FCT', 'VVR',  'VTA', 'JQC',    'JRO', 'JFR', 'NSL', 'JSD', 'OXLC', 'PHD', 'TSLF', 'PPR', 'TLI')  
    discount_rank = discount.rank(mask=loans)  
    pipe.add(discount_rank, 'disc_rank')  

The error stems from setting mask equal to a list of securities.
I'm new to python and I'd appreciate any help with this.

9 responses

The mask and the screen parameters expect a 'filter' object. There are some built in filters but unfortunately not one that returns a user defined list. You can, however, create a custom filter to do that. See the attached code.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 579649747932660ff7356c16
There was a runtime error.


Just noticed a built in filter that filters to a list of equities. Can be used for a single equity or a list of equities.

from quantopian.pipeline.filters import  StaticAssets

aapl = StaticAssets(symbols(['AAPL']))  
aapl_ibm = StaticAssets(symbols(['AAPL', 'IBM']))  

StaticAssets is not yet on the help page. I sent a message to Quantopian support requesting that it be added.

I can see it in the Help now. Note, the list of symbols is given as:

aapl_ibm = StaticAssets(symbols('AAPL', 'IBM'))  

Does anyone have an example of using a list of symbols that also incorporates pipeline and fundamentals, but done in the Research Environment?

@Michael Fortunato

Attached is an example of using a list of symbols with pipeline and fundamentals in a notebook. Is that what you were looking for?

Good luck.

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

Wow Dan...thanks for doing that! This is hugely appreciated. I'm a beginner with Python so you can probably imagine that Quantopian is a challenge for me. Best regards,

Glad to help. The forum community here is pretty responsive and there is a wide variety of experience. Post whenever you have a question or just looking for feedback.