Skip to main content

20 Essential PromQL Formulas for Shadow Portfolio Monitoring

· 2 min read
Max Kaido
Architect

Based on the current shadow portfolio metrics structure and the lifecycle tracking we've implemented, I recommend these top 20 PromQL queries with corresponding chart types for monitoring your system:

Position Metrics

  1. Active Position Count by Tournament Type

    sum(shadow_position) by (tournament_type)

    Chart: Stacked Area Chart - Shows count distribution over time by tournament type

  2. Partially Closed vs Fully Open Positions

    sum(shadow_position) by (status)

    Chart: Pie Chart - Quick ratio visualization of position statuses

  3. Combined (Realized + Unrealized) PnL by Tournament Type

    sum by (tournament_type) (
    shadow_position_pnl{pnl_type="realized"} + on(position_id)
    shadow_position_pnl{pnl_type="unrealized"} * on(position_id) shadow_position
    )

    Chart: Heatmap - Color intensity showing performance across tournament types

  4. Realized vs Unrealized PnL Comparison

    sum(shadow_position_pnl{pnl_type="realized"}) /
    sum(shadow_position_pnl{pnl_type="unrealized"} * on(position_id) shadow_position)

    Chart: Gauge - Quick visualization of how much profit has been locked in

Risk Management

  1. Position Risk Distribution (TP:SL Ratio)

    avg by (tournament_type) (
    label_replace(shadow_position{}, "risk_reward", "$1", "metadata_risk_reward", "(.+)")
    )

    Chart: Bar Chart - Compare risk-reward setup across tournament types

  2. Max Drawdown Across Position Types

    max by (tournament_type) (
    shadow_position{} * on(position_id) label_replace(shadow_position{}, "drawdown", "$1", "max_drawdown_percent", "(.+)")
    )

    Chart: Bar Chart - Shows maximum drawdown by tournament type

  3. Stop Loss Hit Rate

    sum(shadow_position_event{event_type="closed", exit_reason="SL"}) /
    sum(shadow_position_event{event_type="closed"}) * 100

    Chart: Gauge - Percentage of positions closed by stop loss

Performance Analysis

  1. Take Profit Level Hit Distribution

    sum by (level_index) (shadow_position_event{event_type="tp_level_hit"})

    Chart: Bar Chart - Shows which TP levels are most frequently reached

  2. Position Duration vs. PnL Correlation

    sum by (duration_bucket) (
    shadow_position_event{event_type="closed"} * on(position_id)
    shadow_position_pnl{pnl_type="final"}
    )

    Chart: Scatter Plot - Correlation between holding time and returns

  3. Multiple TP Efficiency

    avg by (tp_levels_count) (
    sum by (position_id) (shadow_position_event{event_type="tp_level_hit"}) * on(position_id)
    shadow_position_pnl{pnl_type="realized"}
    )

    Chart: Line Chart - Shows how realized PnL improves with number of TP levels hit

Symbol Analysis

  1. Symbol Performance Heatmap

    sum by (symbol) (shadow_position_pnl{pnl_type="final"})

    Chart: Heatmap - Shows which symbols perform best across all strategies

  2. Symbol Win Rate

    sum by (symbol) (shadow_position_event{event_type="closed", pnl=~".*[1-9].*"}) /
    sum by (symbol) (shadow_position_event{event_type="closed"}) * 100

    Chart: Bar Chart - Win percentage by symbol

  3. Partial Close Efficiency by Symbol

    sum by (symbol) (shadow_position_pnl{pnl_type="realized"}) /
    sum by (symbol) (shadow_position_pnl{pnl_type="unrealized" or pnl_type="realized"})

    Chart: Gauge - Shows which symbols benefit most from partial closes

Time-based Analysis

  1. Position Creation vs. Closure Pattern

    rate(shadow_position_event{event_type="created"}[24h]) -
    rate(shadow_position_event{event_type="closed"}[24h])

    Chart: Line Chart - Net position growth rate

  2. PnL Velocity by Tournament Type

    rate(sum by (tournament_type) (shadow_position_pnl{pnl_type="unrealized"})[6h])

    Chart: Sparkline - Quick visualization of PnL momentum

  3. Intraday Position Performance Pattern

    avg_over_time(shadow_position_pnl{pnl_type="unrealized"}[1d]) by (hour_of_day)

    Chart: Heatmap - Shows performance patterns by time of day

Account Management

  1. Account Balance Utilization

    sum(shadow_position{} * on(position_id) shadow_position_size{}) by (account_id) /
    sum(shadow_account_balance{balance_type="total"}) by (account_id) * 100

    Chart: Gauge - Percentage of account balance currently in use

  2. Account Performance Comparison

    sum by (account_id) (
    shadow_account_performance{metric_type="roi"}
    )

    Chart: Bar Chart - Compare ROI across different accounts

System Health

  1. Position Update Frequency

    increase(shadow_position{} * on(position_id)
    label_replace(shadow_position{}, "updates", "$1", "metadata_last_checked_timestamp", "(.+)")
    [1d])

    Chart: Histogram - Shows how frequently positions are being updated

  2. Metrics Collection Completeness

    count(shadow_position) /
    count(shadow_position_pnl{pnl_type="unrealized"})

    Chart: Stat - Ratio close to 1.0 indicates all positions have PnL metrics

These queries are designed to provide comprehensive monitoring of your shadow portfolio system with special attention to the partial close mechanism we've implemented. The chart types are selected to make the data most intuitive for quick analysis.