返回题库

隐含交叉撮合

Implied Crossing

专题
Systems & Architecture / 系统与架构
难度
L3
来源
MyntBit

题目详情

做市商和套利者持续监控关联标的以识别隐含交叉机会。通过定义的比率和偏移量在两个标的之间构建合成价差,可以检测定价效率不足。

任务:实现隐含交叉检测器类,检测两个关联标的之间的隐含价差机会。当合成价差与实际价差的偏差超过阈值时发出交易信号。

英文原题

Market makers and arbitrageurs continuously monitor correlated instruments to identify and capture implied crossing opportunities. A synthetic spread can be constructed between two instruments using a defined ratio and offset to detect pricing inefficiencies. Building an implied matching engine requires maintaining precise limit order books and evaluating synthetic crosses to execute profitable arbitrage trades in real-time.
Task
Implement an implied matching engine that processes a stream of m

解析

问题分析

Market makers and arbitrageurs continuously monitor correlated instruments to identify and capture implied crossing opportunities. A synthetic spread can be constructed between two instruments using a defined ratio and offset to detect pricing inefficiencies. Building an implied matching engine requ

解法

根据题目要求实现相应功能。核心逻辑需要:

// 核心数据结构和方法——根据题目 API 约定实现
// 1. 确定状态表示——选择支持所需操作的数据结构
// 2. 实现核心算法——确保 O(·) 时间复杂度和正确性
// 3. 处理边界条件——空输入、极值参数、并发访问

验证

用具体输入验证:构造已知输入的测试用例,确认输出匹配预期结果。

复杂度与边界

  • 时间复杂度:取决于选用的算法
  • 空间复杂度:取决于数据规模
  • 关键边界条件:空输入、极值参数、并发场景下的正确性保证

英文解析

Analysis

Market makers and arbitrageurs continuously monitor correlated instruments to identify and capture implied crossing opportunities. A synthetic spread can be constructed between two instruments using a defined ratio and offset to detect pricing inefficiencies. Building an implied matching engine requires tracking synthetic price levels derived from correlated instruments and matching them against resting orders in the book.

Solution

class ImpliedCrossingEngine {
    struct SpreadDef { std::string leg1, leg2; double ratio; double offset; };
    std::vector<SpreadDef> spreads_;
    std::unordered_map<std::string, double> last_prices_;
public:
    void addSpread(const SpreadDef& s) { spreads_.push_back(s); }
    void onPrice(const std::string& sym, double px) {
        last_prices_[sym] = px;
        for (const auto& s : spreads_) {
            if (last_prices_.count(s.leg1) && last_prices_.count(s.leg2)) {
                double implied = last_prices_[s.leg1] * s.ratio + last_prices_[s.leg2] + s.offset;
                checkCrossing(implied);
            }
        }
    }
    void checkCrossing(double implied_px) {
        // Check implied price against resting orders
        // If implied crosses a bid/ask, generate synthetic match
    }
};

Complexity & Edge Cases

  • Time complexity: Price update triggers O(S) spread checks where S = number of spreads
  • Space complexity: O(spreads + instruments)
  • Edge cases: (1) Stale prices on one leg produce invalid implied prices (2) Ratio/offset errors accumulate across legs (3) Race between price updates and crossing detection requires atomic price storage

Verification

Test with two correlated instruments: set leg1=100, leg2=50, ratio=2, offset=0. Implied price = 200. Verify crossing triggers when resting order exists at implied level. Test stale price detection.

Key Considerations

Implied crossing detection must handle price staleness carefully - a stale price on one leg can trigger false crossings. In production systems, each leg price carries a timestamp, and implied prices are invalidated when any leg becomes stale beyond a configured threshold.