Skip to content

Commit 332079b

Browse files
committed
DOC: Docstring updates
1 parent 5051b61 commit 332079b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

backtesting/backtesting.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def I(self, # noqa: E743
8787
`backtesting.backtesting.Strategy.data` is.
8888
Returns `np.ndarray` of indicator values.
8989
90-
`func` is a function that returns the indicator array of
90+
`func` is a function that returns the indicator array(s) of
9191
same length as `backtesting.backtesting.Strategy.data`.
9292
9393
In the plot legend, the indicator is labeled with
@@ -245,12 +245,12 @@ def data(self) -> _Data:
245245
return self._data
246246

247247
@property
248-
def position(self):
248+
def position(self) -> 'Position':
249249
"""Instance of `backtesting.backtesting.Position`."""
250250
return self._broker.position
251251

252252
@property
253-
def orders(self):
253+
def orders(self) -> 'Orders':
254254
"""Instance of `backtesting.backtesting.Orders`."""
255255
return self._broker.orders
256256

@@ -459,11 +459,11 @@ def __repr__(self):
459459
return '<Broker: {:.0f}{:+.1f}>'.format(self._cash, self.position.pl)
460460

461461
def buy(self, price=None, sl=None, tp=None):
462-
assert (sl or -np.inf) <= (price or self.last_close) <= (tp or np.inf), (sl, price or self.last_close, tp) # noqa: E501
462+
assert (sl or -np.inf) <= (price or self.last_close) <= (tp or np.inf), "For long orders should be: SL ({}) < BUY PRICE ({}) < TP ({})".format(sl, price or self.last_close, tp) # noqa: E501
463463
self.orders._update(price, sl, tp)
464464

465465
def sell(self, price=None, sl=None, tp=None):
466-
assert (tp or -np.inf) <= (price or self.last_close) <= (sl or np.inf), (tp, price or self.last_close, sl) # noqa: E501
466+
assert (tp or -np.inf) <= (price or self.last_close) <= (sl or np.inf), "For short orders should be: TP ({}) < BUY PRICE ({}) < SL ({})".format(tp, price or self.last_close, sl) # noqa: E501
467467
self.orders._update(price, sl, tp, is_long=False)
468468

469469
def close(self):
@@ -602,20 +602,20 @@ def __init__(self,
602602
or a monotonic range index (i.e. a sequence of periods).
603603
604604
`strategy` is a `backtesting.backtesting.Strategy`
605-
_subclass_ (not instance).
605+
_subclass_ (not an instance).
606606
607607
`cash` is the initial cash to start with.
608608
609609
`commission` is the commision ratio. E.g. if your broker's commission
610610
is 1% of trade value, set commission to `0.01`. Note, if you wish to
611-
account for bid-ask spread, you approximate doing so by increasing
611+
account for bid-ask spread, you cam approximate doing so by increasing
612612
the commission, e.g. set it to `0.0002` for commission-less forex
613-
trading where average spread is roughly 0.2‰ of asking price.
613+
trading where the average spread is roughly 0.2‰ of asking price.
614614
615615
`margin` is the required margin (ratio) of a leveraged account.
616616
No difference is made between initial and maintenance margins.
617-
To run the backtest using e.g. 50:1 leverge your broker allows,
618-
set margin to `0.02`.
617+
To run the backtest using e.g. 50:1 leverge that your broker allows,
618+
set margin to `0.02` (1 / leverage).
619619
620620
If `trade_on_close` is `True`, market orders will be executed
621621
with respect to the current bar's closing price instead of the
@@ -736,7 +736,8 @@ def optimize(self,
736736
If `return_heatmap` is `True`, besides returning the result
737737
series, an additional `pd.Series` is returned with a multiindex
738738
of all admissible parameter combinations, which can be further
739-
inspected or projected onto 2D to plot a heatmap.
739+
inspected or projected onto 2D to plot a heatmap
740+
(see `backtesting.backtesting.lib.plot_heatmaps()`).
740741
741742
Additional keyword arguments represent strategy arguments with
742743
list-like collections of possible values. For example, the following

0 commit comments

Comments
 (0)