Premium problem169. Attach the Prevailing Quote to Each Trade

Hard Locked

Given a sorted array of quote timestamps quote_ts with prices quote_px, return one price per trade timestamp in trade_ts:

  • take the price of the most recent quote with quote_ts <= trade_ts
  • yield np.nan when no quote precedes the trade

Input

trade_ts = [1 4 5 0]
quote_ts = [2 4 6]
quote_px = [10. 20. 30.]

Output

[nan 20. 20. nan]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)