A foreign exchange trading bot with quite some personalities, utilizing CNN + DQN with persona-driven adjustments.
📌 v4.5 | 2019-09-02 | Refactor to work with Anita_v2.0 + Proper documentation.
A proper README.md
file will be written once the project is fully developed (or once reached a certain milestone). During the developing stage, records will be update on CHANGELOG.md
.
Named after an unified currency of Qin dynasty, half_tael_DQN is aimed to be a foreign-exchange trading bot capable of trading among multiple currencies. Further, with the concept of Anita, we expect such a bot to be able to generate trading strategies subject to different persona-driven adjustments — as an overly simplified example: to provide a more "aggressive" or a more "conservative" trading strategy.
half_tale_DQN is composite by three main blocks of code:
- A virtual trading platform which capable of communicating through OANDA API to retrieve historical price data among different currencies, be able to register all virtual trading signals (buy & sell among any two-currency for a given value, etc), to generate a
trade_log
, and to track your account balance accordingly. A relatively thoughtful exception-handling system is implemented as well.- Constituted by
oanda_interface.py
andtrade_interface.py
. - To operate this virtual trading platform, check 🔰 User Manual for
trade_interface.py
. A standalone demo is also offered astrain_interface_demo.py
.
- Constituted by
- A DQN model with some kind of preprocess (currently CNN), capable of taking DataFrame with format like ./arena_data as input and generates trade signals accordingly.
- Constantly updating, currently as ./DQN_v3.0. Where
FX_env.py
defines the custom environment of foreign-exchange trading,RL_brain.py
builds the logic of model, andmodel_interface.py
runs the model buy integrating the former two together. - Other than the above three "core" files,
model_config.py
andtrain_interface.py
are provided as the configuration panel and the entry point of this program.
- Constantly updating, currently as ./DQN_v3.0. Where
- An Anita evaluator to influent the reward of a (or a set of) trade action(s) according to persona-driven adjustments.
- Constituted by
anita_interface.py
along. - To operate this evaluator, check 🔰 User Manual for
anita_interface.py
.
- Constituted by
-
Register a fxTrade Practice account at OANDA. Then look up your
account_number
at Manage Funds --> My Fund --> Account Summary --> v20 Account Number; and obtain your OANDA's API token by visiting Manage API Access --> Generate/Revoke. -
Edit
oanda_config.py
by assigning your account number and API token tomy_account_id
andmy_access_token
respectively (asstr
). -
Edit
model_config.py
with the desired parameters you'd like. -
You can either identify a version of DQN model you'd like to run with, go into such folder (e.g. ./DQN_v3.0), locate the
train_interace.py
file, then run against it within your IDE.Or in terminal,
cd
into the root folder ofhalf_tael_DQN
, identify the folder which contains your desired version of model, then:python3 model_version_folder/train_interace.py
As for the example of ./DQN_v3.0, the command should be:
python3 DQN_v3.0/train_interface.py
To get involved, you are expected to uphold CONTRIBUTING.md
.
If you are from Graphen.ai and want to carry on this project, you are recommended to branch out from tag v4.5
like:
git checkout -b your_branch_name v4.5
Since later version of half_tael_DQN might detach the Anita evaluator as it is a property of Graphen.ai.
Though published, this is my (@choH) first semi-serious project and also my first exposure to AI. Thus, a lot of works here were done in a premature way. The project is published more for the purpose of exhibition and ease of future development — please use it with caution.
Known limitations of this project include but not limited to:
- Only be able to register trade signals within the virtual trading platform, but not able to submit real trade request to OANDA.
- Only a very simple CNN is implemented as preprocess method to handle multiple currencies (>2) as input — since there will be multiple price data on every timestamp — and the benchmark is not exactly appealing.
- Only a simple double DQN is implemented as model.
- Only a very basic method is implemented for
Anita_Trait
. - Lack of visualization, as the
cost_log
is the only graphical output of this model.
Check out Issue #22 for potential improvements for this project.