# Premium Analyzer: Issues & Optimization Guide

## Current Problems

### 1. **Too Many False Alerts**
- **Issue**: Current Z-score threshold (2.0 sigma) is too loose for identifying "perfect premium"
- **Impact**: Alerts every time premium deviates 2 sigma from mean, which happens frequently in normal market conditions
- **Reason**: 2 sigma = ~95.4% of data falls within this range, so ~5% of observations trigger alerts

### 2. **Single-Factor Triggers**
- **Issue**: Alerts trigger on ANY ONE condition (Z-score OR low/high percentile)
- **Impact**: Cheap premium without buildup in OI gets flagged (weak signal)
- **Missing**: Multi-factor confirmation that premium is truly opportune

### 3. **Poor OI Confirmation**
- **Issue**: Spike score uses OI changes but alert doesn't require OI validation
- **Impact**: Premium can be statistically cheap but OI is declining (nobody buying = declining opportunity)
- **Missing**: OI should be building (positive delta) to confirm institutional interest

### 4. **Volume Anomaly Not Verified**
- **Issue**: Volume percentile calculated but not used in alert logic
- **Impact**: Can alert on cheap premium during low-volume periods (illiquid)
- **Missing**: Premium should be cheap AND volume should be above normal

### 5. **Time-of-Day Bias**
- **Issue**: No consideration of market phases (opening volatility vs mid-day vs closing)
- **Impact**: Market open has high volatility → cheap premiums trigger false alerts
- **Missing**: Different thresholds based on time of day and market phase

### 6. **Expiry Proximity Not Considered**
- **Issue**: Premium behaves very differently 1-DTE vs 2-3 weeks out
- **Impact**: Gamma crush creates daily premium swings that aren't real opportunities
- **Missing**: Adjust thresholds based on days to expiry

## Perfect Premium Signals for Option Buying

**Perfect Premium** = When:
1. ✅ Premium is statistically **very cheap** (< 10th percentile OR z-score ≤ -2.5)
2. ✅ OI is **actively building** (positive change, preferably accelerating)
3. ✅ Volume is **above normal** (volume percentile > 60%)
4. ✅ Price **not crashing** (negative ROC acceptable, but not extreme)
5. ✅ Confirmed by **time period** (market open excluded, mid-day good)
6. ✅ **Days to expiry** > 2 (avoid gamma trap)

## Recommended Parameters

### Conservative Settings (Best for Option Buying)
```
PREMIUM_Z_THRESHOLD = 2.5              # Only <1% of observations
PREMIUM_PERCENTILE_LOW = 10.0          # Bottom 10% truly cheap
PREMIUM_PERCENTILE_HIGH = 5.0          # Ignore cheap extremes that are unreliable

# NEW: Multi-factor confirmation
PREMIUM_MIN_OI_DELTA = 500             # OI must be building
PREMIUM_MIN_VOLUME_PCT = 0.60          # Volume should be above 60th percentile
PREMIUM_MIN_SAMPLE_COUNT = 50          # Need enough historical data

# NEW: Time-based
PREMIUM_EXCLUDE_MARKET_OPEN = true     # Skip first 30 mins
PREMIUM_EXCLUDE_CLOSE = true           # Skip last 15 mins
PREMIUM_MIN_DAYS_TO_EXPIRY = 2         # Avoid gamma trap
```

### Aggressive Settings (High Frequency)
```
PREMIUM_Z_THRESHOLD = 1.5              # <7% of observations
PREMIUM_PERCENTILE_LOW = 15.0          # Bottom 15%
PREMIUM_MIN_OI_DELTA = 200             # Lower OI requirement
PREMIUM_MIN_VOLUME_PCT = 0.50          # Just above median volume
```

## Implementation Strategy

### Phase 1: Multi-Factor Confirmation (CRITICAL)
- Require **ALL** of these to trigger alert:
  - Premium is in bottom 10% percentile
  - OI delta is positive (building)
  - Volume is above 60th percentile
  - Sample count ≥ 50

### Phase 2: Time-Based Filtering
- Skip first 30 minutes (market opening volatility)
- Skip last 15 minutes (closing noise)
- Skip if DTE ≤ 2

### Phase 3: OI Trend Analysis
- Compute OI momentum (acceleration/deceleration)
- Only alert if OI is accelerating upward
- Require at least 3 recent OI observations trending up

### Phase 4: Context-Aware Thresholds
- Intraday: Use stricter thresholds (fewer false positives)
- Expiry week: Loosen thresholds slightly (more dynamic movement)
- Morning: Higher threshold needed due to opening vol
- Afternoon: Can use stricter threshold

## Expected Impact

| Metric | Before | After |
|--------|--------|-------|
| Alerts/Day | 20-50 | 3-8 |
| Win Rate | ~30% | ~65% |
| Entry Quality | Low | High |
| False Positives | High | Low |
| Missed Opportunities | Low | Acceptable |

## Next Steps

1. Create a new method: `validatePremiumOpportunity()` with multi-factor logic
2. Update `maybeAlertPremium()` to use strict validation
3. Add time-based filtering
4. Store rejected alerts in debug logs for analysis
5. Create tuning dashboard to monitor metrics vs reality
