回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

Optiver SWE NG 2024 OA 求加米

全局:

2023(7-9月) 码农类General 硕士 全职@optiver - 网上海投 - 在线笔试  | 🙁 Negative 😐 Average | Fail | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
第一题解法是keep track of the maximum buy price and minimum sell price, 每次需要return worst trade的时候就算现在价格和maximum buy and minimum sell 的差。第二题我没时间做,好像不难。求加米,看面经!
Question 1 Worst trade reporter

You are tasked with building a tool to analyze the profitability of trades (also known as "profit and loss" or PnL). For the purpose of this problem, every trade has the following attributes:
•        TradeID - unique identifier for the trade,
•        InstrumentID - identifier of the instrument that has been traded,
•        Buy/Sell - flag to indicate whether you bought or sold the instrument,
•        Price - the price at which the instrument has been traded,
•        Volume - the quantity of the instrument that has been traded.
Consider a trade with the following attributes:
•        TradeID = 5,
•        InstrumentID = Google,
•        Buy/Sell = BUY,
•        Price = 500,
•        Volume = 20.
It means that you bought 20 lots of Google stock for 500 dollars and the identifier for the trade is 5. Note that trades have a TradeID because there can be multiple trades with the same InstrumentID, Buy/Sell, Price and Volume attributes.
Problem Statement
In this task, you receive a stream of N instructions. Each instruction can be an update or a query. An update can be of 2 kinds:
•        Trade - Indicates that a trade has happened. Attributes: TradeID, InstrumentID, Buy/Sell, Price, and Volume.
•        Price - Indicates that the true value of an Instrument has been updated. Attributes: instrumentID and Price.
There is only 1 kind of query:
•        WorstTrade - output the TradeID of the worst trade for an instrument. Attributes: instrumentID.
The WorstTrade is the trade with the highest loss made per lot of the trade. To calculate PnL of a trade the latest price update for an instrument is used as the true value of the instrument.
•        If you sell 2 Google stocks for 500 each, and had the latest price update saying Google is worth 400, the PnL for the trade is (500 - 400) *
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

3.        R <ClientId> means that the Client with ID ClientId requests position updates.
The ouput format is defined as follows:
1.        Clients print the answer they get as a subscription request like this
•        S <ClientId> <TruckId> <x_pos> <y_pos>
2.        Clients print all updates they get as
•        U <ClientID> <TruckId> <delta_x> <delta_y>
Example
Input
1
2 3
U 0 1.5 2.5
S 0 0
U 0 1 2
U 0 -0.5 -0.5
S 1 0
R 0
U 0 1 1
R 1
Output
S 0 0 3.5 5.5
S 1 0 4 7
U 0 1 2
U 0 -0.5 -0.5
U 1 1 1
Explanation:
•        The first line of output is produced when client with ID=0 subscribes to truck with ID=0. At that point truck with ID=0 is at (3.5, 5.5).
•        The second line of output is produced when client with ID=1 subscribes to truck with ID=0. At that point the truck is at (4, 7).
•        The third and fourth line of output are produced when client with ID=0 requests position updates for truck with ID=0. Since there were 2 updates after the subscription, there's one line for each update
•        The fifth line of output is produced when client with ID=1 requests position updates for truck with ID=0. Since there was 1 update after the subscription, there's one line of output.

Starting Code
  1. from dataclasses import dataclass, replace

  2. @dataclass
  3. class TruckPosition:
  4.         x: float
  5.         y: float

  6. @dataclass
  7. class TruckPositionDelta:
  8.         truck_id: int
  9.         delta_x: float
  10.         delta_y: float

  11. class Subscriber:
  12.         def __init__(self, server):
  13.                 pass
  14.         def process_update(self, update):
  15.                 pass
  16.         def subscribe_to_truck(self, truck_id, client_id):
  17.                 return TruckPosition(0, 0)
  18.         def get_updates(self, client_id):
  19.                 return [TruckPositionDelta(0, 0, 0)]
  20.                
  21. class Server:
  22.         def __init__(self):
  23.                 self.registered_trucks = set()
  24.                 self.current_pos = {}
  25.                
  26.         def subscribe_to_truck(self, truck_id):
  27.                 self.registered_trucks.add(truck_id)
  28.                 return replace(self.current_pos([truck_id])
  29.                
  30.         def add_position(self, truck_id, pos):
  31.                 self.current_pos[truck_id] = pos
复制代码

评分

参与人数 2大米 +26 收起 理由
MeFrix + 1 很有用的信息!
bryanjhy + 25 给你点个赞!

查看全部评分


上一篇:MathWorks EDG 2024 OA 求加米!
下一篇:Akuna 2023 - 2024 Quant &amp; Trading (Python/C++) OA
🔗
墨冰 2023-8-8 02:33:43 | 只看该作者
全局:
感觉不像在考算法,而是考数据结构和OOD?
回复

使用道具 举报

🔗
 楼主| yelv 2023-8-8 04:18:13 | 只看该作者
全局:
墨冰 发表于 2023-8-7 13:33
感觉不像在考算法,而是考数据结构和OOD?

题目很冗长。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表