If you are struggling to master Python or if you are wondering how to jump out of the beginner’s world, a single mindset change could help.

The Sin of Python for Beginners — Hidden Types

If you just started learning to program, especially outside the engineering world, it’s likely you started with Python these days.

Type is one of the most important concepts in programming and probably the first thing you would need to understand.

Why is Type So Important?

Remember…


Data comes first when we are talking about Finance and Python. However, I am not only talking about capturing the raw data but also the way to structure it and ideally creating a financial analytics API around the data.

This is such an important and fundamental piece of the modern asset management stack. This is the reason why big asset managers are spending millions on such Data APIs.

What exactly is needed?

Point-in-time Data

First of all, we need raw data and it should be point-in-time data…


If learning Python is one of your new year resolutions, please read.

A Common Question About Learning Python

Python definitely has been expanding in the Financial Industry in recent years. I am getting to know more and more people, who are not computer engineers, started learning Python, either to advance the career or being asked to do by the companies. One of the most common questions I have got is:

A Common Mistake About Learning Python

One of the reasons why…


A new series of Python in Finance with a practical example. Let’s learn something about how professional money managers are handling the portfolios and where Python can be used.

Motivation

With the limited amount of good quality data available for less cost, the most common articles on Medium are talking about using ML/AI to predict the returns with only the pricing data, which are less likely to generate long term stable returns, because we are missing the other important information.

In real life, professional money managers won’t do so. They have a very comprehensive method to make decisions on what asset…


Coding is the simplest part of the trading and the backtesting is only a start. Behind all the successes it is how we use it makes the difference. In this session, I would like to show how possibly we could use the backtesting.

In the last four sessions, we have built the trading backtesting tools (functions), which gives the top trading strategies for a given period. If you haven’t read the previous sessions, here is the link.

Important Lessons

No Silver Bullet

There will never be a single strategy working all the time. Market condition changes and human behaviour changes. …


There are many technical indicators we can trade with. The question is what is the best one for a given asset? We are going to answer this question by improving our backtesting from the last session.

In the last session, we have seen how to find the best combination of stop loss level and parameter with the strategy Keltner Channel. In this session, we will explore and adding other strategies into our backtesting.

If you haven’t read the previous sessions, here are the links.

Quick Re-cap

Let’s have a quick review of our logic so far.


Find the best combination of stop loss level and parameter of Keltner Channel by turning the previous Python scripts into re-usable functions.

The Goal of This Session

  • Turn the scripts into well-structured functions (re-usable tools).
  • Find the best combination of stop loss level and parameter for Keltner Channel.

Quick Re-cap

In our last session, we added stop loss into our trading simulation and we have done one more risk measure, Maximum Drawdown. We found the 2% stop loss lowered our performance but the maximum drawdown is not reduced dramatically.

If you haven’t read the previous two sessions, here are the links.

Question Left from the Last Session

Will there be a good stop…


Python: Backtesting of Trading Strategy with Technical Indicator #2

The Goal of This Session

  • Add Stop Loss into our trade simulation code
  • Add Maximum Drawdown to our backtesting analysis

Quick Re-cap

In our last session, we used simple code and done the backtesting for a simple strategy using the Keltner Channel. We found that if we do the long-short trading with this signal, we could have earned more than 40% return in the year 2019 by trading ISF.L (UK FTSE 100 Index ETF), which only gained 14% in the year. If you haven’t read it yet, here’s the link.

Why Stop Loss

In short, for managing the risk. It’s all…


Named Tuple and Python Data Model. Fill the knowledge gap as a Python developer.

Fluent Python in an efficient way. I am following the book “Fluent Python” and filling the knowledge gap. It is a thick book with 21 chapters and more than 700 pages. Hopefully, the quick study note can help more people to sharpen Python skills.

Named Tuple

This is a less known type. We may have used list and tuple too much, as they are just too handy. We usually use a tuple to record information. For example, we have a list of student and each student has a…


Backtesting of Trading Strategy with Technical Indicator #1

Want to trade? Better to backtest the idea first. With this series, I want to extend Python Financial Series into practical tasks. We will use all we have learnt from the previous Python series to backtest trading strategy based on technical indicators. If you haven’t gone through the previous Python series, please check the following series.

The Goal of the Series

I am planning to cover the following topics.

  • A simple long-short example: ONE technical indicator for ONE security
  • Add stop loss into our strategy
  • Re-factor the scripts into re-usable tools
  • Apply tools to generate trade ideas

Mr. Q

Coding dad of two little girls (always). Financial application developer and technical sales. Stay real!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store