Problem · Database
Measure Liquidity
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 ascurrent_price / previous_price - 1, round that return to12decimal 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.5as 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.
| Column | Type | Nullable | Description |
|---|---|---|---|
| timestampPK | Timestamp | No | Timezone-neutral observation time in whole-second YYYY-MM-DD HH:MM:SS precision. |
| Asset_1 | Decimal | No | — |
| Asset_2 | Decimal | No | — |
| Asset_3 | Decimal | No | — |
requests
Observed requests. Each row contributes once to request frequency.
| Column | Type | Nullable | Description |
|---|---|---|---|
| request_idPK | Integer | No | — |
| asset | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| asset | Text | No | — |
| liquidity_score | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.000001.
Constraints
- The
pricestable contains at least3rows and at most2000rows. - Every timestamp is unique, timezone-neutral, and uses whole-second
YYYY-MM-DD HH:MM:SSprecision. - Every asset price is a strictly positive exact decimal value representable as
DECIMAL(38, 12). - The
requeststable contains at least1row and at most2000rows. - Every request asset is exactly
Asset_1,Asset_2, orAsset_3. - Use sample standard deviation, equivalent to
ddof=1in Pandas. - Return exactly three rows ordered by
assetascending.