Overall Statistics
Total Trades
1523
Average Win
0.05%
Average Loss
-0.05%
Compounding Annual Return
8.878%
Drawdown
41.100%
Expectancy
0.809
Net Profit
64.312%
Sharpe Ratio
0.436
Probabilistic Sharpe Ratio
4.830%
Loss Rate
16%
Win Rate
84%
Profit-Loss Ratio
1.14
Alpha
-0.015
Beta
0.991
Annual Standard Deviation
0.178
Annual Variance
0.032
Information Ratio
-0.223
Tracking Error
0.072
Treynor Ratio
0.078
Total Fees
$1523.00
Estimated Strategy Capacity
$2100000.00
Lowest Capacity Asset
XTL UTMUH2HW4DB9
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QuantConnect.Data.Custom.AlphaStreams;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion
namespace QuantConnect.Algorithm.CSharp
{
    public class WellDressedVioletChinchilla : QCAlgorithm
    {
        private List<Symbol> _symbols = new();
        private bool _rebalance = false;
        private Dictionary<DateTime, decimal> _portfolioValues = new();

        public override void Initialize()
        {
            SetStartDate(2017, 1, 1);
            SetEndDate(2022, 11, 1);
            SetCash(100000);

            // Sector ETFs from https://www.cnbc.com/sector-etfs/
            var tickers = new[]
            {
                "XLE", // Energy Select Sector SPDR Fund
                "XLF", // Financial Select Sector SPDR Fund
                "XLU", // Utilities Select Sector SPDR Fund
                "XLI", // Industrial Select Sector SPDR Fund
                "GDX", // VanEck Gold Miners ETF
                "XLK", // Technology Select Sector SPDR Fund
                "XLV", // Health Care Select Sector SPDR Fund
                "XLY", // Consumer Discretionary Select Sector SPDR Fund
                "XLP", // Consumer Staples Select Sector SPDR Fund
                "XLB", // Materials Select Sector SPDR Fund
                "XOP", // Spdr S&P Oil & Gas Exploration & Production Etf
                "IYR", // iShares U.S. Real Estate ETF
                "XHB", // Spdr S&P Homebuilders Etf
                "ITB", // iShares U.S. Home Construction ETF
                "VNQ", // Vanguard Real Estate Index Fund ETF Shares
                "GDXJ",// VanEck Junior Gold Miners ETF
                "IYE", // iShares U.S. Energy ETF
                "OIH", // VanEck Oil Services ETF
                "XME", // SPDR S&P Metals & Mining ETF
                "XRT", // Spdr S&P Retail Etf
                "SMH", // VanEck Semiconductor ETF
                "IBB", // iShares Biotechnology ETF
                "KBE", // SPDR S&P Bank ETF
                "KRE", // SPDR S&P Regional Banking ETF
                "XTL"  // SPDR S&P Telecom ETF
            };
            foreach (var ticker in tickers)
            {
                _symbols.Add(AddEquity(ticker, Resolution.Daily).Symbol);
            }

            // Schedule the rebalance
            Schedule.On(DateRules.MonthStart(GetParameter("rebalance-day", 0)),
                TimeRules.Midnight,
                () =>
                {
                    _rebalance = true;
                });
        }

        public override void OnData(Slice data)
        {
            // Record net portfolio value
            _portfolioValues[Time] = Portfolio.TotalPortfolioValue;

            // Rebalance?
            if (!_rebalance)
            {
                return;
            }
            _rebalance = false;

            var weight = 1.0m / _symbols.Count;
            SetHoldings(_symbols.Select(symbol => new PortfolioTarget(symbol, weight)).ToList());
        }

        public override void OnEndOfAlgorithm()
        {
            // Save daily portfolio values to ObjectStore
            ObjectStore.SaveJson<Dictionary<DateTime, decimal>>($"{ProjectId}/portfolioValues", _portfolioValues);
        }
    }
}