Step 2: Create the drawdown functionĭrawdown is computed with 4 lines of code. I want to keep it simple so I use the S&P500 ETF. Drawdown is usually computed with the returns of a portfolio. I use yfinance to get stock data – in this case, SPY. Then I get data and compute the simple returns. I start by importing the libraries I need. Today I’m going to walk you through it step by step. Unfortunately, most people don’t consider drawdown when managing their investments. Computing it helps you compare the relative riskiness between assets or strategies. Every trading strategy experiences drawdowns. In today’s issue, I’m going to show you how to compute the drawdown of the SPY ETF with Python.ĭrawdown is the maximum decline from peak to trough during a specific period before a new peak is reached.