Introduction to Julia – Part I

QuantInsti

Contributor:
QuantInsti
Visit: QuantInsti

This article introduces the Julia programming language, which is specifically designed for scientific computing, that solves the “two-language problem”, i.e. it provides the performance at par with C and the dynamic nature of Python and R.

This series of articles will take you through the journey of getting started with Julia programming to backtesting and implementing live trading strategies in it.

This is the first article in the series and has the following sections –

  • What is Julia?
  • Why do we need another programming language?
  • Is Julia faster than Python or R?
  • How to install Julia?
  • How to run Julia in a Jupyter notebook?
  • How to install packages in Julia?
  • Basic packages in Julia
  • Julia packages for Algorithmic Trading

What is Julia?

Julia is a high-performance programming language specifically designed for efficient numerical computing. It aims to provide high computational speed combined with an easy-to-write programming language.

Julia project was started in 2009 and was released as an open-source language (under MIT license) through a blog post in 2012. Julia 1.0 was released in 2018. The Julia user base has grown widely as the scientific community realised its potential. As of July 2021, Julia has 203,400+ GitHub stars, provides 6000+ registered packages and has over 29 million downloads.


Why do we need another programming language?

The scientific community has always faced a trade-off between the high-performance vs dynamic nature of programming. Programming languages like Matlab, R or Python are widely used in the scientific community.

However, when it comes to solving challenges that require enormously high computation power, the code has to be re-written in languages like C or Fortran to achieve this goal. This is called the “two-language problem”.

Julia claims to solve this challenge by combining the best of both worlds, i.e., speed and easy-to-write language.


Is Julia faster than Python or R?

Let’s look at some benchmarks.

Computation times

The following figure shows the computation time for various languages on different operations (mentioned in the legend). The vertical axis shows each benchmark time normalised against the C implementation.

As we can see, Julia is closest to C for most of the operations, lagging behind LuaJIT and Rust in some cases. It’s much faster than Python or R. More details on this benchmark test can be found here.

Source: https://julialang.org/benchmarks/

Multiple operations on large datasets

The below chart compares the task of the groupby function across various packages. “Query 1” in the figure below is one of the tests performed, and DF.jl (a Julia package) turned out to be the fastest. There are many other queries performed here.

Source: https://h2oai.github.io/db-benchmark/

For query 1: “sum v1 by Id1”: 100 groups of ~10,000,000 rows, Python (pandas package) and R (dplyr package) resulted in an internal error and out of memory error, respectively while Julia took 2.4 seconds the first time and 1.8 seconds the second time.

Stay tuned for the next installment in which Anshul Tayal will demonstrate how to install Julia.

Visit QuantInsti for additional insight on this topic: https://blog.quantinsti.com/julia-programming/.

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.

Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.