Skip to content

Instantly share code, notes, and snippets.

@tschm
Created November 17, 2015 09:07
Show Gist options
  • Save tschm/dffe446254fee1be53ce to your computer and use it in GitHub Desktop.
Save tschm/dffe446254fee1be53ce to your computer and use it in GitHub Desktop.
Compute the drawdown for a price time series...
import numpy as np
import pandas as pd
def drawdown(price):
high_water_mark = np.empty(len(price.index))
moving_max_value = 0
for i, value in enumerate(price.values):
moving_max_value = max(moving_max_value, value)
high_water_mark[i] = moving_max_value
return pd.Series(data=1.0 - (price / high_water_mark), index=price.index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment