docker run -it -v $(pwd):/home/unicorn/work trading python trading/backtesting/main.py
** Workflow guidelines
** Strategy quickstart :PROPERTIES: :ID: 0fc05222-0007-441f-b8e6-de1a1a55b59f :END:
Create strategy:
cp strategies/example_strategy.py strategies/my_strategy.py vim strategies/my_strategy.py
Run strategy (ie. on /datasets/rates_2017_may_60min.csv/):
./strategies/my_strategy.py datasets/rates_2017_may_60min.csv
Test strategy:
./strategy_simulator.py datasets/rates_2017_may_60min.csv MY_STRATEGY.csv
** Docker usage
*** Build image
docker build -t trading:latest .
NOTE: To avoid rebuilding when changing source code, run the image with ~-v $(pwd):/home/unicorn/work~.
*** Download stock dataset
| Input | Output | |--------+--------| | API credentials | Stock dataset |
Download rates for the month of January with a granularity of 30s:
export GDAX_API_KEY=XXX GDAX_API_SECRET=XXX GDAX_API_PASS=XXX
./tools/historic_rates_downloader.py 2017-01-01T06:00:00 2017-01-31T23:59:59 60 BTC-USD > res.csv
NOTE: Samples are not guaranteed to be uniformly distributed. Please plot against timestamp.
*** Run strategies
| Input | Output | |--------+--------| | Stock dataset | Actions |
docker run -it trading python strategies/XXX.py -h
*** Simulator usage
| Input | Output | |--------+--------| | Stock dataset, strategy actions | Simulation result |
docker run -it trading python strategy_simulator.py -h usage: strategy_simulator.py [-h] [--investment AMOUNT] [--reinvest-rate RATE] DATASET ACTIONS
positional arguments: DATASET path to the stock rates dataset ACTIONS path to the timestep to action mapping generated by the strategy
optional arguments: -h, --help show this help message and exit --investment AMOUNT initial investment (default: 1000) --reinvest-rate RATE reinvest rate (default: 0.5)
*** Run Jupyter :PROPERTIES: :ID: 915ba80c-0e46-4efa-958a-dadd35f6380b :END:
To run jupyter-notebook in the container with the web interface accessible from within the browser of the host machine:
sudo docker run -p 8888:8888 -v $(pwd):/home/unicorn/data trading \ jupyter-notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/home/unicorn/data
You'll then be able to access the interface at http://localhost:8888/
You'll be asked to enter a token, this token is visible in the terminal a few seconds after having launch the above command.
Note that this command will also mount the local directory (from which the command is launch, typically from this repository) to =/home/unicorn/data=. This allows you to persists you work achieved through the web interface.
See [[https://docs.docker.com][Docker documentation]] for more information about the options used.
** File formats
**** Stock dataset
time,low,high,open,close,volume 1483228800,970.42,973.4,973.37,970.42,58.11304124 1483229700,969.9,971.37,970.42,970.7,38.38647656 1483230600,970.88,971.99,971.08,971.82,33.3203246
**** Strategy output
time,action 1495328400.0,NOTHING 1495329300.0,BUY 1495330200.0,SELL