OPEN-SOURCE SCRIPT

Performance-based Asset Weighting(MTF)

71
**Performance-Based Asset Weighting (MTF/Symbol Free Setting)**

#### Overview
This indicator is a tool that visualizes the relative strength of performance (price change rate) as “weight (allocation ratio)” for **four user-defined stocks**.

By setting any specified past point in time as the baseline (where all symbols are equally weighted at 25%), it aims to provide an intuitive understanding of which symbols outperformed others and attracted capital, or underperformed and saw capital outflows.

**【Default Settings and Application Scenario: Pension Fund Rebalancing Analysis】**
The default settings reference the basic portfolio of Japan's Government Pension Investment Fund (GPIF), configuring four major asset classes: domestic equities, foreign equities, domestic bonds, and foreign bonds. It is known that when market fluctuations cause deviations from this equal-weighted ratio, rebalancing occurs to restore the original ratio (selling assets whose weight has increased and buying assets whose weight has decreased).
Analyzing using this default setting can serve as a reference point for considering **“whether rebalancing sales (or purchases) by pension funds and similar entities are likely to occur in the future.”**

**【Important: Usage Notes】**
The weights shown by this indicator are **theoretical reference values** calculated solely based on performance from the specified start date. Even if large investors conduct significant rebalancing (asset buying/selling) during the period, those transactions themselves are not reflected in this chart's calculations.
Therefore, please understand that the actual portfolio ratios may differ. **Use this solely as a rough guideline. **

#### Key Features
* **Freely configure the 4 assets for analysis:** You can freely set any 4 assets (stocks, indices, currencies, cryptocurrencies, etc.) you wish to compare via the settings screen.
* **Performance-based weight calculation:** Rather than simple price composition ratios, it calculates each asset's price change since the specified start date as a “performance index” and displays each asset's proportion of the total sum.
* **Freely set analysis start date:** You can set any desired starting point for analysis, such as “after the XX shock” or “after earnings announcements,” using the calendar.
* **Multi-Timeframe (MTF) Support:** Independently of the timeframe displayed on the chart, you can freely select the timeframe (e.g., 1-hour, 4-hour, daily) used by the indicator for calculations.

#### Calculation Principle
This indicator calculates weights in the following three steps:

1. **Obtaining the Base Price**
Obtain the closing price for each of the four stocks on the user-set “Start Date for Weight Calculation.” This becomes the **base price** for analysis.

2. **Calculating the Performance Index**
Divide the current price of each stock by the **base price** obtained in Step 1 to calculate the “Performance Index”.
`Performance Index = Current Price ÷ Base Date Price`
This quantifies how many times the current performance has increased compared to the base date performance, which is set to “1”.

3. **Calculating Weights**
Sum the “Performance Indexes” of the four stocks. Then, calculate the percentage contribution of each stock's Performance Index to this total sum and plot it on the chart.
`Weight (%) = (Individual Performance Index ÷ Total Performance Index of 4 Stocks) × 100`

Using this logic, on the analysis start date, all stocks' performance indices are set to “1”, so the weights start equally at 25%.

#### Usage
* **Application Example 1: Market Sentiment Analysis (Using Default Settings)**
Analyze using the default asset classes. By observing the relative strength between “Equities” and “Bonds”, you can assess whether the market is risk-on or risk-off.

* **Application Example 2: Sector/Theme Strength Analysis**
Configure settings for groups like “Top 4 semiconductor stocks” or “4 GAFAM stocks.” Setting the start date to the beginning of the year or earnings season allows you to instantly compare which stocks within the same sector are performing best.

* **Application Example 3: Cryptocurrency Power Map Analysis**
By setting major cryptocurrencies like “BTC, ETH, SOL, ADA,” you can analyze which currencies are attracting market capital.

**【About Legend Display】**
Due to Pine Script specification constraints, the legend on the chart will display fixed names: **“Stock 1” to “Stock 4”. **
Please note that the symbol you entered for “Symbol 1” in the settings corresponds to the “Symbol 1” line on the chart.

#### Settings
* **Symbol 1 to Symbol 4:** Set the four symbols you wish to analyze.
* **Timeframe for Calculation:** Select the timeframe the indicator references when calculating weights.
* **Start Date for Weight Calculation:** This serves as the base date for comparing performance.

#### Disclaimer
This script is solely a tool to assist with market analysis and does not recommend buying or selling any specific financial instruments. Please make all final investment decisions at your own discretion.


-------------------------------------------------------------------------------------------------------------------

**Performance-based Asset Weighting(MTF・シンボル自由設定)**

#### 概要
このインジケーターは、**ユーザーが自由に設定した4つの銘柄**について、パフォーマンス(騰落率)の相対的な強さを「ウェイト(構成比率)」として可視化するツールです。

指定した過去の任意の時点を基準(全銘柄が均等な25%)として、そこからどの銘柄のパフォーマンスが他の銘柄を上回り、資金が向かっているのか、あるいは下回っているのかを直感的に把握することを目的としています。


**【デフォルト設定と活用シナリオ:年金基金のリバランス考察】**
デフォルト設定では、日本の年金積立金管理運用独立行政法人(GPIF)の基本ポートフォリオを参考に、主要4資産クラス(国内株式, 外国株式, 国内債券, 外国債券)が設定されています。市場の変動によってこの均等な比率に乖離が生じると、元の比率に戻すためのリバランス(比率が増えた資産を売り、減った資産を買う)が行われることが知られています。
このデフォルト設定で分析することで、**「今後、年金基金などによるリバランスの売り(買い)が発生する可能性があるか」を考察するための、一つの目安として利用できます。**


**【重要:利用上の注意点】**
このインジケーターが示すウェイトは、あくまで指定した開始日からのパフォーマンスのみを基に算出した**理論上の参考値**です。実際に大口投資家などが途中で大規模なリバランス(資産の売買)を行ったとしても、その取引自体はこのチャートの計算には反映されません。
そのため、実際のポートフォリオ比率とは異なる可能性があることをご理解の上、**あくまで大まかな目安としてご活用ください。**


#### 主な特徴
* **分析対象の4銘柄を自由に設定可能:** 設定画面から、比較したい4つの銘柄(株式、指数、為替、仮想通貨など)を自由に設定できます。
* **パフォーマンス基準のウェイト計算:** 単純な価格の構成比ではなく、指定した開始日からの各銘柄の騰落を「パフォーマンス指数」として算出し、その合計に占める各銘柄の割合を表示します。
* **分析開始日の自由な設定:** 「〇〇ショック後」「決算発表後」など、分析したい任意の時点をカレンダーから設定できます。
* **マルチタイムフレーム(MTF)対応:** チャートに表示している時間足とは別に、インジケーターが計算に使う時間足(1時間足、4時間足、日足など)を自由に選択できます。


#### 計算の原理
このインジケーターは、以下の3ステップでウェイトを算出しています。
1.  **基準価格の取得**
    ユーザーが設定した「ウェイト計算の開始日」における、4つの各銘柄の終値を取得し、これを分析の**基準価格**とします。
2.  **パフォーマンス指数の算出**
    現在の各銘柄の価格を、ステップ1で取得した**基準価格**で割ることで、「パフォーマンス指数」を算出します。
    `パフォーマンス指数 = 現在の価格 ÷ 基準日の価格`
    これにより、基準日のパフォーマンスを「1」とした場合、現在のパフォーマンスが何倍になっているかが数値化されます。
3.  **ウェイトの算出**
    4つの銘柄の「パフォーマンス指数」の合計値を算出します。そして、合計値に占める各銘柄のパフォーマンス指数の割合(%)を計算し、チャートに描画します。
    `ウェイト (%) = (個別のパフォーマンス指数 ÷ 4銘柄のパフォーマンス指数の合計) × 100`

このロジックにより、分析開始日には全銘柄のパフォーマンス指数が「1」となるため、ウェイトは均等に25%からスタートします。


#### 使用方法
* **応用例1:市場のセンチメント分析(デフォルト設定利用)**

    デフォルト設定の資産クラスで分析し、「株式」と「債券」の力関係を見ることで、市場がリスクオンなのかリスクオフなのかを判断する材料になります。


* **応用例2:セクター・テーマ別の強弱分析**

    設定画面で、例えば「半導体関連の主要4銘柄」や「GAFAMの4銘柄」などを設定します。開始日を年初や決算時期に設定することで、同セクター内でどの銘柄が最もパフォーマンスが良いかを一目で比較できます。


* **応用例3:仮想通貨の勢力図分析**

    「BTC, ETH, SOL, ADA」など、主要な仮想通貨を設定することで、市場の資金がどの通貨に向かっているのかを分析できます。


**【凡例の表示について】**

Pine Scriptの仕様上の制約により、チャート上の凡例は**「銘柄1」〜「銘柄4」という固定名で表示されます。**
お手数ですが、設定画面でご自身が「銘柄1」に入力したシンボルが、チャート上の「銘柄1」のラインに対応する、という形でご覧ください。


#### 設定項目
* **銘柄1〜銘柄4:** 分析したい4つのシンボルをそれぞれ設定します。
* **計算に使う時間足:** インジケーターがウェイトを計算する際に参照する時間足を選択します。
* **ウェイト計算の開始日:** パフォーマンスを比較する上での基準日となります。


#### 免責事項
このスクリプトはあくまで市場分析を補助するためのツールであり、特定の金融商品の売買を推奨するものではありません。投資の最終的な判断は、ご自身の責任において行ってください。

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.