This product is a Jupyter Notebook containing Python code for a Grid Trading strategy for currencies.
Grid Trading Strategy For Currencies
This software comprises a Jupyter Notebook written in Python and is designed to show a simple system which loops through currency data….and simulates the Grid Trading Strategy for currencies. Data should be in bar form: Date, OHLC, sorted from the oldest prices to the newest. Some sample daily currency data is included. If you discover bugs or errors, please let me know and I will do my best to correct the errors. With the best will in the world, bugs and errors have a habit of creeping in!
If you are new to programming, this product will take you in at the deep end. You are advised not to purchase this product unless you are familiar with programming or willing to put in a lot of effort to learn.
The version of Python and the necessary imported libraries are as follows:
Anaconda Version and System Info
(‘3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]’, sys.version_info(major=3, minor=6, micro=8, releaselevel=’final’, serial=0))
The download is in the form of a zip file.
It might be helpful if I set out some of the instructions contained in the notebook, so that prospective customers can get an idea of what they are purchasing. Here are the details of the cell “Initialising Variables:
Target Directory and Ticker. Make sure to set the target directory to where your data is located and to set the ticker to a file which actually exists in your target directory. Make sure the data has headings and format as above.
Running the Notebook. Change dates, allocations and currency data as desired and then either scroll through each cell in turn and press “Run” or, on the Menu, select Cell/Run All.
Bet Size. “bet_size” – represents the trade size in terms of a percentage of the amount of total equity held at the time of the relevant trade.
Quote / Base. “quote” and “base” represent the amounts of quote and base currency held at the start of the test. Set these so that base and quote are equal at the beginning of the test (valued in terms of the base currency). For instance depending on start date, with USDCHF, base might be 1,000 and quote 1,600 if the rate at the start date is USD 1 to CHF 1.6.
Profit Target. “profit_target” is used to construct the list of sell orders from the list of buy orders (the buy orders are created first). Each buy order will be matched by a sell order placed at buy order + the profit percentage.
Number of Trades – The Grid. “num_trades” – the number of buy and sell orders created. If this number is set to 100, 100 buy orders and 100 corresponding sell orders will be created.
Start and End.” buy_start” – “buy_end”. This represents the range of order prices created. If “num_trades” is set by way of example to 100, 100 buy orders will be created logarithmically spaced between “buy_start” and “buy_end”. In other words this setting creates your “range” or “grid”. Sell orders are then based on buy orders + “profit target”.
Modes. Mode 1 is plain vanilla. Each order is executed as, when or if it comes into range. Mode 2 uses a “set_point”:- it is customary when creating a “Grid” to decide whether you think the price is going to trend or mean revert. If your belief is that the instrument mean reverts around a set_pont, then try mode 2. Buys of the base currency will only be executed when the price is below the “set_point, sells of the base currency will only be executed when the price is above the set_point. Mode 3 explores trend following: user defined short and long moving averages define the trend. The base currency will only be sold if the trend is down and bought if the trend is up. Mode 4 encompasses mean reversion and only takes trades which are against the near term trend.
Quote Format. Be aware that currency price series are usually in the format base=1, quote = “x”. In the case of USD/CHF an increase in the closing price from 0.80 to 1.60 (by way of example) means USD has increased in value and CHF has declined vs USD. You need to keep this in mind when adjusting your set_point and also when amending the trend/counter-trend modes.
Errors. A prime cause of apparent error leading to zero trades is the failure to adjust some of the parameters to very different price series. Consider USDCHF and USDJPY. For much of its recent history, USDCHF has varied between 1.6 and 0.8. USDJPY by contrast has ranged between 130 and 75. The parameters base, quote, buy_start, buy_end and set_point need to be tailored to each individual time series or the output will be nonsense.
Full and customary statistics for the test are produced thanks to the Python package FFN and various charts are displayed: Equity Curve, Draw-down, Number of Buys and Sells over time, the composition of the account value over time in terms of the base currency and the quote currency.
Here are sample files produced in a back-test