polakowo / vectorbt

Find your trading edge, using the fastest engine for backtesting, algorithmic trading, and research.
https://vectorbt.dev
Other
4.33k stars 618 forks source link

Long / Short Position Stats #90

Closed kaleming closed 3 years ago

kaleming commented 3 years ago

Hello,

First of all, you are doing an amazing project. Congrats.

My question:

When I run portfolio.stats() my output shows:

Start                                   0
End                                     6
Duration                  0 days 00:21:00
Init. Cash                            100
Total Profit                           -5
Total Return [%]                       -5
Benchmark Return [%]                  -15
Position Coverage [%]             57.1429
Max. Drawdown [%]                 21.7391
Avg. Drawdown [%]                 11.3696
Max. Drawdown Duration    0 days 00:06:00
Avg. Drawdown Duration    0 days 00:06:00
Num. Trades                             2
Win Rate [%]                           50
Best Trade [%]                         15
Worst Trade [%]                  -19.0476
Avg. Trade [%]                   -2.02381
Max. Trade Duration       0 days 00:06:00
Avg. Trade Duration       0 days 00:06:00
Expectancy                           -2.5
SQN                             -0.142857
Gross Exposure                   0.543133
Sharpe Ratio                     -5.41009
Sortino Ratio                    -7.42934
Calmar Ratio                         -4.6

Is there any way to get detailed stats from long and short positions ?

Something like:

Short Positions (won %): 70%
Long Positions  (won %): 61%

Short Positions (Gross): $1,000.00
Long Positions  (Gross): $1,700.00

Long Trades:   1 102 (51.04%) # Number of deals
Short Trades:  1 057 (48.96%) # Number of deals
polakowo commented 3 years ago

See https://polakowo.io/vectorbt/docs/portfolio/trades.html, for example portfolio.trades.short.win_rate().

kaleming commented 3 years ago

Thanks @polakowo