Voleon 面试题 #2 —— 交易所数据流模拟:print / volume-check / order(量化面经|HFT|撮合与风控)

115次阅读
没有评论

The program reads the input line by line from stdin.
Each line is exactly one of the following message types:

  1. Trade print — a trade that occurred on the exchange
print <timestamp> <security> <quantity> <price>
  1. Volume check — request to report the total traded quantity of a security in the preceding minute, and its latest price
volume-check <timestamp> <security>
  1. Order — request to trade shares subject to participation limits
order <timestamp> <security> <client> <goal> <participation_rate>

Fields (space-delimited):

  • timestamp: seconds since market open (non-negative integer). Timestamps are monotonically non-decreasing.
  • security: security symbol (alphabetic string).
  • quantity: number of shares traded (positive integer).
  • price: trade price (positive integer).
  • client: client name (alphabetic string).
  • goal: total number of shares to trade (positive integer).
  • participation_rate: max percent of the security’s trailing 1-minute volume (computed without this order) that this order may constitute (positive integer).

An order is:

  • filled when its goal quantity has been traded,
  • active from its timestamp until it is filled or expires after one minute (T to T+60, exclusive of T+60),
  • at most one active order per (client, security) at any time.

Output

For each volume-check for security S at time T, emit exactly one line:

traded-volume T S <volume> <price>

Where:

  • <volume> is the sum of quantities in all print messages whose timestamps are in (T-60, T]. If none, output 0.
  • <price> is the price of the most recent print for S at or before T. If none, output 0.

A volume-check response must be printed immediately before reading the next input line.


For each order on security S at time T, emit a sequence of prints you execute:

print T' S <quantity> <price>

Subject to all constraints below (maximize filled shares as soon as possible):

  1. Monotone timestamps: your emitted timestamps must not go backwards relative to observed exchange activity; in particular, T' ≥ T.
  2. Expiry: all your prints must satisfy T' < T + 60.
  3. Participation limit: for the trailing minute ending at each T’, \frac{\text{(your emitted volume within that minute)}}{\text{(all *other* trades’volume within that minute)}} \le \text{participation_rate \%} The denominator uses observed exchange prints only (i.e., excludes the order you are executing).
  4. Positive integer quantities: each emitted print has positive integer <quantity>, and the sum over the sequence must not exceed goal.
  5. Price: each emitted print must use the latest observed price of S (from the most recent exchange print at or before T'). If no price exists, you cannot print.

Notes:

  • As earlier exchange prints roll out of the 60-second window, your instantaneous participation ratio may appear to spike; that’s okay — the limit is evaluated at emission time.
  • Always trade as much as possible as soon as possible while respecting the constraints above.

简要总结

实现一个交易所流事件模拟器,逐行读取三类消息:成交 print、查询 volume-check、以及带 1 分钟参与率限制 的客户 order

  • volume-check(T, S) 需要立刻输出:该证券在 (T-60, T] 的总成交量,以及 最近一次 成交价(没有则 0)。
  • order 要在 T…T+60 内,按 不回退时间、使用最新外部成交价 严格满足参与率上限 的前提,尽量快、尽量多地下自有 print 指令完成 goal,每次数量为正整数,总量不超过 goal。参与率分母只看 外部真实成交,不含你的订单执行量。

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Voleon、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0