Debug the Risk-Limit Quoter
Learn this problemProblem statement
A shipped risk-limit quoter contains two defects: its inventory skew can push a position farther from zero, and it can accept a trade exactly at the hard risk cap. Repair the supplied implementation without changing its interface.
The source-backed Java translation of the shipped starter is reproduced below for diagnosis. It intentionally retains the buggy behavior:
public String[] priceQuote(int currentInventory, String side, int quantity, double reference, double halfSpread, int baseLimit, double softFraction, double skewCoefficient) {
int signedQuantity = side.equals("BUY") ? quantity : -quantity;
long projected = (long) currentInventory + signedQuantity;
double hard = baseLimit;
double soft = softFraction * hard;
if (Math.abs(projected) > hard) {
return new String[]{"reject", "null"};
}
double skew = skewCoefficient * currentInventory;
double quote = side.equals("BUY")
? reference + halfSpread + skew
: reference - halfSpread + skew;
String action = "accept";
if (Math.abs(projected) > soft) {
action = "widen";
quote += side.equals("BUY") ? halfSpread : -halfSpread;
}
double rounded = Math.floor(quote * 1000000.0 + 0.5) / 1000000.0;
return new String[]{action, String.format(java.util.Locale.US, "%.6f", rounded)};
}For this quoter, apply these corrected rules in order:
- Use
signedQuantity = +quantityforBUYand-quantityforSELL, then computeprojected = currentInventory + signedQuantity. - Set
hard = baseLimitandsoft = softFraction * hard. Ifabs(projected) >= hard, return["reject", "null"]. - Otherwise use
skew = -skewCoefficient * currentInventory. The baseBUYquote isreference + halfSpread + skew; the baseSELLquote isreference - halfSpread + skew. - If
abs(projected) > soft, return actionwidenafter adding anotherhalfSpreadforBUYor subtracting anotherhalfSpreadforSELL. Otherwise return actionaccept.
The two source-backed risk defects to diagnose are the hard-cap comparison and skew sign shown above. For the execution contract, every decimal input is exact and has at most seven digits after the decimal point; do not copy the shipped binary rounding expression into the repaired implementation. Return a two-element string array [action, quote]. A non-rejected quote is rounded half upward to six decimal places and serialized with exactly six digits after the decimal point.
Function
priceQuote(currentInventory: int, side: String, quantity: int, reference: double, halfSpread: double, baseLimit: int, softFraction: double, skewCoefficient: double) → String[]Examples
Example 1
currentInventory = 900side = "BUY"quantity = 100reference = 100.0halfSpread = 0.05baseLimit = 1000softFraction = 0.6skewCoefficient = 0.001return = ["reject","null"]The projected inventory is exactly 1000. Equality at the hard cap is rejected.
Example 2
currentInventory = 500side = "SELL"quantity = 100reference = 100.0halfSpread = 0.05baseLimit = 1000softFraction = 0.6skewCoefficient = 0.001return = ["accept","99.450000"]Projected inventory is 400, below the soft limit. Correct skew is -0.5, so the SELL quote is 100 - 0.05 - 0.5 = 99.45.
Constraints
-10^9 <= currentInventory <= 10^9sideis eitherBUYorSELL.1 <= quantity <= 10^90 < reference <= 2 * 10^8and0 <= halfSpread <= 10^6.1 <= baseLimit <= 10^9and0 <= softFraction <= 1.0 <= skewCoefficient <= 10^3.- Each decimal input has at most seven digits after the decimal point.
- Every non-rejected quote is positive and at most
10^12.
Source note: The original assessment screenshot supplies the debugging setup, post-trade inventory direction, risk-cap behavior, and shipped Python implementation context.