# Figuring out how TradingView calculates the Sharpe ratio [closed]

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?

• Have you looked at this: tradingview.com/support/solutions/…. Commented May 18, 2023 at 3:38
• Yes, and it didn't help. Commented May 18, 2023 at 3:39

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.

• 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? Commented May 18, 2023 at 15:06
• Wondering why it is off-topic. The question is relevant and I'm stuck too trying to figure out the TV Sharpe ratio formula. Commented Oct 5, 2023 at 21:05
• 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. Commented Oct 5, 2023 at 22:13