Where can I get best return on investment?
5 minutes guide
Where should I start?
5 minutes guide to algorithmic trading
Where should I start?
Welcome to your quick start guide on algorithmic trading
Learning something new on the internet is like trekking in the amazon rainforest. The process is about as epic as you would imagine that to be. You may (sometimes) be lost.
— A welcoming jungle. — Photo by Ting Chang on Unsplash
Here, the objective is to avoid the Jungle Survival Training camp. This article does not pretend to be such a camp.
Instead, relax, take a comfortable seat and a good cup of coffee. (Of course, fill the cup with whatever you want.)
So, let me introduce a first post. A challenging one.
Why?
Three reasons. In only one article, you will:
gather financial data automatically. You will be free to use it as you see fit.
perform a simple financial performance indicator.
Run a code. In 5 minutes, using Python.
A few words about Python and Finance. Here, you do not need to have any background in Mathematics and Finance. Concepts will be described in a simple and logical way.
You do not need to have any background in Python and Computer Science too. You just have to push a button “play” at the end. For sure, we will enter into the code line by line. I am pretty sure you will surprise your friends and family after reading this blog.
In this article, I am not offering investment, legal, or any other advice, nor am I trying to do so. This is only a tutorial for learning purposes. Any decisions, investments, or risks you take as a result of building a trading bot are your responsibility.***
![]()
In this article, I am not offering investment, legal, or any other advice, nor am I trying to do so. This is only a tutorial for learning purposes. Any decisions, investments, or risks you take as a result of building a trading bot are your responsibility.***
Data is the new gold
Well, let’s answer the question. Where should I start ?
“Where there is data smoke, there is business fire.”
Thomas Redman
Before writing this post, I found this quote. Google is a wonderful tool to look for quotations (and other stuff). And this one perfectly fits my introduction.
So, let’s determine where there is data smoke.
Actually, there is data everywhere. Sometimes free, sometimes not. A free solution is used for this tutorial. We will use Yahoo Finance.
Yahoo finance is powerful for gathering financial data. Although data is accessible directly via their website, we will use Python.
Phone a friend
Why Python ?
No need to do manual manipulation in the website and in Excel. No need to repeat the process of gathering again and again. Everything is automated. In other words, the dream of lazy.
More, we will use the library “pandas datareader”. Importing a library in Python is like using the lifeline “Phone a friend” in “Who Wants to Be a Millionaire?”. The friend is the coder who give you access to their code: freely and easily. Unlike the game show, there is no time constraint..
import pandas_datareader.data as web
I know if you are sitting comfortably, reading this line, you will get the key. The key is using the existing code to simplify and perform yours. the library “pandas datareader” is able to gather data from Yahoo Finance in only one line of code.
start = dt.datetime(2020,6,1)
end = dt.datetime(2020,7,1)
tickers = ['IBM', 'TSLA']
data = {}
for t in tickers:
data[t] = web.DataReader(t,'yahoo', start, end).reset_index()
Ok. We can get data. But what data?
A (not so) simple financial data : the stock price.
To keep it simple, a stock represents an ownership of a fraction of a company. This fraction has a price, depending on who is buying or selling it. This is supply and demand. Every business day, every seconds, the price goes up or down.
Who is the best performer, in 3 steps
Here we are. The first use of data – with a simple indicator of financial performance.
The problem is not the data anymore but the exploration of the stocks’ performance.
Let’s take (randomly) the stocks of Amazon and Google. We will compare both stocks for the first semester of 2020.
Again, these two stocks have been chosen randomly for learning purposes. This is neither a stock analysis, nor an advice to invest. ***
Let’s open the arena to our two candidates.
Below is the graph. Are you able to determine who is the best performer?
Step 1.
Compare the price evolution.
At first glance, comparing the price evolution in the graph is not explicit.
We cannot say who is the best performer between the 2 stocks.
Step 2. Get the monthly return and compare.
The simplest indicator in Finance is the return.
A return is the change in price on a valuable object over time, which may be represented in terms of percentage change.
To make it simple, you own a precious chair valued at 100. If next month the value is 110, you could make a profit of 10. A profit of 10 for a value of 100 is then considered as a 10 per 100 return.
Comparison is the main advantage of percentage return.
Would you like to get an overview on the 6-month period?
Comparing monthly returns, month by month is not visually attractive.
Step 3. To have a global view: get the cumulative return.
The solution is summing the monthly performance (i.e. the monthly return).
For example, cumulative return of march = return of January + return of February. The cumulative return of April = cumulative return of March + return of April and so on…
No worries about the math. Python computes everything. Cumulative return will be waited on hand and foot at the end of the article.
Show, don’t tell !
Here is the graph. Click on the 3 buttons to visualize the 3 steps.
Finally, the code…
Before to give the code, a few words about algorithmic trading.
A major disadvantage of algorithmic trading is
The performance measures are subjective depending on the chosen indicator.
Now, just have fun. Push the Run button and look at the result.











Recent Comments