polakowo / vectorbt

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

Constant Position Sizing #195

Closed systats closed 8 months ago

systats commented 3 years ago

Hi great package! I wondered whether it is it possible to have constant position size of 100$ to prevent compounding metrics and to interpret total profits in percents? Thanks for suggestions.

polakowo commented 3 years ago

Pass size_type=‘value’ (https://vectorbt.dev/docs/portfolio/enums.html#vectorbt.portfolio.enums.SizeType)

systats commented 3 years ago

Hi Polakowo,

I compare different backtesting tools to spot bugs and to increase trust into our open source work. So far I got 4 packages and we can sparsely compare the metrics. First of all I very happy that there is already a lot of constituency. Some questions remain though:

1.) The biggest difference so far is drawdown. Any ideas why this metric is all over the place? 2.) Is there any chance that you can expand the metrics to include for example return_mean, equity_last, equity_max, win_ratio, or win_sd/loss_sd? I will do the same for backer. I tried Pass size_type=‘value’ but it didnt change anything. Although beside equity_cum nothing else seems cumulative.

        var         backer     quantstrat  vectorbt      PA
1  equity_last        307.08     297.04        -       -
2   equity_cum       1231.55          -  1231.55 1231.55
3   equity_max        310.81     311.32        -       -
4    return_sd          8.21       8.27        -    8.21
5  return_mean          2.01       2.07        -    2.01
6     time_exp          0.41          -     0.41       -
7    down_mean         -5.28          -    -1.05   -8.84
8     down_max        -19.76     -43.08    -30.2  -18.52
9    win_ratio          2.20       2.97        -       -
10    win_rate          0.44       0.43     0.44       -
11    win_mean          8.41       8.81     2.01       -
12     win_max         43.56      44.22    43.61       -
13      win_sd          8.68          -        -    8.68
14     win_sum        563.62     572.37        -       -
15   loss_mean         -2.98      -2.96        -       -
16    loss_sum       -256.54    -257.94        -       -
17     loss_sd          2.09          -        -    2.09
18    loss_max         -9.74      -9.87    -9.75       -
19     loss_05         -6.32          -        -   -5.67
20     sortino          0.96          -        -    0.74
21      calmar          0.38        6.9        -    7.62
22    n_trades        153.00        152      153       -

There are a few bugs also on my side so I have also to fix some stuff. The following metrics are already in the dictionary in case you spot an issue.

equity_cum = total_profit
time_exp = gross_exposure
down_max = -max_drawdown_percent
down_mean = -avg_drawdown_percent
win_max = best_trade_percent
win_mean = avg_trade_percent
loss_max = worst_trade_percent
win_rate = win_rate_percent/100
n_trades = trade_count

Thanks for your helpful answers.

polakowo commented 3 years ago

@systats

Sorry for any typos, I’m not near my computer right now.

systats commented 3 years ago

I am on the way to normalize all experiments and so far I really like vectorbt.