Skip to main content

A backtesting library built 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

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.

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

tradetestlib-0.1.0.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

tradetestlib-0.1.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file tradetestlib-0.1.0.tar.gz.

File metadata

  • Download URL: tradetestlib-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for tradetestlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2dce0536bfe7d7d710ca9fbfc9dc299a07877c2635a1521a8e91a523a7cf4d7c
MD5 12f88822ce9f2048994411433480f75d
BLAKE2b-256 4fea6164c93c7d6625a6fe29596e0789ea3fbb9d0dfb295538c75c2958f1a4f2

See more details on using hashes here.

File details

Details for the file tradetestlib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tradetestlib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for tradetestlib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ff8a8db8230de54d7a9e1d90be43e8199f98f8f1b99c8377b7e0138b6186f33
MD5 abf0354c50728d383e359559bd107afc
BLAKE2b-256 69d1145412598b9fb0cc016497d4d6d62b7ebfe9530709a0b836f018edcf3476

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page