Skip to content

Boulougou/trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trading-bot

trading-bot is a command line tool that uses FXCM Rest API and Pytorch (through tch-rs) in order to train and apply a model (a simple Neural Network with a single hidden layer) for forex trading.

The following commands are supported :

  • fetch - used for fetching historical data (i.e. candlesticks) for a specific forex instrument
  • train - used for training a model using historical data
  • eval - used for applying a model on historical data and evaluating its performance
  • trade - used for opening a position for a specific forex instrument using a trained model

Examples

Fetching historical data

The command below will fetch candlesticks of one minute (-t Min1) for symbol EUR/USD (-s EUR/USD) between the specified dates:

cargo run -- fetch -t Min1 -s EUR/USD --from-date 201801010000 --to-date 201901010000

The data will be written inside directory ./history/EUR_USD_Min1_201801010000_201901010000/

Training model

After fetching historical data, it is possible to train the model using the train command:

cargo run -- train --input ./history/EUR_USD_Min1_201801010000_201901010000/ --input-window 30 --pred-window 5 --learning-rate 1e-3 --learning-iterations 3000 -m ./models/EUR_USD_Min1_30_5

The command above will train a model that based on last 30 minutes (--input-window 30), it will predict the minimum and maximum bid price of EUR/USD on the next 5 minutes (--pred-window 5). The model will be stored under ./models/EUR_USD_Min1_30_5

Evaluating model

Trained models can be evaluated using the eval command. The command below will simulate the opening of positions every minute between 202009010000 and 202010010000. The opened positions will use predictions made by the model and at the end the total profit or loss will be printed.

cargo run -- eval --min-profit 2.0 --max-loss 10.0 -m ./models/EUR_USD_Min1_30_5 -i ./history/EUR_USD_Min1_202009010000_202010010000/

Note that the data used for evaluation must be different than the data used for training.

Trading

It is also possible to use a model for actual trading (in FXCM demo server). The command below will fetch the lastest candlesticks for symbol EUR/USD, it will feed the model ./models/EUR_USD_Min1_30_5/ with these candlesticks and then will use its prediction for opening a 'buy' position with the specified amount of lots (-a 10).

cargo run -- trade -m ./models/EUR_USD_Min1_30_5/ -a 10 --max-loss 20.0 --max-used-margin 0.003

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages