Module areix_io.base

Classes

class Base

The Base class for runner

Ancestors

  • abc.ABC

Subclasses

Methods

def critical(self, content)

Logging function in critical level

Args

content : str
content you would like to print out
def debug(self, content)

Logging function in debug level

Args

content : str
content you would like to print out
def error(self, content)

Logging function in error level

Args

content : str
content you would like to print out
def finish(self)

The function will be invoked after backtesting complete

def info(self, content)

Logging function in info level

Args

content : str
content you would like to print out
def initialize(self)

The function will be invoked before backtesting starts

def on_market_close(self)

The function will be invoked when market closes

def on_market_start(self)

The function will be invoked when market starts

def run(self, tick)

The core functon that will be invoked in every tick

The run function must be implemented.

Args

tick : [datetime]
datetime of current bar
def warning(self, content)

Logging function in warning level

Args

content : str
content you would like to print out
class BrokerBase

Broker Base

Ancestors

Subclasses

Methods

def order(self)

Inherited members

class Context (feed=None, cash=100000, tradedays=None, broker=None, strategy=None, benchmark=None, backtest=None)

The Context class which stored all the shared data

Args

feed : dict
  • The data feed for backtesting
  • The key would be instrument name and the value would be a DataFrame
tick : datetime
  • The current datetime of tick
bar_data : dict
  • The bar data at the current tick
  • The key would be instrument name and the value would be a DataFrame
hist_data : dict
  • The list of historical bar data until the current tick
  • The key would be instrument name and the value would be a list of DataFrame
latest_price : dict
  • The current datetime of tick
  • The key would be instrument name and the value would be the moment of price (according to BackTest.trade_at)
tradedays : DataFrame
  • The trading calendar
initial_cash : int
  • The initial cash amount
available_cash : int
  • The available cash amount
benchmark : DataFrame
  • The benchmark for calculate the statistics and plot the graph.
strategy : Strategy
  • The instance of Strategy class
broker : Broker
  • The instance of Broker class
backtest : BackTest
  • The instance of BackTest class
order_records : list
  • The list of orders
trade_records : list
  • The list of trades
closed_trade_records : list
  • The list of closed trades
pnls : list
  • The list of dict which contains the daily P&Ls
position : dict
  • The dict which contains the value of the instrument
  • The key would be instrument name and the value would be the instrument dict

Instance variables

var assets_value

Entire asset value (portfolio value + available cash)

Returns

[float]
return the entire asset value
var holding_number

number of holdings

Returns

[int]
return the number of holdings
var holding_value

Entire portfolio value

Returns

[float]
return the entire portfolio value

Methods

def get_position(self, code)

get the selected position

Args

code : [str]
instrument name

Returns

[dict]
return the requested position
def get_quantity(self, code)

get the quantity of selected position

Args

code : [str]
instrument name

Returns

[float]
return the quantity of requested position
def get_value(self, code)

get the value of selected position

Args

code : [str]
instrument name

Returns

[float]
return the market value of requested position