Zettt

Sharpe Ratio v4

I'm publishing this indicator freely, because I'd like to get it reviewed by other people. This indicator was written whilst reading the book Systematic Trading by Robert Carver. In this book Carver describes trading rules that use a "dynamic" position size based on something like an evolving Sharpe Ratio. There are only a few other Sharpe indicators on TradingView, but they are either undocumented or use closed source code. You can use the following code as you wish for your own projects.

I'd like to let other people see this work, and let me know where they think this script is wrong, so that I can improve it.

Here's a basic rundown of Sharpe Ratio and its calculation.

SR is defined as: (excess) return minus the risk free rate divided by standard deviation of those returns. (This is where we're uncertain. Is the standard deviation of the returns, or just the closes?) But anyway the calculation itself is pretty simple:

SR = (r – b) ÷ s

Where r is the return of the asset over a certain period.
b is the interest rate of the risk-free asset.
s is the standard deviation of the returns over the same period.

For this indicator to "work" correctly, we're assuming the risk-free rate is 0. In fact, I did not include b at all in the indicator because it would make things too complicated, and go beyond the aim of this work.

To calculate the returns over a certain period, I'm using Rate of Change. Then calculating the standard deviation of those returns is pretty easy because we can use the same lookback period we used for ROC for the StDev calculation, thus:

averageReturn = ta.roc(close, lookbackLength)
stdev = ta.stdev(averageReturn, lookbackLength)
sharpe = (averageReturn / stdev)


Please leave a comment below if you believe this is incorrect. The chart shows a normal ROC indicator for comparison. I've also created a "bands" version of this indicator, which I'm planning to also release. The Keltner channel is just for comparing it with the StDev bands.

오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?