FunctionRacerProblemsRace

Last Quote Before Each Trade

HardpandasPython

trades has columns ticker and time. quotes has ticker, time and price, with at most one quote per ticker per time. Times are whole seconds.

Return a list with one item per trade, in the order given: the price of the latest quote for the same ticker at or before the trade's time, or None when there is no such quote.

Example 1

trades {"ticker":["AAA","BBB","AAA","AAA"],"time":[10,10,3,25]}
quotes {"ticker":["AAA","AAA","BBB","AAA"],"time":[5,9,12,20],"price":[10.0,10.5,30.0,11.0]}
returns [10.5,null,null,11.0]

The AAA trade at 10 takes the quote from time 9. BBB's only quote comes later, at 12. The AAA trade at 3 is before every AAA quote. The one at 25 takes the quote from 20.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems