![]() ![]() In this article we are going to discuss how to assess the performance of a strategy post-backtest using the previously constructed equity curve DataFrame in the Portfolio object. In that article I outline that the (annualised) Sharpe ratio is calculated via: We've already considered the Sharpe Ratio in a previous article. Where $R_a$ is the returns stream of the equity curve and $R_b$ is a benchmark, such as an appropriate interest rate or equity index. The maximum drawdown and drawdown duration are two additional measures that investors often uses to assess the risk in a portfolio. The former quantities the highest peak-to-trough decline in an equity curve performance, while the latter is defined as the number of trading periods over which it occurs. ![]() In this article we will implement the Sharpe ratio, maximum drawdown and drawdown duration as measures of portfolio performance for use in the Python-based Event-Driven Backtesting suite. Note that the Sharpe ratio is a measure of risk to reward (in fact it is one of many!).Īs with most of our calculation-heavy classes we need to import NumPy and pandas: # performance.py The first task is to create a new file performance.py, which stores the functions to calculate the Sharpe ratio and drawdown information. It has a single parameter, that of the number of periods to adjust for when scaling up to the annualised value. Usually this value is set to 252, which is the number of trading days in the US per year. However, if your strategy trades within the hour you need to adjust the Sharpe to correctly annualise it. Thus you need to set periods to $252*6.5 = 1638$, which is the number of US trading hours within a year. If you trade on a minutely basis, then this factor must be set to $252*6.5*60=98280$. The create_sharpe_ratio function operates on a pandas Series object called returns and simply calculates the ratio of the mean of the period percentage returns and the period percentage return standard deviations scaled by the periods factor: # performance.pyĭef create_sharpe_ratio(returns, periods=252):Ĭreate the Sharpe ratio for the strategy, based on aīenchmark of zero (i.e. Return np.sqrt(periods) * (np.mean(returns)) / np.std(returns) Returns - A pandas Series representing period percentage returns. While the Sharpe ratio characterises how much risk (as defined by asset path standard deviation) is being taken per unit of return, the "drawdown" is defined as the largest peak-to-trough drop along an equity curve. The create_drawdowns function below actually provides both the maximum drawdown and the maximum drawdown duration. The former is the aforementioned largest peak-to-trough drop, while the latter is defined as the number of periods over which this drop occurs. There is some subtlety required in the interpretation of the drawdown duration as it counts trading periods and thus is not directly translateable into a temporal unit such as "days". The function starts by creating two pandas Series objects representing the drawdown and duration at each trading "bar". Then the current high water mark (HWM) is established by determining if the equity curve exceeds all previous peaks. The drawdown is then simply the difference between the current HWM and the equity curve. If this value is negative then the duration is increased for every bar that this occurs until the next HWM is reached. The function then simply returns the maximum of each of the two Series: # performance.pyĬalculate the largest peak-to-trough drawdown of the PnL curveĪs well as the duration of the drawdown. Pnl - A pandas Series representing period percentage returns.ĭrawdown, duration - Highest peak-to-trough drawdown and duration. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |