Overall Statistics
Total Trades
71
Average Win
19.71%
Average Loss
-5.66%
Compounding Annual Return
26.502%
Drawdown
61.000%
Expectancy
1.435
Net Profit
1470.310%
Sharpe Ratio
0.771
Probabilistic Sharpe Ratio
10.859%
Loss Rate
46%
Win Rate
54%
Profit-Loss Ratio
3.49
Alpha
0.023
Beta
0.584
Annual Standard Deviation
0.3
Annual Variance
0.09
Information Ratio
-0.516
Tracking Error
0.244
Treynor Ratio
0.396
Total Fees
$407.69
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 = "SPY";
        
        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;
            }
        }
    }
}