Overall Statistics
Total Trades
77
Average Win
27.27%
Average Loss
-3.58%
Compounding Annual Return
24.466%
Drawdown
52.200%
Expectancy
1.948
Net Profit
1198.512%
Sharpe Ratio
0.743
Probabilistic Sharpe Ratio
9.491%
Loss Rate
66%
Win Rate
34%
Profit-Loss Ratio
7.62
Alpha
0.052
Beta
0.449
Annual Standard Deviation
0.286
Annual Variance
0.082
Information Ratio
-0.458
Tracking Error
0.316
Treynor Ratio
0.473
Total Fees
$404.50
Estimated Strategy Capacity
$2100000.00
Lowest Capacity Asset
UPRO UDQRQQYTO12D
namespace QuantConnect.Algorithm.CSharp
{
    public class LeveragedSMA : QCAlgorithm
    {
        public const string BenchmarkSymbol = "SPY";
        public const string InSymbol = "UPRO";
        public const string OutSymbol = "BIL";
        
        public const int BenchmarkMAPeriod = 200;
        public const bool TradeOncePerDay = true;

        private DateTime PreviousTrade;
        private SimpleMovingAverage BenchmarkMA;

        public override void Initialize()
        {
            SetStartDate(2010, 02, 10);
            SetEndDate(DateTime.Now.AddDays(-1));
            SetCash(10000);
            SetBenchmark(InSymbol);
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage);

			AddEquity(BenchmarkSymbol, Resolution.Minute);
            AddEquity(InSymbol, Resolution.Minute);
            AddEquity(OutSymbol, Resolution.Minute);

            this.BenchmarkMA = this.SMA(BenchmarkSymbol, BenchmarkMAPeriod, Resolution.Daily);
        }

        public override void OnData(Slice data)
        {
            if (!this.BenchmarkMA.IsReady)
            {
                return;
            }

            			// Trade only once per day?
			if (TradeOncePerDay)
			{
    	        if (this.PreviousTrade.Date == this.Time.Date)
        	    {
            	    return;
	            }
	            
	            if (this.Time.Hour != 16)
	            {
	            	return;
	            }
			}

            try
            {
                var inMarketSignal = this.Securities[BenchmarkSymbol].Price > this.BenchmarkMA.Current.Price;

                // Enter the market if we have a buy signal, otherwise GTFO
                if (inMarketSignal)
                {
                    if (!this.Portfolio[InSymbol].Invested)
                    {
                        this.SetHoldings(InSymbol, 1, true);
                        this.Log($"BUY >> {InSymbol} @ {this.Securities[InSymbol].Price}");
                    }
                }
                else
                {
                    if (this.Portfolio[InSymbol].Invested)
                    {
                        this.SetHoldings(OutSymbol, 1, true);
                        this.Log($"SELL >> {InSymbol} @ {this.Securities[InSymbol].Price}");
                    }
                }
            }
            finally
            {
                this.PreviousTrade = this.Time;
            }
        }
    }
}