Future Pricing Dividend Queries
MediumData Structures · Optiver
A simple futures pricer works from a stock's current price base_price and a calendar of expected dividends. The fair price of a future that expires on day d is
text
base_price - (sum of the amounts of all dividends scheduled on days <= d)The dividend calendar starts empty and changes over time. Process events in order; each event is one of:
["ADD", day, amount]: addamountto the dividend scheduled onday(creating it with that amount if none exists).["SET", day, amount]: set the dividend ondayto exactlyamount, creating it if needed.["REMOVE", day]: delete the dividend onday. If there is none, do nothing.["QUERY", day]: report the fair price of a future expiring onday, using the calendar as it stands at this moment.
Return the answers to the QUERY events in order. Prices can go negative; report them as they are.
Example 1
- Input:
- base_price = 100, events = [["ADD", 5, 3], ["ADD", 9, 4], ["QUERY", 7], ["ADD", 5, 2], ["QUERY", 9], ["SET", 9, 1], ["REMOVE", 5], ["QUERY", 20]]
- Output:
- [97, 91, 99]
- Explanation
- On day 7 only the day-5 dividend counts:
100 - 3 = 97. ADD makes day 5 total5, so day 9 sees100 - 5 - 4 = 91. SET lowers day 9 to 1, REMOVE deletes day 5, and day 20 sees100 - 1 = 99.
Example 2
- Input:
- base_price = 50, events = [["ADD", 10, 6], ["QUERY", 9], ["QUERY", 10]]
- Output:
- [50, 44]
- Explanation
- A future expiring on day 9 is before the dividend, so it is
50. On day 10 the dividend counts, giving44.
Example 3
- Input:
- base_price = 20, events = [["REMOVE", 3], ["SET", 3, 25], ["QUERY", 3]]
- Output:
- [-5]
- Explanation
- Removing a day with no dividend does nothing. SET then creates a dividend of 25 on day 3, which pushes the price to
-5.
Constraints
- 1 ≤ events.length ≤ 105
- 0 ≤ day ≤ 109
- 0 ≤ amount ≤ 106
- 0 ≤ base_price ≤ 109