
Modern exchanges are very technological and attract the attention of IT specialists (for example, active discussions of my
articles on the topic speak for this). Many are interested in the topic of writing trading robots - someone wants to independently try to make money on the stock exchange, someone is not averse to making it to order. Today we will talk about how to approach the creation of the first such product - let's discuss a possible technology stack, lower the entry threshold and ways to minimize potential losses.
Disclaimer : a post for those who already at least approximately imagines the device of the exchange, the presence of risks, has the opportunity to experiment not with the last money and, in general, has common sense.
')
Explore possible technology stack
As in any IT project, when developing applications for trading on the exchange, the choice of specific tools dictates the ultimate goal. Before starting to develop a trading robot, you need to design the entire system, understand what modules it will have, how they will interact.
Do you write a high-frequency robot, which is important every millisecond? In which markets of which countries will the trading system operate? Will it only trade engine, or still need to add a module of risk management?
In each of these cases, the set of technologies may vary. A good approach to the choice is
described in an article on the profile resource QuantStart (of course, in English - for developing financial applications it is better to master this language well).
In general, you will most likely have to choose from such a list of technologies:
- Most brokerage and non-API (here is my selection of such tools ) have interfaces in C ++ and / or Java. You may be able to find ready-made connection modules written in C #, Python, R, Excel and MatLab by representatives of the community / clients of a particular broker. But you may have to write them yourself.
- Libraries such as uBLAS, LAPACK and NAG for C ++ are often used for data analysis, and MatLab in Python is popular NumPy / SciPy.
- When developing high-frequency robots using GPU (FPGA), you will most likely have to get acquainted with the CUDA framework.
Learn the specifics of development in the field of finance with the help of embedded programming languages
Creating a powerful trading system is by default a fairly large-scale project. However, if your goal is to get acquainted with the development for the sphere of finance, to study various moments when creating trading robots, then it is quite possible to manage with the so-called embedded programming languages.
There are trading terminals that can not only be used to carry out transactions in manual mode, but also use the scripting languages embedded in them to create simple robots.
One of the most popular terminals in the Russian stock market is QUIK, and it has the algorithmic language QPILE (QUIK Programmable Interface and Logic Environment). With it, you can automate
simple trading systems . QUIK also has an integrated LUA scripting language interpreter - it is called QLUA. Scripts on it can be loaded into the terminal either as source code or already as compiled byte-code.
Sample QPILE code:
PROGRAM FirmCode = "MC0012300000" CurrentBalance = MONEY_CURRENT_BALANCE(ROWNAME, FirmCode, "EQTV", "SUR") CurrentLimit = MONEY_CURRENT_LIMIT(ROWNAME, FirmCode, "EQTV", "SUR") Locked = MONEY_LIMIT_LOCKED(ROWNAME, FirmCode, "EQTV", "SUR") AvailableMoney = MoneyCurrentBalance + MoneyCurrentLimit – MoneyLocked If AvailableMoney > 0 Status = " " Else Status = " " SET_ROW_COLOR(ROWNAME, "RGB(255,138,138)", "DEFAULT_COLOR") End If END_PROGRAM
Both languages have a sufficiently developed user community, questions can be asked in threads on the official
forum .
In addition to QUIK, you can trade on the Russian stock exchanges through the
SMARTx terminal. It uses the built-in TradeScript scripting language. Its syntax is simple, but the number of available words and operands, you can encode quite complex strategies. This is what a simple tradeScript strategy code might look like:
Buy Signals # , TREND(EMA(CLOSE, 20), 15) = UP AND TREND(MACD(13, 26, 9, SIMPLE), 5) = UP Sell Signals # , TREND(EMA(CLOSE, 20), 15) = DOWN AND TREND(MACD(13, 26, 9, SIMPLE), 5) = DOWN Exit Long Signal # , TREND(EMA(CLOSE, 20), 15) = DOWN OR TREND(MACD(13, 26, 9, SIMPLE), 5) = DOWN Exit Short Signal # , TREND(EMA(CLOSE, 20), 15) = UP OR TREND(MACD(13, 26, 9, SIMPLE), 5) = UP
The most important stage: testing and debugging
Developing applications for the financial sector and especially tools for trading on the stock exchange is difficult because here you have to pay for errors in the direct sense with money. This is not writing code for the next web startup, where it can go unnoticed if it fails. Any error in the code of the trading robot will result in a loss of money. Therefore, debugging and testing is the most important step in creating such software.
Of course, you should apply all the best practices, create tests, correctly carry out code acceptance (even if you are developing the project alone). And most importantly - before starting tests on real money, “drive” the program to virtual ones.
Today, many Russian brokers offer a free test access service (for example, a company that develops a terminal SMARTx), when you are given an account that is almost the same as real, but the money is virtual. As a rule, when working with such an account, you can trade in the main markets - stock, currency, time - and work with major shares, futures, etc.
In some cases, you can even test the trade with borrowed funds (that is, leverage) - but when creating the first robot, the question is whether you need to add such functions to it.
Useful resources for developers of trading on the exchange: