If you’ve been trading in a discretionary and manual fashion for some time, you might be interested in automating and scaling your operation. In order 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 a trivial one, and you might be wondering which one you should choose.

Python is the default programming language when it comes to automated trading strategies. Its ecosystem is full of open-source libraries that are especially useful for strategies that heavily rely on statistics, technical indicators, and even machine learning. Having said that, C and C++ are the industry standards for implementing high-frequency trading strategies.

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.

Both Pandas and Numpy are by far the best libraries available for performing operations on large datasets of time series. It allows to effortlessly clean, transform, and resample datasets with only a few convenient functions that would 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.

If you want to backtest your strategies, Python also has a decent number of reliable and mature open-source backtesting projects. If you want to prioritize quickly testing complex strategies, Backtesting.py is the best library available. Additionally, if you require performing thousands of backtests in an efficient manner, VectorBT is, by all means, the appropriate tool. 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 heavily rely on technical indicators, you can calculate more than 130 of them by using PandasTA. In fact, here’s a quick tutorial a created that combines pandas_ta and backtesting.py

Making extensive use of statistical tests is not only beneficial but a requirement for creating profitable trading strategies. It goes without saying that Python also has a thriving community of 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 that are comparable in features to ScikitLearn, TensorFlow, Keras, SciPy, and Pytorch, amongst many others.

Which programming languages are used for algorithmic trading

Python, C#, Java, C, and C++ are by most definitions the most popular programming languages used not only by retail traders but also by quants in the industry. Having said that, algorithmic trading has become increasingly popular in recent years, so you won’t have any trouble finding trading-related resources for other programming languages, like R, Julia, Go, or even JavaScript.

Each programming language has its own 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 algorithms. For such endeavors, C and C++ are the go-to programming languages.

Java, on the other hand, has been the industry standard for implementing FIX engines and for complex order routing algorithms that interface directly with the exchange. Last but not least, C# is nowadays also a popular choice in the financial industry due to its similarity to Java when it comes to Syntax.

Advantages and Disadvantages of programming languages for trading

Python

Advantages

  • 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

Disadvantages

  • Might not be suitable for memory-intensive tasks
  • Low execution speed compared to other programming languages

C# and Java

Advantages

  • 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

Disadvantages

  • Fewer data science and machine learning libraries are available
  • Not many learning resources that focus on algorithmic trading

C and C++

Advantages

  • Allows for maximum scalability
  • Industry-standard for high-frequency trading
  • Best choice for optimizing execution speed

Disadvantages

  • 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 daytraders 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 TradingViews own backtesting engine. Although it had quite a few relevant bugs in the past, the engine has gone through major improvements and is nowadays 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 to validate a given strategy’s expected value (or edge) by means of techniques that are industry standards, like walk-forward optimization, sample-splitting, cross-validation, and statistical hypothesis testing. As a consequence, users are not able to rigorously test the validity of a strategy 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 all of the above limitations, there are countless research ideas that 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:

Advantages

  • 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

Disadvantages

  • Fewer data science and machine learning libraries available
  • Not many learning resources that focus specifically algorithmic trading

Is programming required for Algotrading?

Composer’s intuitive drag and drop interface for rebalancing portfolios. Source

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 in order 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 just turning some knobs and clicking a few checkboxes. Additionally, 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.

Much like TradingView’s PineScript, both of these options have severe limitations when it comes to implementing professional-grade trading strategies. Regardless of this, they are excellent choices for getting your hands dirty and implementing your first rule-based trading system.

Categories:

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *