@@ -87,7 +87,7 @@ def I(self, # noqa: E743
87
87
`backtesting.backtesting.Strategy.data` is.
88
88
Returns `np.ndarray` of indicator values.
89
89
90
- `func` is a function that returns the indicator array of
90
+ `func` is a function that returns the indicator array(s) of
91
91
same length as `backtesting.backtesting.Strategy.data`.
92
92
93
93
In the plot legend, the indicator is labeled with
@@ -245,12 +245,12 @@ def data(self) -> _Data:
245
245
return self ._data
246
246
247
247
@property
248
- def position (self ):
248
+ def position (self ) -> 'Position' :
249
249
"""Instance of `backtesting.backtesting.Position`."""
250
250
return self ._broker .position
251
251
252
252
@property
253
- def orders (self ):
253
+ def orders (self ) -> 'Orders' :
254
254
"""Instance of `backtesting.backtesting.Orders`."""
255
255
return self ._broker .orders
256
256
@@ -459,11 +459,11 @@ def __repr__(self):
459
459
return '<Broker: {:.0f}{:+.1f}>' .format (self ._cash , self .position .pl )
460
460
461
461
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
463
463
self .orders ._update (price , sl , tp )
464
464
465
465
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
467
467
self .orders ._update (price , sl , tp , is_long = False )
468
468
469
469
def close (self ):
@@ -602,20 +602,20 @@ def __init__(self,
602
602
or a monotonic range index (i.e. a sequence of periods).
603
603
604
604
`strategy` is a `backtesting.backtesting.Strategy`
605
- _subclass_ (not instance).
605
+ _subclass_ (not an instance).
606
606
607
607
`cash` is the initial cash to start with.
608
608
609
609
`commission` is the commision ratio. E.g. if your broker's commission
610
610
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
612
612
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.
614
614
615
615
`margin` is the required margin (ratio) of a leveraged account.
616
616
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) .
619
619
620
620
If `trade_on_close` is `True`, market orders will be executed
621
621
with respect to the current bar's closing price instead of the
@@ -736,7 +736,8 @@ def optimize(self,
736
736
If `return_heatmap` is `True`, besides returning the result
737
737
series, an additional `pd.Series` is returned with a multiindex
738
738
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()`).
740
741
741
742
Additional keyword arguments represent strategy arguments with
742
743
list-like collections of possible values. For example, the following
0 commit comments