Skip to content

Passed in daily PNL while cumulative PNL is expected. #19

Description

@julius-datajunkie
def compute_cdar(pnl: array_like, var: array_like) -> np.ndarray:
    """Compute the Drawdown of a portfolio

    Parameters
    ----------
    pnl : array_like
        Profit and Loss values.

    Returns
    -------
    np.ndarray
        Drawdowns
    """
    # Compute the drawdowns
    running_max = np.maximum.accumulate(pnl)
    drawdowns = running_max - pnl

    drawdown_values = np.zeros_like(var)

    for i, item in enumerate(var):
        drawdown_values[i] = np.nanmean(drawdowns[drawdowns > item])

    drawdown_values = np.nan_to_num(drawdown_values)

    return drawdown_values

The above implementation of compute_cdar expects pnl argument to the cumulative pnl, while the the pnl passed in is daily pnl.

Reference: https://scikit-portfolio.github.io/scikit-portfolio/efficient_cdar/

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions