Write LINQ queries for a .NET application and explain how you would use them in database access at Balyasny Asset Management.
For this exercise, provide the PostgreSQL equivalent that a LINQ provider should generate. Include active portfolios, current active positions, aggregated gross exposure, and an exposure classification.
Output
- One row per active portfolio, including portfolios with no qualifying positions.
- Columns:
portfolio_id, portfolio_name, active_position_count, gross_exposure, and exposure_band.
- Sort by
gross_exposure descending, then portfolio_id ascending.
Output details
- Treat
DATE '2026-06-30' as today's date.
- Include positions only when
as_of_date equals DATE '2026-06-30' and their instruments have is_active = TRUE.
- Calculate
gross_exposure as the sum of absolute quantity * last_price, using 0 when no qualifying positions exist.
- Classify exposure as
High for values >= 10000, Medium for values >= 1000 and < 10000, otherwise Low.
- Count only qualifying active instruments with non-NULL
instrument_id in active_position_count.