Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
data.fetcher_assets issue

Hi,
Im having an issue with the fetcher_assets
im importing a csv file that looks like this:

Date,symbol,Signal
07.01.2014,AIG,-1
07.02.2014,CBI,1
07.03.2014,FMCC,1

then if i run
fetch_csv('https://dl.dropboxusercontent.com/s....txt?dl=0', date_column = 'Date', date_format = '%m.%d.%Y', post_func=rename_col)

only the columns with the dates and the symbol are getting imported while the signal column isnt (i can see that because i have a preview command in rename_col and the ouput i get is:
sid
dt
2014-07-01 00:00:00+00:00 Equity(239 [AIG])
2014-07-02 00:00:00+00:00 Equity(1287 [CBI])
2014-07-09 00:00:00+00:00 Equity(239 [AIG])
2014-07-10 00:00:00+00:00 Equity(239 [AIG])
2014-07-11 00:00:00+00:00 Equity(239 [AIG])

)

then I have another issue using the fetcher_assets command. If I run:

def before_trading_start(context, data):
"""
Called every day before market open. This is where we get the securities
that made it through the pipeline.
"""
for i in range(0,len(data.fetcher_assets)):
log.info(data.fetcher_assets[i].asset_name)

not only the stocks that should be active on this day according to my list and according to the help file are being returned, but all the stocks that have been 'activated' so far. so this is the log i get:

2014-07-01 before_trading_start:51 INFO AIG
2014-07-02 before_trading_start:51 INFO CBI
2014-07-02 before_trading_start:51 INFO AIG
2014-07-03 before_trading_start:51 INFO CBI
2014-07-03 before_trading_start:51 INFO AIG

even though on the 07/02/2014 (for example) the only stock that should be returned is the CBI
could you give me some pointers?
thank you,
Dario

13 responses

same issue here. It seems that data.fetcher_assets keeps appending new stocks.

https://www.quantopian.com/posts/data-dot-fetcher-assets-doesnt-work

Hi Zhi,
I saw from your post that youre doing something really similar to me (and to the help we site).
Were you able to fully upload your table? Im unable to get all three columns (ie date, stock, and score) into Quantopian in one go, so now ive split my data into two tables: one with dates and stocks and one with dates and score. Then im calling fetch_csv twice, once for each table (which is ok for now but might get compliacated later, ie id like to do the whole thing in one fetch_csv).
Were you able to access your signal the way you imported it?
Thanks

Hi Dario,
The csv file is like this.
symbol start_date stock_score
AA 2/13/2012 0.876536739
WFM 2/13/2012 0.056418644
FDX 2/14/2012 0.976608748
M 2/15/2012 0.352700668
AAPL 2/16/2012 0.718324572

I am just doing a little experiment using example(with some changes) from quantopian (under fetcher)
https://www.quantopian.com/help

To access your signal, you can iterate through data.fetcher_assets and use data.current(asset,your_signal):

for asset in data.fetcher_assets:  
      if data.can_trade(asset):  
            order_target_percent(asset,data.current(asset,'score'))  

You will find even if there is no score for AA on 2/14, It will still be re-balanced based on its prior day's score. Currently I am trying to find a way to close the stock if there is no score shown on that day. I think the issue comes from data.fetcher_assets.

Hey Zhi,
ok i figured out what was wrong with my import (was importing the wrong file).
So i did (a very ugly, brute force, work-around the date issue) that works for me for now (unitl the quantopian support gets back to me about the fetcher_assets) which seems to work.

In case your'e interested what i did is created a list with two date columns, so it looks like this:
Date,symbol,Signal,Date1
07.01.2014,AIG,-1,7012014
07.02.2014,CBI,1,7022014
... I add a second date column so i can work with these dates directly, which i wasnt really able to do with the column i set to date_column + fetch_csv doesnt let me upload a file without a date column (as far as i can tell) it keeps giving me an error if I try to.

Then in my algorithm i brute force check if the current date matches with the date i extract from the Date1 column from the table (quite tedious and slow), if it does i then add this security to a list of securities i want to trade...
definitely not pretty and will definitely try to change the code soon, but at least i can check some things already.

Zhi,
so i talked to the quantopian support: it seems this is an issue with the fetcher_assets, ie its not working correctly.

Ouch.

Yeah that works! Another solution would be to keep the same stock universe for each day:

07.01.2014,AIG,-1
07.01.2014,CBI,-1
07.01.2014,FMCC,1
07.02.2014,AIG,-1
07.02.2014,CBI,1
07.02.2014,FMCC,1
07.03.2014,AIG,1
07.03.2014,CBI,-1
07.03.2014,FMCC,1

Then you can get correct score for symbols on simulation date.

for asset in data.fetcher_assets:  
    print data.current(asset,'Signal')  

Hi Zhi,
do you know if instead of using this double date column trick I am doing theres a way to access the trade dates directly?
Like for example data.current(data.fetcher_assets, 'tradeDate') or something?
thanks,
Dario

I don't know actually.. I think the date and symbol columns will become DataFrame index after fetch and will no longer be able to extract.

Hi folks - I ran into the same problem lately. Wondering if anyone found a more efficient way to solve this?

Thanks in advance

Hi Mark Cheng,
a lot of issues actually in quantopian unless they have been fixed lately. But long story short, no, still using the trick I explained above, its become sort of standard in all my simulations.

Many thanks Dario, agree with you.

I guess I also wasted a decent amount of time trying to find out what was wrong with my algo when there is a bug in the framework.

@quantopian: It would be a very nice addition to link accepted bugs (with a certain severity) automatically on the documentation. If you are using Github / Jira / etc. or your bug tickets, this should be quite simple to accomplish. That way we can better trust whether something works as intended or not. Having the docs not reflect a known severe bug for +7 months is a bit frustrating