adridem

Rolling Sortino Ratio with Ref Ticker V1.0 [ADRIDEM]

Overview

The Rolling Sortino Ratio with Ref Ticker script is designed to offer a comprehensive view of the Sortino ratios for a selected reference ticker and the current ticker. This script helps investors compare risk-adjusted returns between two assets over a rolling period, providing insights into their relative performance and risk. Below is a detailed presentation of the script and its unique features.

Unique Features of the New Script

  • Reference Ticker Comparison : Allows users to compare the Sortino ratio of the current ticker with a reference ticker, providing a relative performance analysis. Default ticker is BTCUSDT but can be changed.
  • Customizable Rolling Window : Enables users to set the length for the rolling window, adapting to different market conditions and timeframes. The default value is 252 bars, which approximates one year of trading days, but it can be adjusted as needed.
  • Smoothing Option : Includes an option to apply a smoothing simple moving average (SMA) to the Sortino ratios, helping to reduce noise and highlight trends. The smoothing length is customizable, with a default value of 4 bars.
  • Visual Indicators : Plots the smoothed Sortino ratios for both the reference ticker and the current ticker, with distinct colors for easy comparison. Additionally, horizontal lines and a shaded background help identify key levels.
  • Dynamic Background Color : Adds a gray-blue transparent background between the Sortino ratio levels of 0 and 1, highlighting the critical region where risk-adjusted returns are assessed.

Originality and Usefulness

This script uniquely combines the analysis of Sortino ratios for a reference ticker and the current ticker, providing a comparative view of their risk-adjusted returns. The inclusion of a customizable rolling window and smoothing option enhances its adaptability and usefulness in various market conditions.

Signal Description

The script includes several features that highlight potential insights into the risk-adjusted returns of the assets:

  • Reference Ticker Sortino Ratio : Plotted as a red line, this represents the smoothed Sortino ratio for the user-selected reference ticker.
  • Current Ticker Sortino Ratio : Plotted as a white line, this represents the smoothed Sortino ratio for the current ticker.
  • Horizontal Lines and Background Color : Lines at 0 and 1, along with a shaded background between these levels, help to quickly identify the regions of positive and strong risk-adjusted returns.

These features assist in identifying relative performance differences and confirming the strength or weakness of risk-adjusted returns between the two tickers.

Detailed Description

Input Variables

  • Length for Rolling Window (`length`) : Defines the range for calculating the rolling Sortino ratio. Default is 252.
  • Smoothing Length (`smoothing_length`) : The number of periods for the smoothing SMA. Default is 4.
  • Annual Risk-Free Rate (`riskFreeRate`) : The annual risk-free rate used in the Sortino ratio calculation. Default is 0.02 (2%).
  • Reference Ticker (`ref_ticker`) : The ticker symbol for the reference asset. Default is "BINANCE:BTCUSDT".

Functionality

Sortino Ratio Calculation : The script calculates the daily returns, mean return, and downside deviation for both the reference ticker and the current ticker. These values are used to compute the annualized Sortino ratio.

```pine
ref_dailyReturn = ta.change(ref_close) / ref_close
ref_meanReturn = ta.sma(ref_dailyReturn, length)
ref_downsideDeviation = ta.stdev(math.min(ref_dailyReturn, 0), length)
ref_annualizedReturn = ref_meanReturn * length
ref_annualizedDownsideDev = ref_downsideDeviation * math.sqrt(length)
ref_sortinoRatio = (ref_annualizedReturn - riskFreeRate) / ref_annualizedDownsideDev
```


Smoothing : A simple moving average is applied to the Sortino ratios to smooth the data.

```pine
smoothed_ref_sortinoRatio = ta.sma(ref_sortinoRatio, smoothing_length)
smoothed_current_sortinoRatio = ta.sma(current_sortinoRatio, smoothing_length)
```


Plotting : The script plots the smoothed Sortino ratios for both the reference ticker and the current ticker, along with horizontal lines and a shaded background.

```pine
plot(smoothed_ref_sortinoRatio, title="Ref Ticker Sortino Ratio", color=color.rgb(255, 82, 82, 50), linewidth=2)
plot(smoothed_current_sortinoRatio, title="Current Ticker Sortino Ratio", color=color.white, linewidth=2)
h0 = hline(0, "Zero Line", color=color.gray)
h1 = hline(1, "One Line", color=color.gray)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
```


How to Use

  • Configuring Inputs : Adjust the detection length, smoothing length, and risk-free rate as needed. Set the reference ticker to the desired asset for comparison.
  • Interpreting the Indicator : Use the plotted Sortino ratios and background shading to assess the relative risk-adjusted returns of the reference and current tickers.
  • Signal Confirmation : Look for differences in the Sortino ratios to identify potential performance advantages or weaknesses. The background shading helps to highlight key levels of risk-adjusted returns.

This script provides a detailed comparative view of risk-adjusted returns, aiding in more informed decision-making by highlighting key differences between the reference ticker and the current ticker.

Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?