Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Function to Calculate Max Drawdown for N-days

How to write a function to calculate a stock's max drawdown percentage in the past N-days? Or in a range of time.

The function prototype could be like this:

def calc_max_drawdown(context, data, stock_symbol, past_n_days):  
    ...  
    return max_drawdown  

For example:
calc_max_drawdown(context, data, 'SPY', 30)