-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add vectorized lookup_symbol. #1627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -827,6 +827,40 @@ def lookup_symbol(self, symbol, as_of_date, fuzzy=False): | |
return self._lookup_symbol_fuzzy(symbol, as_of_date) | ||
return self._lookup_symbol_strict(symbol, as_of_date) | ||
|
||
def lookup_symbols(self, symbols, as_of_date, fuzzy=False): | ||
""" | ||
Lookup a list of equities by symbol. | ||
|
||
Equivalent to:: | ||
|
||
[finder.lookup_symbol(s, as_of, fuzzy) for s in symbols] | ||
|
||
but potentially faster because repeated lookups are memoized. | ||
|
||
Parameters | ||
---------- | ||
symbols : sequence[str] | ||
Sequence of ticker symbols to resolve. | ||
as_of_date : pd.Timestamp | ||
Forwarded to ``lookup_symbol``. | ||
fuzzy : bool, optional | ||
Forwarded to ``lookup_symbol``. | ||
|
||
Returns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a note saying that it is the same as the list comprehension but better for performance. |
||
------- | ||
equities : list[Equity] | ||
""" | ||
memo = {} | ||
out = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this just be a generator? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you asking if the internal implementation should be a generator, or if the top-level interface should be a generator? I'm indifferent toward the former. w/r/t the latter, I can't think of a case where you'd want to call this and not have strict semantics, and returning a generator creates issues for using this with numpy/pandas, so I'd rather have this be eager. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was talking about the top level impl, but this the numpy case makes sense. |
||
append_output = out.append | ||
for sym in symbols: | ||
if sym in memo: | ||
append_output(memo[sym]) | ||
else: | ||
equity = memo[sym] = self.lookup_symbol(sym, as_of_date, fuzzy) | ||
append_output(equity) | ||
return out | ||
|
||
def lookup_future_symbol(self, symbol): | ||
"""Lookup a future contract by symbol. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should you compare against a comprehension again?