Skip to content

Instantly share code, notes, and snippets.

@rajvermacas
Last active May 28, 2026 11:36
Show Gist options
  • Select an option

  • Save rajvermacas/6fd3a822ce4eac08106c16ba7e62d169 to your computer and use it in GitHub Desktop.

Select an option

Save rajvermacas/6fd3a822ce4eac08106c16ba7e62d169 to your computer and use it in GitHub Desktop.
KiteTradebook

Analyze the uploaded tradebook using FIFO matching and provide the following metrics only for realized/closed trades.

  1. Overall Metrics
  • Total trades
  • Winning trades
  • Losing trades
  • Win rate %
  • Loss rate %
  • Net realized P&L
  • Charges
  • Average profit %
  • Average loss %
  • Median profit %
  • Median loss %
  • Maximum profit %
  • Maximum loss %
  • Minimum profit %
  • Minimum loss %
  1. Distribution Analysis Show percentage distribution of trades at configurable intervals.

A. Loss distribution Show:

  • 0 to -2
  • -2 to -4
  • -4 to -6
  • -6 to -8
  • <= -8

Include:

  • number of trades
  • percentage of total losing trades

B. Profit distribution Show:

  • 0 to 2
  • 2 to 4
  • 4 to 6
  • ...
  • till 20

Include:

  • number of trades
  • percentage of total winning trades

C. Combined distribution Create non-overlapping intervals from -10 to 20 using 3% buckets: Example:

  • -10 to <-7
  • -7 to <-4
  • -4 to <-1
  • ...
  • 17 to <20
  • =20

For each bucket show:

  • number of trades
  • percentage of total closed trades

Ensure all combined percentages sum exactly to 100%.

  1. Additional Insights
  • Best trade
  • Worst trade
  • Median trade
  • Profit factor
  • Expectancy
  • Largest winning streak
  • Largest losing streak
  1. Optional Filters Allow filtering by:
  • month
  • stock symbol
  • strategy
  • intraday vs swing

Important:

  • Use FIFO matching
  • Ignore open positions unless explicitly requested
  • Use realized P&L only
  • Cross-check totals and percentages before final output
  • Clearly separate winning and losing trade statistics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment