Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Get fundamental data for existing positions?

What's the best way to get the fundamental data for my context.portfolio.positions?
I may wish to use this as a sell signal.
In before_trading_start, I do this:
context.pe_ratios = get_fundamentals(query(fundamentals.valuation_ratios.pe_ratio))
But it's throwing up KeyErrors.

6 responses

Thanks Mr. Loeber.

It is possible to retrieve fundamentals for one or several sids.

What you'll want is a .filter(fundamentals.valuation.sid==mySid). So all in all, it should look like:

context.pe_ratios = get_fundamentals(query(fundamentals.valuation_ratios.pe_ratio).filter(fundamentals.valuation.sid==mySid))

Maybe

from datetime import timedelta

context.pe_ratios = get_fundamentals(query(fundamentals.valuation_ratios.pe_ratio).filter(fundamentals.valuation.sid.in_([position.sid for position in context.portfolio.positions if position.amount > 0])),get_datetime().date() - timedelta(days=1))

Mr. Loeber,

Thanks for your advice and collaboration here:

I attended The University of Chicago intermittently between 2005 when I matriculated and 2009 when I graduated.

Where are you based?

Feel free to email me

Whoa is fundamentals in algos with point-in-time dates released now? Did I miss the memo?

SImon: terribly sorry, it isn't. You can retrieve fundamentals with point-in-time dates on research (which is where I primarily work), but not on algos (the fundamentals are automatically retrieved for the current day of trading). I actually forgot that this was the case. I've amended my answer above appropriately.

However, I expect this feature to arrive in the future.