advanced
Complex Time-Series Analysis with SQL Window Functions
Solve a data retrieval problem requiring intricate calculation over sliding windows and frame clauses.
📝 Prompt Content
Given a table 'stock_prices' with columns 'symbol', 'trade_date', and 'close_price', write a single SQL query that calculates the 30-day moving average, the exponential moving average with a smoothing factor of 0.2, and the Bollinger Bands (upper and lower) for each symbol. The query should return only dates where the closing price crosses above the upper Bollinger Band. Assume a standard PostgreSQL environment. Explain the choice of window frame clauses (RANGE vs. ROWS) and their impact on handling missing dates in the data.