A backtesting library for MetaTrader5
Project description
tradetestlib
: A MetaTrader5 backtesting tool
tradetestlib
is a backtesting library built to integrate with MetaTrader5, with the purpose being able to provide a broad overview of a trading strategy/idea, more specifically, an evaluation of a strategy. Some of the main evaluation metrics used in this project are the sharpe ratio, and profit factor.
tradetestlib
also provides the option to optimize a strategy by using a Grid Search algorithm for hyperparameter tuning.
Currently, hyperparameters are limited to position sizing, and exposure.
A demonstration can be found here
Installation
tradetestlib
can be installed with pip
pip install tradetestlib
Usage
A simulation instances can be created by calling the Simulation class.
symbol
and timeframe
are only used for naming conventions, for comparing a basket of assets.
train_raw
and test_raw
are dataframes that contain Open, High, Low, Close, signal, and true_signal
columns.
lot
is the lot size used to trade
starting_balance
is the initial deposit of the simulation in USD.
from tradetestlib import Simulation
sim = Simulation(
symbol = symbol,
timeframe = tf,
train_raw = train,
test_raw = test,
lot = 1,
starting_balance = 100000
)
Optimization can be used by creating a params
dictionary with the required hyperparameters.
run_grid_search
returns the optimal configuration, and overall testing set.
Optimized hyperparameters may also be accessed as attributes, which can then be used to create a final simulation instance, to verify result with the test set.
from tradetestlib import Optimize
params = {
'lot' : [1,2],
'hold_time': [5, 10],
'max_loss': [0.005, 0.01]
}
o = Optimize(symbol = symbol,
timeframe = tf,
train = train,
test = test,
metric = 'sharpe_ratio',
how = 'maximize')
best, df = o.run_grid_search(params)
o.optimized_lot # best lot
o.optimized_holdtime # best holdtime
o.optimized_max_loss # best exposure
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tradetestlib-1.0.1.tar.gz
.
File metadata
- Download URL: tradetestlib-1.0.1.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80064815bca8ec7a73f8b8be90f822ac89a4b3a0b8d79a3db702176f277217bf |
|
MD5 | 1394a80d5e99d5ea30dcc576753ea688 |
|
BLAKE2b-256 | 9a89665ebec700df38174dd3caeda29120291d1f29ad16d33dbc941eb4895530 |
File details
Details for the file tradetestlib-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: tradetestlib-1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f26890b4ee7d41a9d3bc8c5502f63834a39346563a93e0b4fceb48c75604e61 |
|
MD5 | 393aaaecdbc1fbc13d52a9d4bbae07b7 |
|
BLAKE2b-256 | 82a4ad7f8e39f409fd9873d42171bc4522dea3886463e5a2f86be7b2e0f18674 |