You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have large quantities of stock data sorted by date, symbol, time. I'd like to produce the most recent quote that happened at or before every trade. This is what merge_asof was made for. However, the shape of the data merge_asof seems to require seems strange to me. I think it should work with the data in the form it's currently in.
Feature Description
Create some sample data:
importpandasaspdimportnumpyasnp# sample data for trades dataframetrades_data= {'date': ['2022-01-01', '2022-01-01', '2022-01-02', '2022-01-02'],
'symbol': ['AAPL', 'MSFT', 'AAPL', 'MSFT'],
'time': [2200, 1200, 2200, 1200],
'trade_price': [100, 200, 150, 50]}
# create trades dataframetrades=pd.DataFrame(trades_data)
# set the multi-index for the trades dataframetrades.set_index(['date', 'symbol', 'time'], inplace=True)
trades.sort_index(inplace=True)
# sample data for quotes dataframequotes_data= {'date': ['2022-01-01', '2022-01-01', '2022-01-01', '2022-01-01', '2022-01-02', '2022-01-02', '2022-01-02', '2022-01-02'],
'symbol': ['AAPL', 'MSFT', 'AAPL', 'MSFT', 'AAPL', 'MSFT', 'AAPL', 'MSFT'],
'time': [2000, 1000, 2500, 1500, 2000, 1000, 2500, 1500],
'quote_price': [90, 10, 95, 15, 105, 25, 40, 45]}
# create quotes dataframequotes=pd.DataFrame(quotes_data)
# set the multi-index for the quotes dataframequotes.set_index(['date', 'symbol', 'time'], inplace=True)
quotes.sort_index(inplace=True)
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I have large quantities of stock data sorted by date, symbol, time. I'd like to produce the most recent quote that happened at or before every trade. This is what
merge_asof
was made for. However, the shape of the datamerge_asof
seems to require seems strange to me. I think it should work with the data in the form it's currently in.Feature Description
Create some sample data:
Alternative Solutions
OR
Additional Context
No response
The text was updated successfully, but these errors were encountered: