Module areix_io.backtest
Classes
class BackTest (feed, StrategyClass, tradedays, commission_rate=0.001, min_commission=0, trade_at='close', cash=200000, slippage=0.0, benchmark=None, allow_ss=False, logger=None, store_path='.')
-
Args
feed
:[dict]
-
- The data feed for backtesting
- The key would be instrument name and the value would be a DataFrame
StrategyClass
:Strategy
-
- The
Strategy
class
- The
tradedays
:DataFrame
-
- The trading calendar
commission_rate
:float
, optional-
- The commission rate.
- Defaults to 0.001.
min_commission
:int
, optional-
- The minimum commission that will be deducted.
- Defaults to 0.
trade_at
:str
, optional-
- The moment of price that would be executed for
Market
order. - Defaults to 'close'.
- The moment of price that would be executed for
cash
:int
, optional-
- The cash amount that you would like to exercise in the backtesting
- Defaults to 200000.
slippage
:float
, optional-
- The percentage of slippage that would be happened during backtesting.
- Defaults to 0.0.
benchmark
:DataFrame
, optional-
- The benchmark for calculate the statistics and plot the graph.
- Defaults to None.
allow_ss
:bool
, optional-
- If allow_ss is True, the
Broker
will allow to perform short selling - Defaults to False.
- If allow_ss is True, the
logger
:logger
, optional-
- You custom logger if any
- Defaults to None.
store_path
:str
, optional-
- The base path to store all the output from backtesting
- Defaults to '.'.
Class variables
var path
Methods
def add_hook(self, HookClass, hook_type='post')
-
Add your customized hook
Args
HookClass
:Base
- The class must be inherited from
Base
hook_type
:str
, optional- The hook type which decides it will be invoked before or after the
Strategy
. Defaults to 'post'.
def add_runner(self, runner)
-
Add your customized runner
All the runner will bind to a
Context
object for sharing all the data in the backtest.Args
runner
:Base
- The class must be inherited from
Base
def contest_output(self, prefix='')
-
Generate all the contest required output at once
Args
prefix
:str
, optional- prefix of file name. Defaults to ''.
def plot(self, path, interactive=False, **kwargs)
-
The function to plot the diagram.
Args
path
:str
- The path that you would like to store the generated chart.
interactive
:bool
, optional- Decide whether generated chart is interactive or not. Defaults to False.
def start(self)
-
The function to kick start the backtesting process