Problem · Database

Measure Liquidity

HardMillennium logoMillenniumNEW GRADINTERNOA

Problem statement

Use the prices and requests tables to calculate one liquidity score for each of Asset_1, Asset_2, and Asset_3.

Metric definitions

  • Sort prices by timestamp. Treat prices as exact decimal values. For each asset, calculate each adjacent return as current_price / previous_price - 1, round that return to 12 decimal places using round-half-away-from-zero for an exact tie, and then define volatility as the sample standard deviation of the rounded returns.
  • Define request frequency as the number of requests for an asset divided by the total number of rows in requests.
  • Min-max normalize the three volatility values together and the three frequency values together. If a metric has zero range, use 0.5 as that metric's normalized value for every asset.

Liquidity score

For each asset, calculate 0.1 + 0.9 * (0.5 * (1 - volatility_normalized) + 0.5 * frequency_normalized). Round the final score to 6 decimal places using the same round-half-away-from-zero rule and return rows in ascending asset-name order.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

prices

Exact decimal prices for the three assets at timezone-neutral whole-second timestamps.

ColumnTypeNullableDescription
timestampPKTimestampNoTimezone-neutral observation time in whole-second YYYY-MM-DD HH:MM:SS precision.
Asset_1DecimalNo
Asset_2DecimalNo
Asset_3DecimalNo

requests

Observed requests. Each row contributes once to request frequency.

ColumnTypeNullableDescription
request_idPKIntegerNo
assetTextNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
assetTextNo
liquidity_scoreDecimalNo

Row order: must match exactly. Numeric tolerance: 0.000001.

Constraints

  • The prices table contains at least 3 rows and at most 2000 rows.
  • Every timestamp is unique, timezone-neutral, and uses whole-second YYYY-MM-DD HH:MM:SS precision.
  • Every asset price is a strictly positive exact decimal value representable as DECIMAL(38, 12).
  • The requests table contains at least 1 row and at most 2000 rows.
  • Every request asset is exactly Asset_1, Asset_2, or Asset_3.
  • Use sample standard deviation, equivalent to ddof=1 in Pandas.
  • Return exactly three rows ordered by asset ascending.

More Millennium problems