Exploring the AI Trading Strategies Course Using Mojo
Learn about AI Trading Strategies course with Mojo, a new programming language created by the team behind LLVM and Swift. This article covers the course syllabus and setting up Mojo with Jupyter Notebooks to follow the class.
Introduction
Artificial intelligence and financial trading are exciting areas that bring together technology and money. This article introduces the AI Trading Strategies course, explains its main ideas, and shows how we can use the Mojo programming language to make the most of it.
I started this course because Udacity offered a 55% Black Week discount, making it the perfect time to learn something new.
Course Overview
The AI Trading Strategies course teaches how to use AI to improve trading. Here’s what it covers:
- Basics of AI in Trading: Key ideas about machine learning and deep learning for trading.
- Trading Strategies: Practical examples include mean-reversion, momentum, and arbitrage strategies.
- Testing and Improving Strategies: How to backtest and make strategies better.
- Real-Life Applications: Tips for using strategies in live trading.
This course assumes programming knowledge and targets those who want to learn more about trading with algorithms.
Course Overview
The AI Trading Strategies course teaches how to use AI to improve trading. Here’s what it covers:
- Basics of AI in Trading: Key ideas about machine learning and deep learning for trading.
- Trading Strategies: Practical examples include mean-reversion, momentum, and arbitrage strategies.
- Testing and Improving Strategies: How to backtest and make strategies better.
- Real-Life Applications: Tips for using strategies in live trading.
Starting the Course
The course focuses on cleaning data with pandas for the first few weeks, which might feel boring for programming language nerds like me. So, I decided to spice things up by also giving Mojo, a new programming language designed for AI and high-speed computing, a try.
Why Mojo?
Mojo is a new programming language developed by Modular, a company co-founded by Chris Lattner, the creator of LLVM and the Swift programming language.
This interview at Developer Voices goes in depth at the history of Modular, why they decided to create a new programming language, and why they chose Python's Syntax.
Here is a summary of why I think Mojo is one of those uncommon technologies that are guaranteed to succeed:
- The people behind them have delivered multiple successful projects, and the technology solves a fundamental issue: how to bridge the gap from AI models written in Python without having to rewrite them in another language for performance purposes.
- Easy Like Python: Mojo's goal is to become Python++, and eventually be able to run any valid Python program.
- Fast Like C: the simplest way to think about Mojo is like a compiled Python, but that only scratches the surface. I look forward to learning to adopt Mojo's unique features, like progressively adding types to gain even more speed.
- Works Well for AI: since I have not used the language yet, I do not know for sure, but I think it is a safe assumption, given that is the company's goal.
- Cool Features: I hope to learn about MLIR since Mojo is the first front end of the compiler technology I know of.
Challenges and Rough Edges
Since Mojo is new and evolving quickly, we should expect some challenges. For example, the course relies heavily on Jupyter Notebooks. The resources I found suggested Jupyter should work more or less out of the box after installing Mojo and the Visual Studio Code extension.
This wasn't the case, and I think this is because since the articles were written, Modular released a new tool to manage Mojo projects called magic
, it is similar to other tools like rustup
. From a Python perspective magic
is like rolling Python Virtual Environments and PIP into a single tool, one to rule them all.
Setting Our Environment for Mojo Development
As of December 2024, the best way to install Mojo is to install Mojo is to install the magic package manager:
$ curl -ssL https://magic.modular.com/deb17415-5cb5-4367-9b15-b60aed1f68de | bash
And start a project with it:
$ magic init hello-mojo --format mojoproject
$ cd hello-mojo
$ magic shell
$ mojo
The step is to install Visual Studio Code or Codium and the Mojo Extension and check if everything is running as advertised.
To do that, I downloaded one of the notebooks from Modular and try to run it in VS Codium:
$ wget https://raw.githubusercontent.com/modularml/mojo/refs/heads/main/examples/notebooks/Matmul.ipynb
VS Code should automatically start Jupyter, but unfortunately, it does not seem to find the Mojo kernel, which should have been there according to the resources I found.
Remember to start your IDE from the magic
shell to ensure it inherits the project environment.
Getting Jupyter Notebooks to Run
This is when I thought that the articles I found so far didn't seem to be aware of magic
, and I suspected they were working with a system-wide installation of mojo
. This would explain why VS Code was unable to find the kernel.
My first step was to install Jupyter in the environment of the project using magic
:
$ magic add Jupyter
Unfortunately, that was insufficient; I could see the kernel, which is called MAX, but not mojo. However, VSCode appeared to enter a lengthy evaluation loop without getting any results.
Hence, I tried to run Jupyter by hand and got an error about not being able to find Python.
$ magic add python
After that, start VS code again; make sure to start it in the folder of the project so you can easily open the Matrix Multiplication Notebook we downloaded from Modular.
$ codium .
And finally, run the notebook; if it asks for a kernel, look into Jupyter Kernels and choose max.
The Notebook I downloaded is a comparison of Matrix multiplication with Python and Mojo. The Notebook's specifics are beyond this article's scope, but just using Python Code with Mojo is 1.4x faster, and progressively translating the code to use mojo
features leads to 22k times improvements over Python.
This looks extremely promising, given that matrix multiplication is the turtle on which most artificial intelligence rests.
Conclusion
This article looked at the AI Trading Strategies course and how Mojo can help us learn. We also explained how to set up Mojo and Jupyter to get started.
In the next article, we’ll look at the first exercises of the code using Pandas to look fetch and process finance data.
Addendum: A Special Note for Our Readers
I decided to delay the introduction of subscriptions. You can read the full story here.
If you find our content helpful, there are several ways you can support us:
- The easiest way is to share our articles and links page on social media; it is free and helps us greatly.
- If you want a great experience during the Chinese New Year, I am renting my timeshare in Phuket. A five-night stay in this resort in Phuket costs 11,582 € on Expedia. I am offering it in USD at an over 40% discount compared to that price. I received the Year of the Snake in style.
- If your finances permit it, we are happy over any received donation. It helps us offset the site's running costs and an unexpected tax bill. Any amount is greatly appreciated:
- Finally, some articles have links to relevant goods and services; buying through them will not cost you more. And if you like programming swag, please visit the TuringTacoTales Store on Redbubble. Take a look. Maybe you can find something you like: