import numpy as np

def calculateMaxDD(cumret):
    """
    Python implementation of the MATLAB calculateMaxDD function.
    Calculates maximum drawdown and maximum drawdown duration
    based on cumulative COMPOUNDED returns.
    
    Parameters:
    cumret (ndarray): Cumulative compounded returns
    
    Returns:
    tuple: (maxDD, maxDDD) Maximum drawdown and maximum drawdown duration
    """
    if isinstance(cumret, list):
        cumret = np.array(cumret)
    
    # Initialize high watermarks, drawdowns, and drawdown durations
    highwatermark = np.zeros_like(cumret)
    drawdown = np.zeros_like(cumret)
    drawdownduration = np.zeros_like(cumret)
    
    # Calculate drawdowns and durations
    for t in range(1, len(cumret)):
        highwatermark[t] = max(highwatermark[t-1], cumret[t])
        # Drawdown on each day
        drawdown[t] = (1 + cumret[t]) / (1 + highwatermark[t]) - 1
        
        if drawdown[t] == 0:
            drawdownduration[t] = 0
        else:
            drawdownduration[t] = drawdownduration[t-1] + 1
    
    # Maximum drawdown
    maxDD = np.min(drawdown)
    
    # Maximum drawdown duration
    maxDDD = np.max(drawdownduration)
    
    return maxDD, maxDDD 