OPEN-SOURCE SCRIPT
Vigilant Asset Allocation G4 Backtesting Engine

This script was based off of an idea that CubanEmissary had so the description and some of the code that CubanEmissary built on TradingView was used.
Vigilant Asset Allocation G4 (VAA G4) is a dual-momentum based investment strategy that aggressively monitors the market and reallocates portfolio funds based on the relative momentums of user-defined risk assets and safety assets. It was created by Wouter Keller and JW Keuning, based on their paper "Breadth Momentum and Vigilant Asset Allocation." In contrast to traditional dual momentum strategies, VAA G4 monitors the market itself through the two asset types. When all risk assets have positive momentum, the portfolio is allocated entirely into the risk asset with the strongest momentum At any other time, the portfolio is allocated entirely into the safety asset with the strongest momentum. The combination of breadth momentum with a very defensive reallocation trigger results in a strategy which captures alpha consistently.
The Strategy Rules:
1. Calculate each asset's momentum score on each monthly close:
momentumScore = (12*(currentMonthlyClose/lastMonthlyClose))+(4*(currentMonthlyClose/thirdLastMonthlyClose))+(2*(currentMonthlyClose/sixthLastMonthlyClose))+(currentMonthlyClose/twelvethLastMonthlyClose)-19
2. If all risk asset momentums are positive, allocate entire portfolio to the risk asset with the strongest momentum.
3. If any risk asset's momentum is negative, allocate entire portfolio to the safety asset with the strongest momentum.
4. Reevaluate at the end of each month.
Caveats:
1. It seems like TradingView only has limited price data for these tickers that are listed in the strategy. So it is best to start the strategy when they all have ample data (~ June 2nd, 2008)
2. This backtesting engine is basic and doesn't account for slippage and trading fees. So I implemented a basic "trading fee" input that will subtract a trading fee whenever the strategy makes a trade at the end of the month.
3. It is assumed in this engine that the trades will be made the exact second a new monthly bar opens up.
4. MUST USE ON MONTHLY CHART. It is hard-coded to work on monthly chart, if you open it on a daily chart , the Sharpe, Sortino, & CAGR calculations might not be right as well as the momentum score
Vigilant Asset Allocation G4 (VAA G4) is a dual-momentum based investment strategy that aggressively monitors the market and reallocates portfolio funds based on the relative momentums of user-defined risk assets and safety assets. It was created by Wouter Keller and JW Keuning, based on their paper "Breadth Momentum and Vigilant Asset Allocation." In contrast to traditional dual momentum strategies, VAA G4 monitors the market itself through the two asset types. When all risk assets have positive momentum, the portfolio is allocated entirely into the risk asset with the strongest momentum At any other time, the portfolio is allocated entirely into the safety asset with the strongest momentum. The combination of breadth momentum with a very defensive reallocation trigger results in a strategy which captures alpha consistently.
The Strategy Rules:
1. Calculate each asset's momentum score on each monthly close:
momentumScore = (12*(currentMonthlyClose/lastMonthlyClose))+(4*(currentMonthlyClose/thirdLastMonthlyClose))+(2*(currentMonthlyClose/sixthLastMonthlyClose))+(currentMonthlyClose/twelvethLastMonthlyClose)-19
2. If all risk asset momentums are positive, allocate entire portfolio to the risk asset with the strongest momentum.
3. If any risk asset's momentum is negative, allocate entire portfolio to the safety asset with the strongest momentum.
4. Reevaluate at the end of each month.
Caveats:
1. It seems like TradingView only has limited price data for these tickers that are listed in the strategy. So it is best to start the strategy when they all have ample data (~ June 2nd, 2008)
2. This backtesting engine is basic and doesn't account for slippage and trading fees. So I implemented a basic "trading fee" input that will subtract a trading fee whenever the strategy makes a trade at the end of the month.
3. It is assumed in this engine that the trades will be made the exact second a new monthly bar opens up.
4. MUST USE ON MONTHLY CHART. It is hard-coded to work on monthly chart, if you open it on a daily chart , the Sharpe, Sortino, & CAGR calculations might not be right as well as the momentum score
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.