1
$\begingroup$

This is the simplest backtest I've come up with, yet I can't figure out how TradingView has calculated the Sharpe ratio to be 0.577. I've set the risk_free_rate=0. Is it possible to extract the formula that TradingView is using from this simple example, or more data is needed?

enter image description here

$\endgroup$
2

1 Answer 1

2
$\begingroup$

According to the documentation, it requires at least 3 periods.

Given the output shows 1% profit you get the following in Python,

# define return vector
ret = [0.01,0,0]
# compute SR 
round(np.mean(ret)/np.std(ret,ddof=1),3)

which yields 0.577

I voted to close this question because it is off topic here. It's probably suited for money stack exchange but it is not a quantitative finance question.

$\endgroup$
3
  • $\begingroup$ Thanks. I wasn't aware of the difference between sample and population standard deviation, and didn't think of adding a null trade. Now there's another problem: When I have three identical trades with ret = [0.0164, 0.0164, 0.0164], I expect the Sharpe ratio to be N/A or infinity. However, TradingView shows 0.369. What kind of standard deviation could they possibly be using? $\endgroup$
    – asmani
    Commented May 18, 2023 at 15:06
  • $\begingroup$ Wondering why it is off-topic. The question is relevant and I'm stuck too trying to figure out the TV Sharpe ratio formula. $\endgroup$
    – Begoodpy
    Commented Oct 5, 2023 at 21:05
  • $\begingroup$ I explained it in my answer. You can see what is on topic here. This site is intended for professionals and academics. The link also explains that Basic Finance and Definitions are better suited for Personal Finance & Money. $\endgroup$
    – AKdemy
    Commented Oct 5, 2023 at 22:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.