# Task: Generate End-of-Session Shadow Paper Trading Report

## Objective

Create a complete paper-trading session report after the market closes.

The report must reconstruct every shadow signal generated during today's session and simulate the trade exactly as the production paper-trading engine manages positions.

This is an investigation and reporting task.

Do NOT modify any code.

Do NOT modify any database records.

Do NOT place any orders.

Do NOT change any configuration.

Generate the report only.

---

## Report output

Create the report in:

docs/shadow_session_results/

Use the following filename format:

DD_MMM_YYYY.md

Examples:

docs/shadow_session_results/17_Aug_2026.md
docs/shadow_session_results/18_Aug_2026.md
docs/shadow_session_results/19_Aug_2026.md

Create the directory if it does not already exist.

---

## Data sources

Use the actual database.

Do NOT estimate.

Do NOT infer.

Use the real stored records.

Primary sources:

- ops_decisions
- historical_candles
- historical_option_candles
- historical_option_contracts
- shadow_mode outcomes
- shadow outcome resolver
- paper-trading position logic
- production trailing-stop logic

Use any additional tables that are actually used by the paper-trading engine.

---

## Important requirements

The simulation must use the SAME logic as production.

Do NOT create a simplified model.

The following production rules must be preserved:

- Entry logic
- Initial stop loss
- Target
- Trailing stop loss
- Position management
- Exit logic

The report must use the actual trailing-stop implementation.

Do NOT use only the initial target and stop-loss values.

Reconstruct the entire trade lifecycle.

---

## Section 1: Session summary

Generate the following table.

| Metric | Value |
| --- | --- |
| Session date | |
| Total observations | |
| Total events | |
| Total signals | |
| Total rejections | |
| Total no-signal observations | |
| Total completed paper trades | |
| Total wins | |
| Total losses | |
| Total breakeven trades | |
| Total ambiguous trades | |
| Total unresolved trades | |
| Win rate | |
| Total paper P&L (₹) | |

---

## Section 2: Complete trade ledger

Create one row for every SIGNAL.

| # | Observed (IST) | Bar (IST) | Direction | Contract | Entry | Initial SL | Initial Target | Exit Price | Exit Reason | MFE | MAE | Trailing SL Activated | Final Trailing SL | Profit/Loss (Points) | Profit/Loss (₹) | Duration (minutes) | Final Result |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |

Definitions:

Observed (IST):
- generated_at converted to IST

Bar (IST):
- context.bar_ts converted to IST

Exit Reason must be one of:

- Target hit
- Initial stop hit
- Trailing stop hit
- Breakeven stop
- Timeout
- Ambiguous
- Unresolved

Final Result must be one of:

- WIN
- LOSS
- BREAKEVEN
- AMBIGUOUS
- UNRESOLVED

---

## Section 3: Direction analysis

| Direction | Trades | Wins | Losses | Win Rate | Total P&L (₹) |
| --- | --- | --- | --- | --- | --- |
| BUY_CE | | | | | |
| BUY_PE | | | | | |

---

## Section 4: Strategy analysis

| Strategy | Trades | Wins | Losses | Win Rate | Total P&L (₹) |
| --- | --- | --- | --- | --- | --- |

---

## Section 5: Best trades

Top 5 profitable trades.

| Rank | Time | Direction | Contract | P&L (₹) |
| --- | --- | --- | --- | --- |

---

## Section 6: Worst trades

Top 5 losing trades.

| Rank | Time | Direction | Contract | P&L (₹) |
| --- | --- | --- | --- | --- |

---

## Section 7: Trailing stop-loss analysis

Generate the following table.

| Metric | Value |
| --- | --- |
| Trades with trailing SL activated | |
| Percentage of trades with trailing SL activation | |
| Trades saved by trailing SL | |
| Average trailing-stop profit | |
| Maximum trailing-stop profit | |
| Maximum trailing-stop loss | |

---

## Section 8: Suspicious signals

Automatically identify suspicious trades.

Flag trades that contain any of the following:

- Extremely small EMA separation
- Weak crossover
- Direction mismatch
- Low momentum
- Choppy market regime
- Quality score below threshold
- Immediate reversal after entry

Create the following table.

| Time | Direction | Contract | Reason for investigation |
| --- | --- | --- | --- |

---

## Section 9: Trade replay

For every suspicious trade:

Generate a candle-by-candle replay.

Include:

- Entry candle
- Option price movement
- MFE
- MAE
- Every trailing-stop adjustment
- Exit candle
- Exit reason
- Final result

---

## Section 10: Recommendations

Provide:

- What worked today
- What failed today
- Signals that should be investigated
- Whether the trailing-stop logic behaved correctly
- Whether any signal-generation bugs are suspected

---

## Constraints

- Do NOT modify code.
- Do NOT modify the database.
- Do NOT modify the trading engine.
- Do NOT change any configuration.
- Do NOT place any orders.
- Generate only the Markdown report.

Save the final report as:

docs/shadow_session_results/<DD_MMM_YYYY>.md



























# Investigation Task: Generate Today's Paper Trading Results Table From ops_decisions

Objective:

I want to review today's shadow-mode trading performance using the data stored in the database.

Do NOT estimate anything.

Do NOT use assumptions.

Do NOT use summary counts.

Use the actual records.

Focus on today's trading session only.

Date:
2026-08-17

Data sources (use the database, not logs):

- ops_decisions
- shadow outcomes
- paper outcome resolver
- historical_option_candles
- historical_option_contracts
- any other table actually used by shadow_mode attach-outcomes

Important:

The analysis must simulate the trade exactly as the paper-trading engine would manage it.

This analysis MUST include trailing stop-loss behavior.

Do not calculate only the initial stop and target.

Reconstruct the entire trade lifecycle.

For every SIGNAL generated today, create a table with the following columns:

| # | Observed (IST) | Bar (IST) | Direction | Contract | Entry | Initial SL | Initial Target | Exit Price | Exit Reason | MFE | MAE | Trailing SL Activated | Trailing SL Price | Profit/Loss (Points) | Profit/Loss (₹) | Final Result |

Definitions:

Observed (IST):
- generated_at converted to IST

Bar (IST):
- context.bar_ts converted to IST

Exit Reason must be one of:

- Target hit
- Initial stop loss hit
- Trailing stop loss hit
- Timeout
- Ambiguous
- Unresolved

MFE:
- Maximum favorable excursion

MAE:
- Maximum adverse excursion

Trailing SL Activated:
- Yes or No

Profit/Loss (Points):
- Option premium difference

Profit/Loss (₹):
- Calculate using the actual lot size

Final Result:
- WIN
- LOSS
- BREAKEVEN
- AMBIGUOUS
- UNRESOLVED

After generating the table, create a second table containing only completed trades:

| Direction | Trades | Wins | Losses | Win Rate | Total P&L (₹) |

Then create a third table showing the complete ranking:

| Time | Direction | Contract | P&L (₹) |

Sort from highest profit to highest loss.



Then perform a dedicated investigation of this specific trade:

Observed:
11:29:05 IST

Bar:
11:28:00 IST

Direction:
BUY_CE

Contract:
NIFTY18AUG2624300CE

Entry:
49.25

Initial SL:
48.27

Initial Target:
70.04

For this trade, provide:

- Candle-by-candle option price movement after entry
- Whether the initial target was reached
- Whether trailing stop-loss was activated
- Every trailing stop-loss adjustment
- Maximum option price reached
- Final exit price
- Final profit in points
- Final profit in ₹
- Whether this trade is actually the best trade of today's session



Finally, answer these questions:

1. If trailing SL behaved exactly as implemented in production, what would today's total paper-trading P&L be?

2. Which signal generated the highest profit?

3. Which signal generated the highest loss?

4. Would the 11:29:05 BUY_CE trade still be the session's best trade after applying the production trailing-stop algorithm?

Show all calculations and include the SQL queries or source records used to produce the tables.

Do not summarize.

Produce the full dataset.