1

I am very new to Python, Pandas and to portfolio statistics in general. I have a large portfolio with different assets and over 4000 rows of return numbers. I am trying to calculate the start, end and duration of top N max drawdowns for each asset (column). I am using Pandas library and I am applying the nsmallest() on my drawdown list to find out the top n smallest values which are max drawdowns, I then iterate through the columns and add max drawdown values for each asset to the ndrawdowns list. However, I struggle to find the start of those drawdowns and duration. This is what I have so far:

def max_drawdown(self, ddcount):

    returns = self.df
    maxd = returns.cummax()
    dd = returns/maxd - 1.0


             def finddrawdowns(n, count=ddcount):
             dd1 = dd.nsmallest(count, dd.columns[n])
             d = dd1[dd1.columns[n]]
             return d 

    ndrawdowns = []
    for a in range(0, length):
        values = finddrawdowns(a)
        ndrawdowns.append(values)

    return ndrawdowns

Any recommendations would be welcome! Thank you!

aaaaaa
  • 11
  • 1
  • Hard to tell what you're trying to accomplish without some sample data. Also, just as a note to simplify your code and take advantage of `pandas`...have a look at https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html. The `apply` method can eliminate the need for many loops. – OverflowingTheGlass Jul 28 '17 at 15:35

0 Answers0