|
1 | 1 | """
|
2 |
| -Core backtesting data structures. |
3 |
| -Objects from this module can be imported from the top-level |
| 2 | +Core framework data structures. |
| 3 | +Objects from this module can also be imported from the top-level |
4 | 4 | module directly, e.g.
|
5 | 5 |
|
6 | 6 | from backtesting import Backtest, Strategy
|
| 7 | +
|
| 8 | +.. warning:: v0.2.0 breaking changes |
| 9 | + Version 0.2.0 introduced some **breaking API changes**. For quick ways to |
| 10 | + migrate existing 0.1.x code, see the implementing |
| 11 | + [pull request](https://github.com/kernc/backtesting.py/pull/47/). |
7 | 12 | """
|
8 | 13 | import multiprocessing as mp
|
9 | 14 | import os
|
@@ -962,7 +967,7 @@ def __init__(self,
|
962 | 967 | To run the backtest using e.g. 50:1 leverge that your broker allows,
|
963 | 968 | set margin to `0.02` (1 / leverage).
|
964 | 969 |
|
965 |
| - If `trade_on_close` is `True`, market orders will be executed |
| 970 | + If `trade_on_close` is `True`, market orders will be filled |
966 | 971 | with respect to the current bar's closing price instead of the
|
967 | 972 | next bar's open.
|
968 | 973 |
|
@@ -1029,6 +1034,37 @@ def run(self, **kwargs) -> pd.Series:
|
1029 | 1034 | Run the backtest. Returns `pd.Series` with results and statistics.
|
1030 | 1035 |
|
1031 | 1036 | Keyword arguments are interpreted as strategy parameters.
|
| 1037 | +
|
| 1038 | + >>> Backtest(GOOG, SmaCross).run() |
| 1039 | + Start 2004-08-19 00:00:00 |
| 1040 | + End 2013-03-01 00:00:00 |
| 1041 | + Duration 3116 days 00:00:00 |
| 1042 | + Exposure Time [%] 93.9944 |
| 1043 | + Equity Final [$] 51959.9 |
| 1044 | + Equity Peak [$] 75787.4 |
| 1045 | + Return [%] 419.599 |
| 1046 | + Buy & Hold Return [%] 703.458 |
| 1047 | + Max. Drawdown [%] -47.9801 |
| 1048 | + Avg. Drawdown [%] -5.92585 |
| 1049 | + Max. Drawdown Duration 584 days 00:00:00 |
| 1050 | + Avg. Drawdown Duration 41 days 00:00:00 |
| 1051 | + # Trades 65 |
| 1052 | + Win Rate [%] 46.1538 |
| 1053 | + Best Trade [%] 53.596 |
| 1054 | + Worst Trade [%] -18.3989 |
| 1055 | + Avg. Trade [%] 2.35371 |
| 1056 | + Max. Trade Duration 183 days 00:00:00 |
| 1057 | + Avg. Trade Duration 46 days 00:00:00 |
| 1058 | + Profit Factor 2.08802 |
| 1059 | + Expectancy [%] 8.79171 |
| 1060 | + SQN 0.916893 |
| 1061 | + Sharpe Ratio 0.179141 |
| 1062 | + Sortino Ratio 0.55887 |
| 1063 | + Calmar Ratio 0.049056 |
| 1064 | + _strategy SmaCross |
| 1065 | + _equity_curve Eq... |
| 1066 | + _trades Size EntryB... |
| 1067 | + dtype: object |
1032 | 1068 | """
|
1033 | 1069 | data = _Data(self._data.copy(deep=False))
|
1034 | 1070 | broker = self._broker(data=data) # type: _Broker
|
@@ -1160,7 +1196,7 @@ def __getattr__(self, item):
|
1160 | 1196 | raise ValueError('No admissible parameter combinations to test')
|
1161 | 1197 |
|
1162 | 1198 | if len(param_combos) > 300:
|
1163 |
| - warnings.warn('Searching best of {} configurations.'.format(len(param_combos)), |
| 1199 | + warnings.warn('Searching for best of {} configurations.'.format(len(param_combos)), |
1164 | 1200 | stacklevel=2)
|
1165 | 1201 |
|
1166 | 1202 | heatmap = pd.Series(np.nan,
|
@@ -1367,7 +1403,7 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
|
1367 | 1403 | a separate drawdown graph section.
|
1368 | 1404 |
|
1369 | 1405 | If `smooth_equity` is `True`, the equity graph will be
|
1370 |
| - interpolated between points of cash-only positions, |
| 1406 | + interpolated between fixed points at trade closing times, |
1371 | 1407 | unaffected by any interim asset volatility.
|
1372 | 1408 |
|
1373 | 1409 | If `relative_equity` is `True`, scale and label equity graph axis
|
|
0 commit comments