I want to calculate the sharp ratio, but did’nt find exact method. I found something below in manual of pinescript, but don’t understand how to calculate standard deviation right.
The formula for the Sharpe ratio is SR = (MR – RFR) / SD, where MR is the average return for a period (monthly for a trading period of 3 or more months or daily for a trading period of 3 or more days), and RFR is the risk-free rate of return (by default, 2% annually. Can be changed with the “risk_free_rate” parameter of the “strategy()” function). SD is the standard deviation of returns. Thus, this formula yields a value that could be loosely defined as return per unit risked if we accept the premise that variability is risk. The higher Sharpe ratio, the smoother the equity curve. Having a smooth equity curve is an important objective for many traders.
So my code
avg_returns = strategy.netprofit / strategy.equity
stddev = ta.stdev(avg_returns,?????)
risk_free_rate = 0.02
sharpe_ratio = math.round((avg_returns - risk_free_rate) / stddev,2)
Sam Mayilyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.