How to Become a Financial Hacker: A Gentle Introduction

financial hacker, How to Become a Financial Hacker: A Gentle Introduction

Hi dudes, I’ve been offline for a while, I know, but I’ve kept working in the shadow: I had my first face-to-face interview with a new trending Spanish platform called Microwd. I plan to release it by the end of next week-ish. I’ve also worked in a new version of Mintos Loan Explorer and Mintos Lender Ratings fintech tools, including new exciting features.

Last week I received an email from one of my beloved subscribers which asked about how to become a Financial Hacker. The term Hacker doesn’t have a good press nowadays, but this is what Wikipedia says: A computer hacker is any skilled computer expert that uses their technical knowledge to overcome a problem. That’s exactly what we’re about to do: overcome financial problems using our computer. 

As you probably know, some investing platforms release their data to the public by allowing investors to download their accounting or history statistics. But it turns out to be quite overwhelming to mess up with 1.8GB of data split into 46 CVS files, huh? (Hello, Mintos! 🙂 ).

The purpose of this article is to introduce you to programming in general and how to apply your skills to analyse financial data. Despite I’m not a financial advisor, I have nearly 7 years of experience developing and designing applications for the Airline Industry, and I’m familiar with introducing new staff members to the business logic and the programming best-practices. Feel free to ping me on LindkedIn, lads.

I’ll divide this post into three subsections: Learning to code, Learning math and Learning finance. Bon appetit!

Learning to code

Well, the very first step to becoming a financial hacker is to learn a coding language. Why? Simply because, despite you have the functional knowledge in a field, you also need a technical background so you can manipulate the data and reaching new conclusions. Programming is an excellent tool to do so.

Thus, you need to choose which programming language to learn. But there are literally tons of them, and each one has its own pros and cons. In my opinion, there is no such thing as the best programming language.

Your first program

In this post, we’ll create our very first program using Python, as it is a versatile language very beginner-friendly. 

  1. Download Python from their official website.
  2. Execute the setup file and complete the installation process.
  3. Create a new fille called hellocoin.py in C:\ directory with the content print('hello thecoinmagent!').
  4. Open the command prompt (CMD), type python C:\hellocoin.py and press Enter.

If you have followed the previous steps correcly, you’ll see the following message:

financial hacker, How to Become a Financial Hacker: A Gentle Introduction

Yay! You’re one step closer to Mr. Robot!

Not rocket science by now, huh? Now take a deep breath and learn Python essentials in 5 minutes. Will be enough to get used to the syntax and to understand the general idea of the following sections.

Installing libraries

Now let’s install some libraries. In a nutshell, libraries are predefined modules which incorporate specific functionalities, so we don’t have to code everything from scratch (aka reinventing the wheel). To do so, we need to install pip by this way:

  1. Download get-pip.py to a folder on your computer.
  2. Open a command prompt and navigate to the folder containing get-pip.py.
  3. Run the following command:python get-pip.py.

Afterwards, let’s install some usefull libraries like this:

pip install jupyter pandas numpy matplotlib pandas_datareader mpl_finance

Let’s code something cool

Ok, I get it: you want something to impress the kids of your class. Hold my beer…

Now we can execute the Python code in our new IDE, by running jupyter-notebook in the CMD.

Note: If you get an error like this one, edit the asyncio file according to this StackOverflow answer.

File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "c:\users\user\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

Once we have opened Jupyter Notebook, click on New > Python 3 on the right corner of the top.

Let’s import the libraries we’re about to use:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mpl_dates
import pandas as pd
import pandas_datareader.data as pdr
import warnings

# Omiting annoying warnings
warnings.filterwarnings("ignore")

# Cool chart formating
style.use('bmh')

Hit Enter + Shift to execute the cell (easy, right?). In the next cell, we’ll retrieve the last days of Apple stocks using the Yahoo Finance API:

# Defining the dates to retrieve the info
start = dt.datetime(2019, 10, 1)
end = dt.datetime.now()

# Loading the Apple data from Yahoo Finance API
df = pdr.DataReader('AAPL', 'yahoo', start, end)

# Just displaying the first 5 rows
df.head()

You should see something like this output:

financial hacker, How to Become a Financial Hacker: A Gentle Introduction

Now we have the Apple data loaded in our dataframe called df. Lastly, let’s display a fancy chart with a rolling mean of the last 5 days:

# Defining the rolling mean of last 5 days
df['SMA5'] = df['Adj Close'].rolling(5).mean()

# Removing null values
df.dropna(inplace=True)

# Creating a column with the index of the dataframe
df['Date'] = df.index

# Creating the OCHL dataset
df_ohlc = df[['Date', 'Open', 'High', 'Low', 'Close']]
df_ohlc['Date'] = pd.to_datetime(df_ohlc['Date'])
df_ohlc['Date'] = df_ohlc['Date'].apply(mpl_dates.date2num)
df_ohlc = df_ohlc.astype(float)

# Defining the grid to display both graphs
fig = plt.figure()
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1)
ax1.xaxis_date()

# Loading the OCHL data in the first chart
candlestick_ohlc(ax1, df_ohlc.values, width=0.5, colorup='#6ab04c', colordown='#eb4d4b', alpha=0.8)
# Loading the simple moving average we created earlier
ax1.plot(df['Date'], df['SMA5'], color='#686de0')

# Loading the volume in the second chart
ax2.fill_between(df['Date'], df['Volume'].values, 0, color='#95afc0')

# Displaying the chart :)
plt.show()

This is the final result:

financial hacker, How to Become a Financial Hacker: A Gentle Introduction

Hurray! You cracked the game!

However, this article doesn’t mean to be a programming course, I just want to get you started in this broad field. Instead, I’ll provide a checklist of useful FREE resources which will help to build a solid background:

Interactive STUFF

Boring but good

Once you know the basics

Learning math

If you’re interested in coding in general and Machine Learning in particular, you need to have a basic knowledge of discrete mathematics. Discrete mathematics is the study of mathematical structures that are countable or otherwise distinct and separable, like combinations, graphs or logical statements.

I’d personally focus my energy in the following fields:

Probability

Statistics

Calculus

Linear Algebra

For the general public who want an overall introduction, you should also check Mathematics: A Very Short Introduction. It’s quite beginner-friendly and easy to read. 11 + 1 = 100 (at least in binary 🙂 ).

For those who already have a programming background, and fancy a deeper understanding of maths, I strongly recommend taking a look at A Programmer’s Introduction to Mathematics by Jeremy Kun. It literally changed the way I pose my algorithmic approaches. Here is an example:

financial hacker, How to Become a Financial Hacker: A Gentle Introduction
Page 18 of A Programmer’s Introduction to Mathematics book

Learning finance

As every Data Scientists say: always understand the data! It doesn’t matter if you can create fancy charts or know the math’s behind a GAN algorithm if you don’t know what are you looking for.

In my job, we usually spend more time determining what to do, than actually technically solving the problem itself. Anybody can find a solution, but no so many the best one. That’s why I always to create a glossary of the terms involved, UML diagrams, brainstormings, etc. before witting a single line of code.

When it comes to Finance, there is an overwhelming amount of info out there. It also depends on which field do you want to specialise: Forex trading, crowdlending, Index Funds, etc. Therefore, I’ll provide some of the courses I took to acquire an general overview of the most common topics:

In another vein, although the project is now discontinued, I really enjoyed learning algorithmic trading using Quantopian. There you can simulate the historic performance of your algorithms for free. They provide their own trading framework in Python. Here are some of the top public algorithms of the platform so you can learn about different successful approaches for the same problem. Here is a cool example:

financial hacker, How to Become a Financial Hacker: A Gentle Introduction
Long Short Pipeline Multi-Factor by James Christopher

Note that you can also click on the Source Code tab to see what’s the algorithm actually doing. I checked this stuff years ago, but I think some of the forum discussions and papers posted there are still valuable.

The bottom line

My final advice is to avoid spending the whole day reading reference books, but starting messing up with simple projects. By that way, you’ll address the theory on the go, not beforehand (aka learning by doing). This is quite important in order to keep you motivated. You always need to understand the 100% of what we’re doing, if you get stuck, check the reference book or try an easier problem. Also be realistic in terms of setting up doable goals, if your first project is to create an HFT bot to beat the forex market you’ll get frustrated the first week. This is a long-distance race, mate, but in the end, it pays out. 

If you want me to create more content of this kind, just share this article and drop a comment in the section down below.

Let's be friends!
Join The Coin Magnet email list to don't miss a thing! Just 1-3 emails per month with 0% spam. Unsubscribe anytime.
Rate this post
[Total: 1 Average: 5]

3 thoughts on “How to Become a Financial Hacker: A Gentle Introduction”

  1. Nice article. I’ve become an Excel “obsessive” and do most of my data crunching with that and VBA macros… However, your Python intro has inspired me to experiment and perhaps find some better ways to analyse my data. Thanks.

    1. Thanks for your comment, Colin! I’m glad you’ve found my article useful, that motivates me to keep posting stuff like that. That’s funny because, on the other hand, my Excel skills are almost null. If you’re used to VBA, I bet you won’t have any problem with Python. Keep in touch!

Leave a Reply

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