kernc / kernc/backtesting.py

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

Open
#1,309 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Enhancement description

In addition to the `#Trades` I would also like to see the `#Short Trades` and `#Long Trades` as I would like to gauge how balanced are my bull and bear models. In addition, a bulls to bears ratio would be best as the ideal would be approximately 1 for perfectly balanced: `#Short Trades / (#Long Trades + 1e-10)`

```
Start 2025-09-01 00:00...
End 2025-09-07 09:00...
Duration 6 days 09:00:00
Exposure Time [%] 24.67532
Equity Final [$] 105.6097
Equity Peak [$] 107.64386
Commissions [$] 8.60254
Return [%] 5.6097
Buy & Hold Return [%] 2.37975
Return (Ann.) [%] 306.45261
Volatility (Ann.) [%] 130.1985
CAGR [%] 2175.93476
Sharpe Ratio 2.35373
Sortino Ratio 22.70538
Calmar Ratio 162.16873
Alpha [%] 5.22595
Beta 0.16126
Max. Drawdown [%] -1.88971
Avg. Drawdown [%] -0.43725
Max. Drawdown Duration 1 days 18:00:00
Avg. Drawdown Duration 0 days 15:00:00
# Trades 23
Win Rate [%] 65.21739
Best Trade [%] 1.77771
Worst Trade [%] -0.52609
Avg. Trade [%] 0.25156
Max. Trade Duration 0 days 01:00:00
Avg. Trade Duration 0 days 01:00:00
Profit Factor 3.39641
Expectancy [%] 0.25339
SQN 1.93883
Kelly Criterion 0.45458
_strategy KSpotTradingStra...
_equity_curve ...
_trades Size EntryB...
dtype: object
```

### Code sample

```python

```

### Additional info, images

_No response_

Contributor guide

Open the contributing guide

Research direction

Locate the code that assembles the output report and the existing # Trades statistic, then trace how long and short trade directions are represented. Check the report-related tests or run the relevant test suite before making changes. Done means the report includes # Short Trades, # Long Trades, and the requested short-to-long ratio with the stated small denominator safeguard.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
analytics
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.