Notebook

Notebook to plot the price and drawdown of a particular stock

In [29]:
# Import some methods we will be needing
from quantopian.research import get_pricing, returns
from empyrical import max_drawdown
In [30]:
# First let's make a place where we can easily set the stock and dates we want to check
stock = 'TSLA'
start_date = '1-1-2020'
end_date = '9-1-2020'
In [32]:
# Next let's get both the stock close prices and daily returns over the dates
stock_prices = get_pricing(stock, start_date, end_date, fields='price')
stock_returns = returns(stock, start_date, end_date, price_field='price')

# To get the max drawdown use the empyrical drawdown method
# Apply it over an expanding window of stock_returns
stock_drawdown = stock_returns.expanding().apply(max_drawdown)

# Now plot these. Setting secondary_y=True adds a second Y axis for returns
stock_prices.plot()
stock_returns.plot(secondary_y=True);
stock_drawdown.plot(secondary_y=True);

For TSLA over the period 1-1-2020 to 9-1-2020 it looks like the max drawdown was 60%

For AAPL over the period 1-1-2020 to 9-1-2020 it looks like the max drawdown was about 32%

In [ ]: