If you’ve been trading in a discretionary and manual fashion for some time, you might be interested in automating and scaling your operation. To do so, you can choose to hire a developer, partner with one, or even learn how to implement your strategy on your own. In either case, the choice of programming language is not trivial, and you might be wondering which one you should learn.
Python is the default programming language when it comes to automating strategies. Its ecosystem is full of open-source libraries that are especially useful for strategies that heavily rely on statistics, technical indicators, and machine learning. Having said that, C and C++ are the industry standards for implementing high-frequency trading strategies.
If you’re not already an experienced programmer, it is worth mentioning that you’ll probably be able to research stocks much more efficiently using BacktestXL. This backtesting engine works natively in Microsoft Excel and also fetches historical stock prices, and alternative datasets. It also calculates technical indicators and has pattern recognition functions. Disclaimer: we’re the developers, but it really is the software we use for our personal research!
Why is Python used for Algorithmic Trading?
Python is extensively used not only for algorithmic trading but also for most data-science-related tasks. This programming language is especially good for researching, developing, backtesting, and implementing trading strategies due to its rich repertoire of libraries.
Pandas and Numpy are the best libraries for performing operations on large datasets of time series. It allows one to effortlessly clean, transform, and resample datasets with only a few convenient functions that would otherwise require a proficient programmer a few hours to implement in other programming languages. With Pandas, it is trivial to do complex tasks, such as resampling tick data and transforming it into bars.
Python also has many reliable and mature open-source backtesting projects if you want to backtest your strategies. If you want to prioritize quickly testing complex strategies, Backtesting.py is the best library available. Additionally, if you require efficiently performing thousands of backtests, VectorBT is, by all means, the appropriate framework.
I wrote an article that goes deeper into this specific topic, which you can read here. Additionally, in the following video, I show how to quickly create a backtest of a simple strategy using Backtesting.py.
For strategies that rely heavily on technical indicators, you can calculate more than 130 by using PandasTA.
Using statistical tests is beneficial and a requirement for creating profitable trading strategies. It goes without saying that Python also has a thriving community of data scientists that contribute to creating the most popular libraries for such tasks. It is almost impossible to find open-source projects for other programming languages comparable in features to ScikitLearn, TensorFlow, Keras, SciPy, and Pytorch, amongst many others.
Which programming languages are used for algorithmic trading
Each programming language has its advantages and disadvantages. Although Python is an excellent choice for prototyping and developing complex machine-learning algorithms, it might not be a suitable language for implementing high-frequency trading strategies. For such endeavors, C and C++ are the go-to programming languages. Keep in mind that high-frequency trading strategies require custom-made hardware and server colocation, making it impossible for retail traders to compete in that niche.
Last but not least, Java has been the industry standard for implementing FIX engines and complex order routing algorithms that interface directly with the exchange. C# is nowadays also a popular choice in the financial industry due to its similarity to Java in Syntax.
Advantages and Disadvantages of programming languages for trading
- Allows for high productivity
- Excellent for data science and machine learning
- Popular choice for systematic trading in the industry
- Mature libraries for trading-related tasks (time series analysis, statistics, backtesting)
- Most brokers have their own Python libraries for trading
- Easy to learn
- Might not be suitable for memory-intensive tasks
- Low execution speed compared to other programming languages
C# and Java
- Memory-access capabilities despite being high-level languages
- Very popular for backend-related modules in the financial industry
- Relatively easier than C and C++
- “Fast enough” for most algorithms that are considered high-frequency trading
- Fewer data science and machine learning libraries are available
- Not many learning resources focus on algorithmic trading
C and C++
- Allows for maximum scalability
- Industry standard for high-frequency trading
- Best choice for optimizing execution speed
- Steep learning curve
- Absence of built-in multithreading (for concurrency). Not an issue for C++11
- Absence of garbage collector (no automatic memory management)
- Not many reliable open-source backtesting engines are available
- Not widely used for data science and machine learning research
Are proprietary programming languages good for trading?
Due to the fact that proprietary trading programming languages are built especially for this purpose, they do have their advantages. They tend to have a broad set of useful functions that are intensively used for trading. Most, if not all of them, prioritize having a friendly learning curve to allow newcomers to ease the onboarding process and implement simple trading strategies in a matter of minutes.
Almost all proprietary programming languages also allow users to calculate trading indicators, measures of central tendency (mean, median, mode), and dispersion (variance, standard deviation).
Most of them also feature their own event-driven backtester and convenient charting features.
Having said that, proprietary programming languages also have many disadvantages. They tend to have limited features when compared to Turing-complete programming languages.
The fact that they are closed-source has led to them being relatively outdated. Other programming languages benefit from the fact that they have thriving communities of programmers that actively fix, maintain, and further develop open source.
As an example, it would be impossible to implement an XGBoost-based trading algorithm on PineScript, and relatively simple tasks such as hyperparameter optimization have to be done by manual trial and error.
Is PineScript (TradingView) good for algorithmic trading?
You might not know that Tradingview, one of the most popular charting platforms available, also has its own programming that is specifically geared towards systematic trading, especially when using technical indicators. PineScript makes it very easy for non-programmers to create their own complex strategies (relative to what most day traders do).
PineScript is definitely a suitable choice for day traders that want to research, backtest and even implement their ideas with a more systematic and less discretionary approach. With only a few simple and intuitive lines of code, traders are able to code strategies based on more than 100 available technical indicators and with multiple time frames.
Once you’ve implemented a few rules for opening and closing positions, you can easily backtest them using TradingView’s own backtesting engine. Although it had quite a few relevant bugs in the past, the engine has gone through major improvements and is a reliable tool for testing strategies.
Due to their simplicity, PineScript (and TradingView as a whole) also have many limitations. Firstly, TradingView does not allow for validation of a given strategy’s expected value (or edge) through techniques that are industry standards, like walk-forward optimization, sample-splitting, cross-validation, and statistical hypothesis testing. Consequently, users cannot rigorously test a strategy’s validity in a scientific fashion, leading to a trial-and-error approach that is conducive to overfitting.
Although it is possible to implement strategies based on very basic econometric techniques, such as linear regressions, it would be nearly impossible to add more interesting models, such as AR(p), MA(q), ARIMA(p,d,q), SARIMAX, and other popular time series models commonly used for signal processing. It goes without saying that PineScript does not allow the training of machine learning models.
Last but not least, PineScript (and TradingView) does not accept to use external data sources, which poses important limitations when it comes to implementing news-based signals. Popular strategies, such as trading based on Reddit or Twitter sentiment, are thus not possible.
Despite the above limitations, countless research ideas have been implemented using PineScript. Most daytraders are not affected by the above limitations since they mostly trade on price and volume data. The following video is an excellent resource for getting started with PineScript:
- Easy to learn and implement day trading strategies
- Excellent repertoire of technical indicators
- Intuitive event-driven approach
- Easy to create strategies based on multiple timeframes
- Fewer data science and machine learning libraries available
- Not many learning resources focus specifically algorithmic trading
Is programming required for Algotrading?
Having a basic understanding of a programming language is, by most definitions, a requirement for algorithmic trading. Although it is common practice to outsource the coding implementation of trading strategies, it is still beneficial to have a basic grasp to review the code, spot errors, and request changes and new features or improvements.
Having said that, if you want to get your feet wet at systematic trading without committing to learning a programming language, there are multiple platforms that allow traders to implement relatively complex algorithms without having to write down a single line of code.
One of these startups is Composer (Link), which uses a drag-and-drop interface similar to Scratch (an educational tool for children). It has many features and is mostly geared toward automatically rebalancing portfolios.
Trality, on the other hand, is a startup that allows its users to implement fairly complex combinations of technical indicators by turning some knobs and clicking a few checkboxes. Trality also has its own coding platform, which features a set of convenient functions on top of Python. Due to its event-driven approach, it is also fairly intuitive.
Like TradingView’s PineScript, both options have severe limitations when implementing professional-grade trading strategies. Regardless, they are excellent choices for getting your hands dirty and implementing your first rule-based trading system.