Suppose that I backtest a strategy with the following specifications:
- Data time-frame: 4H
- Backtest duration: 3 months
And here is the result:
- #Trades: 2
- Returns of trades: [+5%, +10%]
Now how should I calculate anualized sharpe ration to get more realistic results?
According to following code which is bringed in the notebook:
def annualized_sharpe_ratio(returns, N=252):
return np.sqrt(N) * returns.mean() / returns.std()
If I select N=1008 (because my trading time-frame is 4H, so 252*4), I will get the ASR = 66.675...! because:
- N = 252 * 4 = 1008, sqrt(n) = 31.75
- Mean of returns = 7.5
- STD of returns = 3.5
- SR = 2.1
- ASR = 31.75 * 2.1 = 66.675
Am I doing something wrong? How should I calculated a realistic ASR in such situations?
Thanks in advance.
There are quite a few issues with your calculation and understanding of Sharpe ratio. Sharpe ratio is a statistics which is the ratio of expected excess returns to expected volatility.
If we assume each trading day has 8 trading hours, then for timeframe of 4H with 3 months (60 business days approx) of data, your returns series will have (8/4) daily returns metric X 60 = 120 data points. Also this returns metric to calculate are NOT trade-wise profit or loss, but 4-hourly returns on the portfolio. Assuming you had only two trades each lasting 4 hours each, the returns series for Sharpe calculation should look like[0, 0, …, 5%, 0,0,…, 10%, 0,…], with total 120 points, and NOT just [+5%, +10%] with 2 points. This changes your calculation drastically, your standard deviation is now 1.013% and mean a meagre 0.125%.
Second, Sharpe ratio (see the definition above) is an estimate and is only as good as your input data. Estimating Sharpe ratio of strategy that traded 2 times in 3 months is like estimating average population age of a city by sampling a couple of customers at the local Starbucks. You simply have far too less data to conclude anything statistically. A strategy that trades twice in 3 months will require at least 5 years of data (around 40 trades expected) for anything statistically significant.
Finally the annualization of sharpe ratio (see here for a very good discussion on the topic) is non-trivial. The annualization factor you use works if the portfolio returns are normally distributed. For strategy that trades twice a month is probably non-linear and you need to adjust your annualization factors accordingly.
Hello Mohammad,
In the function annualized_sharpe_ratio you need to pass your daily returns. You will keep N=252 as the number of trading days in an year are 252 to get annual sharpe ratio. So it won't be 1008.
Also, you will have to be specific about the duration of your returns [+5,+10]. Are these daily or weekly or monthly returns. This needs to be stated for you to calculate the average returns for that duration. Once you know that duration for which these are the returns you can generalise it to longer periods like one year for shape ratio in this case in this case.
If these are returns over multiple days you'll have to find the average returns for per day within that period to get the average daily returns. For both, +5% and for +10%. Thereafter those average returns can be used to annualise the shape ratio.
Thank you all. I used 1008 as N, because I supposed crypto market which is 24/7 open, but forgot to mention that in question.
This is the key I was looking for and infered from your great answers: I should record and use returns based on the time unit of the strategy time frame. for example if the first trade last for 8 hours, had +2% in the first four hours and +3% in the second one, I should store and use returns list like this:
[0, 0, …, 2, 3, 0, 0, …]
Thanks a lot - I got what should I do completely.