I'm exploring the use of portfolio metrics to evaluate asset performance (after all, portfolio equity over time and asset price over time are both time series).
So far i'm able to easily calculate % return and sharpe ratio (there's actually an indicator for sharpe), but I need a little guidance in calculating Drawdown percent for a stock over a period of time, using the in-built statistics method:
In the docs for Statistics.DrawdownPercent, i see the following method signature:
public static decimal DrawdownPercent(
SortedDictionary<DateTime,decimal> equityOverTime,
int rounding
)
But there's no details of what is expected for 'equityOverTime'. Looking at C#'s definition of a 'SortedDictionary', it seems this is a dictionary where the key is a datetime. However, in the docs for Statistics.DrawdownValue, (a related method) it refers to "equityOverTime" as "Array of portfolio value over time", suggesting it is a literal array (ie: a list) of floats (doubles).
Any thoughts on what should actually be used for 'equityOverTime'?
.ekz.
For additional context, here's the code I have now; i am passing a dict with dateTime keys:
# Get 1 min bars, used to calculate Drawdown for the day history = self.algo.History(symbol, 390, Resolution.Minute) performance = {} for index, row in history.loc[symbol].iterrows(): performance[index]=(row['close']) ddownPct = Statistics.DrawdownPercent(performance, 2)
...and here's the error I am getting:
TypeError : No method matches given arguments for DrawdownPercent: (<class 'dict'>, <class 'int'>) (Open Stacktrace)
Derek Melchin
Hi .ekz.,
There is no SortedDictionary class in Python. We can create our own drawdown methods instead:
def current_drawdown_percent(self, equity_curve): hwm = max(equity_curve) current = equity_curve[-1] return (hwm - current) / hwm * 100 def max_drawdown_percent(self, equity_curve): i = np.argmax(np.maximum.accumulate(equity_curve) - equity_curve) if equity_curve[:i].size == 0: return np.nan j = np.argmax(equity_curve[:i]) return abs((equity_curve[i]/equity_curve[j]) - 1) * 100
where `equity_curve` is a pandas Series.
See the attached backtest for reference.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
.ekz.
Ha! I was literally just tagging you in a comment about this, in another related thread. I popped over to this chrome tab to copy the url, et voila, i see you have already given an answer :)
Thanks for your help, this is exactly what I needed!
.ekz.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!