diff --git a/backtesting/_plotting.py b/backtesting/_plotting.py index c0283577..d4dcfeb7 100644 --- a/backtesting/_plotting.py +++ b/backtesting/_plotting.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import re import sys diff --git a/backtesting/_stats.py b/backtesting/_stats.py index 09a30f07..2d8de0ca 100644 --- a/backtesting/_stats.py +++ b/backtesting/_stats.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import TYPE_CHECKING, List, Union import numpy as np diff --git a/backtesting/_util.py b/backtesting/_util.py index 9d8c5edd..f1bbd527 100644 --- a/backtesting/_util.py +++ b/backtesting/_util.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import warnings from numbers import Number from typing import Dict, List, Optional, Sequence, Union, cast diff --git a/backtesting/backtesting.py b/backtesting/backtesting.py index d90f4b2f..19312f12 100644 --- a/backtesting/backtesting.py +++ b/backtesting/backtesting.py @@ -5,6 +5,9 @@ from backtesting import Backtest, Strategy """ + +from __future__ import annotations + import multiprocessing as mp import os import sys @@ -200,9 +203,10 @@ def buy(self, *, stop: Optional[float] = None, sl: Optional[float] = None, tp: Optional[float] = None, - tag: object = None): + tag: object = None) -> 'Order': """ - Place a new long order. For explanation of parameters, see `Order` and its properties. + Place a new long order and return it. For explanation of parameters, see `Order` + and its properties. See `Position.close()` and `Trade.close()` for closing existing positions. @@ -218,9 +222,10 @@ def sell(self, *, stop: Optional[float] = None, sl: Optional[float] = None, tp: Optional[float] = None, - tag: object = None): + tag: object = None) -> 'Order': """ - Place a new short order. For explanation of parameters, see `Order` and its properties. + Place a new short order and return it. For explanation of parameters, see `Order` + and its properties. See also `Strategy.buy()`. @@ -745,7 +750,7 @@ def new_order(self, tp: Optional[float] = None, tag: object = None, *, - trade: Optional[Trade] = None): + trade: Optional[Trade] = None) -> Order: """ Argument size indicates whether the order is long or short """ diff --git a/backtesting/lib.py b/backtesting/lib.py index d66d5d00..6164c86f 100644 --- a/backtesting/lib.py +++ b/backtesting/lib.py @@ -11,6 +11,8 @@ [issue tracker]: https://github.com/kernc/backtesting.py """ +from __future__ import annotations + from collections import OrderedDict from inspect import currentframe from itertools import compress diff --git a/backtesting/test/__init__.py b/backtesting/test/__init__.py index 142d2498..e1de19e6 100644 --- a/backtesting/test/__init__.py +++ b/backtesting/test/__init__.py @@ -1,4 +1,7 @@ """Data and utilities for testing.""" + +from __future__ import annotations + import pandas as pd