Problem · Math

Calculate the Half Spread

Learn this problem
EasyMillennium logoMillenniumNEW GRADINTERNOA

Problem statement

A market-making model starts with a base half spread, then adjusts it for volatility and liquidity. Higher volatility must make the quote wider, while higher liquidity must make it narrower.

Implement calculateHalfSpread and compute:

modeledHalfSpread = baseHalfSpread * (1 + volatility) / liquidityScore

Each input is a decimal value with at most seven digits after the decimal point; interpret those decimal values exactly. Return the larger of modeledHalfSpread and minimumHalfSpread. Round the result to six decimal places; an exact halfway case rounds upward.

Function

calculateHalfSpread(baseHalfSpread: double, volatility: double, liquidityScore: double, minimumHalfSpread: double) → double

Examples

Example 1

baseHalfSpread = 0.02volatility = 0.5liquidityScore = 0.75minimumHalfSpread = 0.03return = 0.04

The modeled value is 0.02 * 1.5 / 0.75 = 0.04. It is larger than the minimum 0.03.

Example 2

baseHalfSpread = 0.01volatility = 0.1liquidityScore = 1.0minimumHalfSpread = 0.02return = 0.02

The modeled value is 0.011, so the minimum half spread 0.02 becomes the result.

Constraints

  • 0 < baseHalfSpread <= 100
  • 0 <= volatility <= 10
  • 10^-6 <= liquidityScore <= 1
  • 0 <= minimumHalfSpread <= 100
  • Every input has at most seven digits after the decimal point.
  • The unrounded modeled value is at most 10^9.

More Millennium problems

drafts saved locally
public double calculateHalfSpread(double baseHalfSpread, double volatility, double liquidityScore, double minimumHalfSpread) {
    // write your code here
}
baseHalfSpread0.02
volatility0.5
liquidityScore0.75
minimumHalfSpread0.03
expected0.04
checking account