20 Essential PromQL Formulas for Shadow Portfolio Monitoring
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
-
Active Position Count by Tournament Type
sum(shadow_position) by (tournament_type)Chart: Stacked Area Chart - Shows count distribution over time by tournament type
-
Partially Closed vs Fully Open Positions
sum(shadow_position) by (status)Chart: Pie Chart - Quick ratio visualization of position statuses
-
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
-
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
-
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
-
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
-
Stop Loss Hit Rate
sum(shadow_position_event{event_type="closed", exit_reason="SL"}) /
sum(shadow_position_event{event_type="closed"}) * 100Chart: Gauge - Percentage of positions closed by stop loss
Performance Analysis
-
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
-
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
-
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
-
Symbol Performance Heatmap
sum by (symbol) (shadow_position_pnl{pnl_type="final"})Chart: Heatmap - Shows which symbols perform best across all strategies
-
Symbol Win Rate
sum by (symbol) (shadow_position_event{event_type="closed", pnl=~".*[1-9].*"}) /
sum by (symbol) (shadow_position_event{event_type="closed"}) * 100Chart: Bar Chart - Win percentage by symbol
-
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
-
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
-
PnL Velocity by Tournament Type
rate(sum by (tournament_type) (shadow_position_pnl{pnl_type="unrealized"})[6h])Chart: Sparkline - Quick visualization of PnL momentum
-
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
-
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) * 100Chart: Gauge - Percentage of account balance currently in use
-
Account Performance Comparison
sum by (account_id) (
shadow_account_performance{metric_type="roi"}
)Chart: Bar Chart - Compare ROI across different accounts
System Health
-
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
-
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.
