Run Modes¶
Module: tradeforce @ main.py
The main class Tradeforce offers methods to run the application in different modes:
run(): Run “normal mode”. Connects to the exchange APIs (i.e. to fetch history or trade live)run_sim(): Run simulations (i.e. backtest specific strategies)run_optuna(): Run hyperparameter search with Optuna
General usage:
from tradeforce import Tradeforce
CONFIG = {...}
# Run "normal mode"
Tradeforce(CONFIG).run()
# Run simulations
sim_result = Tradeforce(config=CONFIG).run_sim()
# Run hyperparameter search with Optuna
HYPERPARAM_SEARCH = {...}
study = Tradeforce(CONFIG).run_sim_optuna(optuna_config=HYPERPARAM_SEARCH)
Note
For better understanding and context, please refer to the usage examples and their respective documentation.
Specifc example scripts are referenced in the docstrings of the following run methods:
- class tradeforce.main.Tradeforce(config=None, config_file=None, assets=None)¶
Main application class.
The Tradeforce class orchestrates all modules and components, providing methods to run the application in different modes.
- Parameters:
config (
dict, optional) – A dictionary containing user-defined configuration settings. Eitherconfigorconfig_filehas to be provided.config_file (
str, optional) – A path to ayamlconfiguration file. Can be used instead of passing aconfigdictionary.assets (
List[str], optional) – A list of asset symbols to include. This has to be a subset of the assets available in the market history. If not provided, all assets will be included.
- run(load_history=True)¶
Run Tradeforce in
normal mode.This run method enables primarily following use cases:
- Dedicated market server:
See dedicated_market_server.py in examples.
- Live trading bot:
See live_trader_simple.py in examples.
Warning
Use at your own risk! Tradeforce is currently in beta, and bugs may occur. Furthermore, there is no guarantee that strategies that have performed well in the past will continue to do so in the future.
Note
Custom strategies are not yet available for the live trader.
- Analysis in a Jupyter notebook:
For analysis and visualization of simulation results. See hyperparam_search_result_analysis.ipynb in examples.
- Parameters:
load_history (
bool) – Whether to load the market history on initialization. Default: True.- Return type:
- run_sim(pre_process=None, buy_strategy=None, sell_strategy=None)¶
Run Tradeforce in
simulation mode.Default strategies are used if no custom ones are provided (via parameters
pre_process,buy_strategy,sell_strategy). For reference, how to define custom strategies, see: simulator_custom.pyNote
In Jupyter environment before running a simulation, the history needs to be loaded via
async load_history(). For reference, see: hyperparam_search_result_analysis.ipynb- Parameters:
pre_process (
Optional[Callable]) – An optional function to pre-process market data.buy_strategy (
Optional[Callable]) – An optional function to determine buy signals.sell_strategy (
Optional[Callable]) – An optional function to determine sell signals.
- Returns:
A dictionary containing the following keys:
score (
int):mean(profit subsets) - std(profit subsets). Seetradeforce.simulator.simulator_core.run()for more details.trades (
np.array): Trading history, including buy and sell events.buy_log (
np.array): Buy log, containing the details of each buy event.
- Return type:
dict
- run_sim_optuna(optuna_config, optuna_study=None, pre_process=None, buy_strategy=None, sell_strategy=None)¶
Run Tradeforce in simulation mode
combined with Optuna hyperparameter optimization.
Default strategies are used if no custom ones are provided. For reference, how to define custom strategies, see: simulator_custom.py
Note
In Jupyter environment before running a simulation, the history needs to be loaded via
async load_history(). For reference, see: hyperparam_search_result_analysis.ipynb- Parameters:
optuna_config (
dict) – A dictionary containing the Optuna configuration.optuna_study (
Optional[Study]) – An optional Optuna study object.pre_process (
Optional[Callable]) – An optional function to pre-process market data.buy_strategy (
Optional[Callable]) – An optional function to determine buy signals.sell_strategy (
Optional[Callable]) – An optional function to determine sell signals.
- Returns:
An Optuna study object.
- Return type:
optuna.Study