InvestorUnknown

[InvestorUnknown] Performance Metrics

Overview
The Performance Metrics indicator is a tool designed to help traders and investors understand and utilize key performance metrics in their strategies. This indicator is inspired by the Rolling Risk-Adjusted Performance Ratios created by @EliCobra, but it offers enhanced usability and additional features to provide a more user-friendly code for understanding the calculations.

Features

Rolling Lookback:
Dynamic Lookback Calculation: The indicator automatically calculates the number of bars from the start of the asset's price history, up to a maximum of 5000 bars due to TradingView platform restrictions.
Adjustable Lookback Period: Users can manually set a lookback period or choose to use the rolling lookback feature for dynamic calculations.

RollingLookback() =>
    x = bar_index + 1
    y = x > 4999 ? 5000 : x > 1 ? (x - 1) : x
    y

Trend Analysis
The Trend Analysis section in this indicator helps traders identify the direction of the market trend based on the balance of positive and negative returns over time. This is achieved by calculating the sums of positive and negative returns and optionally smoothing these values to provide a clearer trend signal.
Configuration: Enable smoothing if you want to reduce noise in the trend analysis. Choose between EMA and SMA for smoothing. Set the length for smoothing according to your preference for sensitivity (shorter lengths are more sensitive to changes, longer lengths provide smoother signals).
Interpretation:
- A positive trend difference (filled with green) indicates a bullish trend, suggesting more positive returns.
- A negative trend difference (filled with red) indicates a bearish trend, suggesting more negative returns.
- Colored bars provide a quick visual cue on the trend direction, helping to make timely trading decisions.

// The Trend Analysis section calculates and optionally smooths the sums of positive and negative returns.
// This helps identify the trend direction based on the balance of positive and negative returns over time.
Ps = Smooth ? Smooth_type == "EMA" ? ta.ema(pos_sum, Smooth_len) : ta.sma(pos_sum, Smooth_len) : pos_sum
Ns = Smooth ? Smooth_type == "EMA" ? ta.ema(neg_sum, Smooth_len) : ta.sma(neg_sum, Smooth_len) : neg_sum
// Calculate the difference between smoothed positive and negative sums
dif = Ps + Ns

Performance Metrics Table
Visual Table Display: Option to display a table on the chart with calculated performance metrics. This table includes comprehensive metrics like Mean Return, Positive and Negative Mean Return, Standard Deviation, Sharpe Ratio, Sortino Ratio, and Omega Ratio.

Performance Metrics Calculated

Mean Return:
Description: The average return over the lookback period.
Purpose: Helps in understanding the overall performance of the asset by providing a simple average of returns.

Positive Mean Return:
Description: The average of all positive returns over the lookback period.
Purpose: Highlights the average gain during profitable periods, giving insight into the asset's potential upside.

Negative Mean Return:
Description: The average of all negative returns over the lookback period.
Purpose: Focuses on the average loss during unprofitable periods, helping to assess the downside risk.

Standard Deviation (STDEV):
Description: A measure of volatility that calculates the dispersion of returns from the mean.
Purpose: Indicates the risk associated with the asset. Higher standard deviation means higher volatility and risk.

Sharpe Ratio:
Description: A risk-adjusted return metric that divides the mean return by the standard deviation of returns. It can be annualized if selected.
Purpose: Provides a standardized way to compare the performance of different assets by considering both return and risk. A higher Sharpe Ratio indicates better risk-adjusted performance.

sharpe_ratio = mean_all / stddev_all * (Annualize ? math.sqrt(Lookback) : 1)

Sortino Ratio:
Description: Similar to the Sharpe Ratio but focuses only on downside volatility. It divides the mean return by the standard deviation of negative returns. It can be annualized if selected.
Purpose: Offers a better assessment of downside risk by ignoring upside volatility. A higher Sortino Ratio indicates a higher return per unit of downside risk.

sortino_ratio = mean_all / stddev_neg * (Annualize ? math.sqrt(Lookback) : 1)

Omega Ratio:
Description: The ratio of the probability-weighted average of positive returns to the probability-weighted average of negative returns.
Purpose: Measures the overall likelihood of positive returns compared to negative returns. An Omega Ratio greater than 1 indicates more frequent and/or larger positive returns compared to negative returns.

omega_ratio = (prob_pos * mean_pos) / (prob_neg * -mean_neg)

By calculating and displaying these metrics, the indicator provides a comprehensive view of the asset's performance, enabling traders and investors to make informed decisions based on both returns and risk-adjusted metrics.

Use Cases:

Performance Evaluation: Assesses an asset's performance by analyzing both returns and risk factors, giving a clear picture of profitability and volatility.
Risk Comparison: Compares the risk-adjusted returns of different assets or portfolios, aiding in identifying investments with superior risk-reward trade-offs.
Risk Management: Helps manage risk exposure by evaluating downside risks and overall volatility, enabling more informed and strategic investment decisions.
Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?