Back to Community
using a specific list of securities in pipeline

Hi,
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

    discount=Discount()  
    pipe.add(discount, 'disc')  
    set_symbol_lookup_date('2016-07-24')  
    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.
Thanks

5 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
37
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
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.

Thanks

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'))