Skip to content

Add # Long Trades and # Short Trades to stats output#1349

Open
wavebyrd wants to merge 1 commit intokernc:masterfrom
wavebyrd:add-long-short-trade-counts
Open

Add # Long Trades and # Short Trades to stats output#1349
wavebyrd wants to merge 1 commit intokernc:masterfrom
wavebyrd:add-long-short-trade-counts

Conversation

@wavebyrd
Copy link

Summary

Add two new statistics to the backtest results output:

  • # Long Trades: count of trades with positive size (long positions)
  • # Short Trades: count of trades with negative size (short positions)

Example output

# Trades                                   23
# Long Trades                              15
# Short Trades                              8
Win Rate [%]                         65.21739

Motivation

This helps users gauge how balanced their bull and bear models are without needing to manually filter the trades dataframe. As noted in the issue, this is useful for understanding strategy behavior.

Implementation

Simple addition in _stats.py - counts trades based on the sign of the Size column:

  • Size > 0 = long trade
  • Size < 0 = short trade

Test plan

  • Existing tests pass (new stats computed alongside existing ones)
  • Verify counts match manual filtering of trades dataframe

Fixes #1309

🤖 Generated with Claude Code

Add two new statistics to the backtest results:
- # Long Trades: count of trades with positive size (buy positions)
- # Short Trades: count of trades with negative size (sell positions)

This helps users understand the balance between bullish and bearish
positions in their strategies without needing to manually filter
the trades dataframe.

Fixes kernc#1309

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@wavebyrd
Copy link
Author

Friendly ping on this feature addition. Let me know if you'd like any changes to the implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include the number of long and short trades in the output report

1 participant