Q26 ALPHA-TRADING SYSTEM
Public Member Functions | Public Attributes | List of all members
SIMULATION Class Reference

Public Member Functions

def __init__ (self, PORTFOLIO_LIST, PRICE_TABLE)
 
def importStrategy (self)
 Description : More...
 
def set_database (self, client_id=0, name="Unamed", path="./", model="sqlite3", log=False, tables=[])
 Description : More...
 
def parametersCheck (self)
 Description : More...
 
def run (self, mode="sequential", idx=None, latency=0)
 Description : More...
 
def initiatePortfolios (self, mode=None, idx=None, latency=None)
 
- Public Member Functions inherited from ANALYSIS
def showEquityCurve (self, index=[], labels=list(), xTime=False, y_scale="linear", y_lim=None, x_lim=None, x_label="# of transaction", y_label="Equity Curve", x_rotation=45, subCurve=None, linestyle="-", marker=None)
 Description : More...
 
- Public Member Functions inherited from WRITER
def sayHello (self)
 
def writeClosedPositionsFile (self, index=0, outputFile="./closedPositions", ext="csv", onlyColumns=[], exceptColumns=[], renameColumns={"possibleClosePrice" :"closePrice", "possibleCloseDate" :"closeDate"}, equityCurve=True)
 

Public Attributes

 portfolio
 
 priceTable
 
 startIndex
 
 stopIndex
 
 subLoopModel
 
 maxHstDataSize
 
 strategyPath
 
 strategyFile
 
 strategy
 
 verbose
 
 logEvery
 
 hideWarnings
 

Detailed Description


Q26 - QuanTester module - SIMULATION(ANALYSIS, WRITER) object.

Description :

Main class of the Q26 QuanTester module. This object is dedicated to 
initialize the simulation parameters and output the simulation 
results. 

Examples :

Planned developments :

Known bugs :

Member Function Documentation

◆ importStrategy()

def importStrategy (   self)

Description :

This function allows to import strategy files as a strategy module. 
If a given strategy is imported number of times (the strategyFiles and 
strategyPath lists contain a multiplicity of the same file/path), the 
imported strategy modules are independent one from each others. 

Parameters :

None 

Returns :

None 

◆ parametersCheck()

def parametersCheck (   self)

Description :

This function checks that everything is fine before running the 
simulation. 
!!! This function is not working yet !!! 

Parameters :

None 

Returns :

None 

◆ run()

def run (   self,
  mode = "sequential",
  idx = None,
  latency = 0 
)

Description :

Main function of the simulation. This function initiate the time 
loop where at each time step, a new price is presented to the 
portfolio. 

Parameters :

- mode [int] = "sequential" : Drives the way for the simulation to 
                              be done. The different parameters are : 
                                  - "sequential" : every couple portfolio/strategy is updated at each time step 
                                  - "linear" : the algorithm simulate sequentially each couple portfolio/strategy 
                                  - "unique" : given an idx index, only the couple indexed by idx is simulated 
- idx [int] = None : If mode == "unique", this parameters represent the index of the couple portfolio/strategy 
                     to be backtested.

Returns :

None 

◆ set_database()

def set_database (   self,
  client_id = 0,
  name = "Unamed",
  path = "./",
  model = "sqlite3",
  log = False,
  tables = [] 
)

Description :

This function allows to create a database associated with a PORTFOLIO indexed with the 
**client_id** variable. If this method is not called, no database will be created. 

Parameters :

- client_id = 0     [int]: Index of the current portfolio 
- name = "Unamed"   [str]: Name of the database file as it will be saved on the user system 
- path = "./"       [str]: Path at which the database will be saved on the system 
- model = "sqlite3" [str]: Model of database to be used. 
                           The choices are: 
                                - "sqlite3": A light and easy-to-use database model 
- log = False       [bool]: If True, the system will generate a table named **log** in which 
                            each action element stored in the list PORTFOLIO.trading_log_actions 
                            will be stored at each simulation time step.  
- tables = [] [list(dict)]: This parameters allows the user to create custom tables to his/her database. 
                            Each element of the list **tables** has a dictionnary structure as 
                            here below: 
                              {"name"     : "custom_table_name", 
                               "structure": structure} 
                            where the **name** key refers to the name of the custom table as it will be 
                            stored in the database and the key **structure** is itself another dictionnary of 
                            the following structure: 
                               {"attribute_name_1" : "pythonic-type", 
                                "attribute_name_2" : "pythonic-type", 
                                ...}
                            where the keys refers to the name of the columns to be stored in the table (note that 
                            space character is not allowed in the keys, otherwise one will lead to an error in the 
                            database module), and the associated values refers to the data type to be stored (in 
                            python3 format and wrapped in a string character).

Returns :

None 

Member Data Documentation

◆ hideWarnings

hideWarnings

Hide warnings

Type: boolean
Defaut value : False
Description: If True, all the simulation warnings will be ignored.

◆ logEvery

logEvery

Log frequency

Type : integer
Defaut value : 100
Description : If logEvery = 100, each 100 timestep (without considering subcandle timesteps) the code will print the simulation advancement and run the function .show() in each strategy.STRAGEY() class.

◆ maxHstDataSize

maxHstDataSize

Historical data buffer size

Type : integer
Defaut value : 1000
Description :
This value defines the size of the buffer allowed to store any historical data price to be accessible by the trading strategies the function : getHistoricalData.

◆ portfolio

portfolio

PORTFOLIO class object.

Type : class PORTFOLIO()
Description :
This object contains the portfolio informations

◆ priceTable

priceTable

PRICE_TABLE class object.

Type : class PRICE_TABLE()
Description :
This object contains the global price dataset.

◆ startIndex

startIndex

Intial index of the simulation.

Type : integer
Defaut value : 0
Description :
This index corresponds to the first available index in the datasets dedicated to simulate the price evolution.

◆ stopIndex

stopIndex

Ending index of the simulation.

Type : integer
Defaut value : 99999999999999
Description :
This index corresponds to the last available index in the datasets dedicated to simulate the price evolution.

◆ strategy

strategy

Strategy module list

Type : list[python module]
Defaut value : list()
Description :
This list contains all the imported strategy modules. In case of a
simulation with one strategy have been duplicated, every strategy element in this list is independant.

◆ strategyFile

strategyFile

Strategy file list

Type : list[string]
Defaut value : list()
Description :
This list contains all the strategy file names (without the .py extension). It follows the same structure as for the strategy path list.

◆ strategyPath

strategyPath

Strategy path list

Type : list[string]
Defaut value : list()
Description :
This list contains all the paths to the trading strategy to be used in the simulation. In case of Monte Carlo type simulations of one trading strategy with parameter variations, the same path have to be inserted the number of times as the number of variations of the strategy parameters to be simulated.

◆ subLoopModel

subLoopModel

Model used to cross prices below the candle resolution

Type : string
Values :

  • "ohlc standard" : Prices are presented in the following order, open -> high -> low -> close
  • "close only" : Only close price is presented

Description :
The backtest simulation is defined by presenting a succession of candle sampled price, each candle being defined by : Open, High, Low, Close. The models define how the prices are successively presented to the portfolio at timescales below the candle resolution.

◆ verbose

verbose

Debug mode

Type : boolean
Defaut value : False
Description : If True, the simulation will print a lot of debug informations.
Warning : This parameter is not fully functionnal yet.


The documentation for this class was generated from the following file: