Parabolic SAR Trading Strategy

How To Build A Profitable Parabolic SAR Trading Strategy Using Python

Introduction

This tutorial will explain how to implement the Parabolic SAR indicator to build a trading strategy in Python, and along the way, it will introduce the Object Oriented Programming (OOP) approach to download the data, calculate the Parabolic SAR strategy, and generate the buy and sell signals. It’s all about how to build a profitable Parabolic SAR trading strategy using Python.

This tutorial will use data from the ETF AGG; additionally, in the last section, it will implement the QuantStats Python package to obtain performance and risk metrics. But please keep in mind that the main aim of the article is to show how it can be coded using Python. The trading strategy itself is of minor importance.

Parabolic SAR

The Parabolic SAR is a trading indicator developed by Welles Wilder, and it aims to identify trends and reversals. This indicator finds short-term entry and exit signals. The Parabolic SAR has as a characteristic that its formula changes depending on whether there is a downtrend or upward trend.

 Welles Wilder does not recommend applying this indicator in intervals below an hour or when the price fluctuation is flat.

The calculation for an upward trend is:

\text{PSAR}_t = \text{PSAR}_{t-1} + a_{t-1} (\text{EP}_{t-1} - \text{PSAR}_{t-1})

Meanwhile, the calculation for a downtrend is

\text{PSAR}_t = \text{PSAR}_{t-1} - a_{t-1} (\text{EP}_{t-1} - \text{PSAR}_{t-1})

The idea is to add +at-1(EPt-1 – PSARt-1) in an upward trend or subtract -at-1(EPt-1 – PSARt-1) in a downward trend, the expected result, to the previous Parabolic SAR value.

Where:

PSARt is the Parabolic SAR of the previous t.

PSARt-1 is the Parabolic SAR of the previous period t-1. Example: if today is day ten (or week ten), then t-1 is day nine (or week nine)

at-1 is the accelerating factor starts at 0.02, and in an upward trend, it will increase 0.02 every time there is a higher high, until 0.2; in a downtrend, it will increase 0.02 every moment there is a lower low, until 0.2.

EPt-1 is the lowest low for a downtrend or the highest high for an upward trend.

Python Example

Download Data and Parabolic SAR Estimatio