Chapter 19 Quiz

Question 1

What is the most dangerous type of API error when submitting an order?

A) HTTP 400 Bad Request B) HTTP 429 Rate Limit Exceeded C) A timeout with no response D) HTTP 500 Internal Server Error

Answer: C A timeout is the most dangerous because you do not know whether the order was placed or not. If you blindly retry, you may create duplicate orders. HTTP 400 is a definitive rejection (safe). HTTP 429 and 500 mean the request was not processed (safe to retry). A timeout requires checking whether the order exists on the exchange before deciding whether to retry.


Question 2

Which of the following is NOT a valid reason to override an automated trading bot?

A) The data feed is clearly stuck on stale prices B) The bot is losing money over the last three days C) The platform announced an upcoming rule change affecting active markets D) The bot submitted an order at an obviously wrong price due to a bug

Answer: B Three days of losses could easily be within normal variance for a strategy with genuine edge. Overriding the bot because of short-term losses is emotional trading, not informed decision-making. Stale data (A), external information the bot cannot access (C), and clear bugs (D) are all legitimate reasons for human intervention.


Question 3

A token bucket rate limiter has rate = 5 tokens/second and burst = 10. If the bucket is full and you send 10 requests instantly, how long must you wait before you can send the next request?

A) 0.1 seconds B) 0.2 seconds C) 1.0 seconds D) 2.0 seconds

Answer: B After sending 10 requests instantly, the bucket is empty (0 tokens). Tokens refill at 5 per second, so you need 1 token which takes 1/5 = 0.2 seconds.


Question 4

What is "implementation shortfall" in the context of execution quality?

A) The difference between your order price and the fill price B) The fraction of theoretical P&L lost to execution costs C) The percentage of orders that fail to execute D) The latency between signal generation and order fill

Answer: B Implementation shortfall measures the total cost of your execution process as a fraction of the theoretical P&L you would have earned with perfect execution. It captures slippage, partial fills, unfilled orders, and timing effects in a single metric.


Question 5

In the staged deployment approach recommended in this chapter, what comes between paper trading and full live trading?

A) Unit testing B) Integration testing C) Small live trading with minimal position sizes D) Backtesting with live data

Answer: C The four stages are: (1) unit testing, (2) paper trading, (3) small live trading at 5-10% of target capital, and (4) full live trading. Small live validates execution quality, market impact, and psychological factors that paper trading cannot.


Question 6

Which circuit breaker state allows test requests to check if the service has recovered?

A) CLOSED B) OPEN C) HALF_OPEN D) TESTING

Answer: C In the circuit breaker pattern, HALF_OPEN is the state where the circuit allows a limited number of test requests to check if the service has recovered. If they succeed, the circuit returns to CLOSED. If they fail, it returns to OPEN.


Question 7

A pre-trade risk check rejects an order because the resulting position would be $6,000 when the max_position_value is set to $5,000. The current position is 80 contracts bought at $0.50. The new order is to buy 30 more at $0.55. What is the resulting position value that triggered the rejection?

A) $5,500 B) $5,830 C) $6,050 D) $6,600

Answer: C The resulting position would be 110 contracts. At the order price of $0.55, the position value would be 110 * $0.55 = $6,050, which exceeds the $5,000 limit.


Question 8

What is the primary limitation of paper trading compared to live trading?

A) Paper trading cannot process real-time data B) Paper trading cannot test signal generation logic C) Paper trading cannot validate market impact and fill probability D) Paper trading cannot run for extended periods

Answer: C Paper trading uses real-time data and can run indefinitely, testing signal generation logic perfectly well. However, because paper orders never hit the real order book, it cannot validate market impact (how your orders move prices) or realistic fill probability (which depends on queue position and order flow).


Question 9

You are calculating slippage for a SELL order. Your intended price was 0.65 and you were filled at 0.63. What is the slippage?

A) -0.02 (negative slippage, favorable) B) +0.02 (positive slippage, unfavorable) C) -0.02 (negative slippage, unfavorable) D) +0.02 (positive slippage, favorable)

Answer: B For a sell order, slippage = intended_price - fill_price = 0.65 - 0.63 = +0.02. Positive slippage means you got a worse price than intended (you received less than you expected), which is unfavorable.


Question 10

In the trading bot architecture described in this chapter, which component publishes "OrderRequest" events?

A) Signal Generator B) Risk Manager C) Order Executor D) Data Feed Handler

Answer: B The message flow is: Data Feed -> Signal Generator (publishes Signals) -> Risk Manager (validates, publishes OrderRequests if approved) -> Order Executor. The Risk Manager is the gatekeeper that converts validated signals into order requests.


Question 11

Why should the save_state() method write to a backup file first, then rename?

A) To improve write performance B) To ensure atomicity -- if the process crashes mid-write, the old state is still intact C) To maintain a history of previous states D) To support concurrent access from multiple processes

Answer: B Writing to a backup file and then renaming is a common pattern for atomic writes. If the process crashes while writing the backup file, the original state file is still intact. The rename operation is atomic on most filesystems, so the state file is always in a consistent state.


Question 12

What is "tilt" in trading psychology?

A) A strategy that profits from trending markets B) A state of emotional compromise that leads to poor decisions C) A technical indicator based on price momentum D) A method for adjusting position sizes based on confidence

Answer: B Tilt, borrowed from poker, describes a state of emotional compromise where a trader makes decisions driven by frustration, anger, or desperation rather than rational analysis. Signs include increased trading frequency, deviation from rules, and obsessive P&L checking.


Question 13

A strategy has a 60% win rate. What is the probability of experiencing 5 consecutive losses?

A) 0.78% B) 1.02% C) 2.40% D) 7.78%

Answer: B P(5 consecutive losses) = (1 - 0.60)^5 = 0.40^5 = 0.01024 = 1.02%. This is the probability at any given point. Over many trades, this event will almost certainly occur.


Question 14

Which of the following is the CORRECT way to handle API keys in a trading bot?

A) Store them in a JSON configuration file committed to git B) Hardcode them in the source code but use a private repository C) Read them from environment variables or encrypted configuration files D) Store them in a database table with the bot's other settings

Answer: C API keys should never be committed to version control (even private repos) or hardcoded. Environment variables and encrypted configuration files are the standard secure approaches. Database storage (D) could be acceptable with proper encryption and access controls, but environment variables are simpler and more standard for this use case.


Question 15

A position tracker shows you are long 50 contracts with an average entry price of 0.45. You sell 20 contracts at 0.55. What is the realized P&L from this trade (ignoring fees)?

A) $1.00 B) $2.00 C) $5.50 D) $11.00

Answer: B Realized P&L = (exit_price - entry_price) * quantity_closed = (0.55 - 0.45) * 20 = 0.10 * 20 = $2.00.


Question 16

What is the purpose of the "cooling-off rule" described in Section 19.9.3?

A) To reduce API rate limit usage after a burst B) To prevent cascading emotional decisions after a manual intervention C) To allow the market to stabilize after a large trade D) To give the risk manager time to recalculate limits

Answer: B The cooling-off rule states that after any manual intervention, you should wait at least 1 hour before making another manual change. Its purpose is to prevent the cascading of emotional decisions, where one intervention leads to another in rapid succession without rational analysis.


Question 17

In the exponential backoff retry strategy with base_delay = 1.0 and exponential_base = 2.0, what is the delay before the 4th retry attempt (attempt index 3)?

A) 3 seconds B) 6 seconds C) 8 seconds D) 16 seconds

Answer: C Delay = base_delay * exponential_base^attempt = 1.0 * 2.0^3 = 8.0 seconds. (Attempt indices are 0, 1, 2, 3, so the 4th retry uses attempt=3.)


Question 18

Which pre-trade risk check is MOST important for preventing catastrophic losses from a single bug?

A) Price reasonableness check B) Liquidity check C) Daily loss limit D) Correlation check

Answer: C The daily loss limit is the most important safeguard against catastrophic losses because it halts all trading when cumulative losses exceed a threshold. A price reasonableness check catches individual bad orders, but a series of individually reasonable but collectively disastrous orders would pass it. The daily loss limit catches any pattern of losses regardless of cause.


Question 19

Your execution quality analyzer shows a fill rate of 45% and average slippage of 0.1 cents. What should you do?

A) Increase order size to compensate for low fill rate B) Switch to market orders for guaranteed fills C) Make your limit prices more aggressive (closer to or crossing the spread) D) Reduce polling frequency to improve latency

Answer: C A 45% fill rate with very low slippage indicates your limit prices are too passive -- you are pricing for minimal slippage but missing most trading opportunities. Making prices slightly more aggressive will increase fill rate at the cost of slightly more slippage, likely improving overall performance. Market orders (B) would go too far in the aggressive direction. Increasing order size (A) would not help fill rate. Polling frequency (D) is unrelated to fill rate on limit orders.


Question 20

What should a trading bot do immediately upon detecting that it has lost its connection to the exchange API?

A) Continue generating signals and queue orders for when connection returns B) Attempt to cancel all outstanding orders (if possible through an alternate channel) C) Increase position sizes to make up for lost trading time D) Switch to a paper trading mode

Answer: B Upon connection loss, the priority is to move to a safe state. Outstanding orders could fill while you have no ability to monitor or manage them, so canceling them (if possible) is the first priority. Queueing orders (A) is dangerous because market conditions change. Increasing sizes (C) is irrational. Paper trading mode (D) does not address the risk of outstanding orders.


Question 21

Position reconciliation between your local tracker and the exchange shows a discrepancy: you think you are long 30 contracts, but the exchange shows 50. What is the most likely cause?

A) The exchange made an error B) A fill notification was lost or not processed by your system C) Someone else is trading on your account D) The position tracker has a rounding error

Answer: B The most common cause of local-vs-exchange position discrepancies is missed fill notifications. This can happen due to network issues, processing errors, or race conditions. Exchange errors (A) are very rare. While unauthorized trading (C) is possible, it is much less likely than a missed fill. A rounding error (D) would not produce a 20-contract discrepancy.


Question 22

Why is structured JSON logging preferred over simple text logging for trading systems?

A) JSON logs are smaller in file size B) JSON logs can be parsed programmatically for automated analysis and alerting C) JSON logs are more human-readable D) JSON logs are required by financial regulators

Answer: B Structured JSON logging enables programmatic parsing, querying, and analysis. You can build automated monitoring and alerting systems that parse log entries, extract fields (market_id, P&L, error type), and trigger actions. Text logs are easier for humans to read but difficult for machines to parse reliably.


Question 23

You are running a trading bot that uses a mean-reversion strategy. After going live, you notice that your backtest showed 15% annual returns but live trading shows only 3%. Which of the following is the LEAST likely explanation?

A) Your backtest had lookahead bias B) Market impact from your trades is eroding the edge C) The platform changed its fee structure D) Your API key has insufficient permissions

Answer: D Insufficient API permissions would cause orders to fail or be rejected entirely, not produce reduced (but still positive) returns. All other options can explain a gradual erosion of returns: lookahead bias (A) inflates backtest results, market impact (B) adds execution costs, and fee changes (C) reduce net returns.


Question 24

In the paper trading engine, why is it important to simulate partial fills?

A) Partial fills never happen in real markets so they test edge cases B) They test the position tracker's ability to handle non-integer quantities C) Real markets frequently produce partial fills, and strategies must handle them correctly D) Partial fills improve the paper trading P&L to be more optimistic

Answer: C Partial fills are common in real markets, especially in thinner prediction markets. A strategy must correctly handle partial fills -- adjusting position sizes, recalculating average entry prices, managing remaining order quantities, and making decisions about whether to chase the remaining fill or cancel. Paper trading should simulate this to validate the strategy handles these cases correctly.


Question 25

A pre-trade liquidity check limits your order size to 5% of average daily volume. The market trades 2,000 contracts per day. Your model generates a signal to buy 150 contracts. What happens?

A) The order is rejected entirely B) The order is submitted for 100 contracts (5% of 2,000) C) The risk check depends on implementation -- it could reject or resize D) The order is submitted for 150 contracts because the check only applies to individual trades

Answer: C The chapter describes the liquidity check as a maximum: q_order <= alpha * ADV. Whether the system rejects the order outright or resizes it to the maximum allowable quantity depends on the implementation. Some systems reject and let the signal generator decide what to do. Others automatically clip to the limit. The important point is that 150 > 100 violates the check.