OPEN-SOURCE SCRIPT
Analyst Targets Probability

This indicator calculates the probability of the current stock price reaching or exceeding the analyst-provided high, average, and low price targets within a one-year time horizon. It utilizes a geometric Brownian motion (GBM) model, a standard approach in financial modeling that assumes log-normal price distribution with constant volatility.
### Key Features:
- **Analyst Targets**: Automatically pulls the high, average, and low one-year price targets from TradingView's syminfo data.
- **Risk-Free Rate**: Fetched from the 1-year US Treasury yield (symbol: TVC:US01Y). Defaults to 4% if unavailable.
- **Dividend Yield**: Uses trailing twelve-month (TTM) dividends per share (DPS) from financial data, divided by current price. Defaults to 0% if unavailable.
- **Volatility**: Computed as annualized historical volatility based on 252 trading days of daily log returns. Falls back to a 20-day period if insufficient data, or defaults to 30% if still unavailable.
- **Probability Calculation**: Employs the barrier hitting probability formula under GBM:
- Drift (μ) = risk-free rate - dividend yield - (volatility² / 2)
- The formula for probability P of hitting target H from current price S₀ over time T is:
P = Φ(d₊) + (H / S₀)^p ⋅ Φ(d₋) for H > S₀ (or adjusted for H < S₀)
Where l = ln(max(H, S₀)/min(H, S₀)), ν = drift, p = -2ν / σ², d₊ = (-l + νT) / (σ√T), d₋ = (-l - νT) / (σ√T), and Φ is the standard normal CDF (approximated using a polynomial method for accuracy).
- **Output Display**: A table in the top-right corner shows each target type, its value, and the estimated probability (as a percentage). "N/A" appears if data is unavailable or calculations cannot proceed (e.g., zero volatility).
### Assumptions and Limitations:
- Assumes constant volatility and drift, no transaction costs, and continuous trading (real markets may deviate due to jumps, news events, or changing conditions).
- Probabilities are model-based estimates and not guarantees; they represent the likelihood under risk-neutral measure.
- Best suited for stocks with available analyst targets and historical data; may default to assumptions for less-liquid symbols.
- No user inputs required—fully automated using TradingView's data sources.
This script is provided under the Mozilla Public License 2.0. For educational and informational purposes only; not financial advice. Test on your charts and consider backtesting for validation.
### Key Features:
- **Analyst Targets**: Automatically pulls the high, average, and low one-year price targets from TradingView's syminfo data.
- **Risk-Free Rate**: Fetched from the 1-year US Treasury yield (symbol: TVC:US01Y). Defaults to 4% if unavailable.
- **Dividend Yield**: Uses trailing twelve-month (TTM) dividends per share (DPS) from financial data, divided by current price. Defaults to 0% if unavailable.
- **Volatility**: Computed as annualized historical volatility based on 252 trading days of daily log returns. Falls back to a 20-day period if insufficient data, or defaults to 30% if still unavailable.
- **Probability Calculation**: Employs the barrier hitting probability formula under GBM:
- Drift (μ) = risk-free rate - dividend yield - (volatility² / 2)
- The formula for probability P of hitting target H from current price S₀ over time T is:
P = Φ(d₊) + (H / S₀)^p ⋅ Φ(d₋) for H > S₀ (or adjusted for H < S₀)
Where l = ln(max(H, S₀)/min(H, S₀)), ν = drift, p = -2ν / σ², d₊ = (-l + νT) / (σ√T), d₋ = (-l - νT) / (σ√T), and Φ is the standard normal CDF (approximated using a polynomial method for accuracy).
- **Output Display**: A table in the top-right corner shows each target type, its value, and the estimated probability (as a percentage). "N/A" appears if data is unavailable or calculations cannot proceed (e.g., zero volatility).
### Assumptions and Limitations:
- Assumes constant volatility and drift, no transaction costs, and continuous trading (real markets may deviate due to jumps, news events, or changing conditions).
- Probabilities are model-based estimates and not guarantees; they represent the likelihood under risk-neutral measure.
- Best suited for stocks with available analyst targets and historical data; may default to assumptions for less-liquid symbols.
- No user inputs required—fully automated using TradingView's data sources.
This script is provided under the Mozilla Public License 2.0. For educational and informational purposes only; not financial advice. Test on your charts and consider backtesting for validation.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.