Ever since I started investing back in college, I was exposed to the different ways of analyzing stocks —_ technical analysis_ and fundamental analysis. I’ve even read books and countless articles about these techniques.

In a nutshell, technical analysis argues that you can identify the right time to buy and sell a stock using technical indicators that are based on the stock’s historical price and volume movements. On the other hand, fundamental analysis argues that you can measure the actual intrinsic value of a stock based on the fundamental information found in a company’s financial statements.

Both types of analyses made sense to me and I was eager to use them to inform my trades; however, I was always frustrated about one main thing:

There are many possible strategies to take, but no systematic way to choose one. In practice, most trades still end up as “gut feel” decisions that are not driven by data.

So how can we possibly assess these strategies? We can do this by comparing the expected return on investment (ROI) that we can get from each approach. The best way to do this, is with a method called _backtesting — _where a strategy is assessed by simulating how it would have performed had you used it in the past.

Now, there are already quite a few backtesting frameworks out there, but most of them require advanced knowledge of coding. It’s typical for a simple hello world implementation to require as much as ~30 lines of code.

To fill this gap, I decided to create fastquant, with the goal of bringing backtesting to the mainstream by making it as simple as possible. With fastquant, we can backtest trading strategies with as few as 3 lines of code!

fastquant is essentially a wrapper for the popular backtrader framework that allows us to significantly simplify the process of backtesting from requiring at least 30 lines of code on backtrader, to as few as 3 lines of code on fastquant.

For the rest of this article, I will walk you through how to backtest a simple moving average crossover (SMAC) strategy through the historical data of Jollibee Food Corp. (JFC).

Let’s get started!

Backtest our first strategy

Install fastquant

It’s as simple as using pip install!

#stocks #money #finance #trading #data-science

Backtest Your Trading Strategy with Only 3 Lines of Python
10.30 GEEK