Overall Statistics
Total Trades
49
Average Win
50.45%
Average Loss
-5.38%
Compounding Annual Return
24.484%
Drawdown
51.100%
Expectancy
2.029
Net Profit
1200.661%
Sharpe Ratio
0.741
Probabilistic Sharpe Ratio
9.367%
Loss Rate
71%
Win Rate
29%
Profit-Loss Ratio
9.38
Alpha
0.051
Beta
0.454
Annual Standard Deviation
0.287
Annual Variance
0.083
Information Ratio
-0.458
Tracking Error
0.315
Treynor Ratio
0.469
Total Fees
$361.64
Estimated Strategy Capacity
$1700000.00
Lowest Capacity Asset
UPRO UDQRQQYTO12D
namespace QuantConnect.Algorithm.CSharp
{
    public class LeveragedSMA : QCAlgorithm
    {
        public const string LeveragedSymbol = "UPRO";
        public const string BenchmarkSymbol = "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(LeveragedSymbol);
            SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage);
            
            AddEquity(LeveragedSymbol, Resolution.Minute);
            AddEquity(BenchmarkSymbol, 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[LeveragedSymbol].Invested)
                    {
                        this.SetHoldings(LeveragedSymbol, 1);
                        this.Log($"BUY >> {LeveragedSymbol} @ {this.Securities[LeveragedSymbol].Price}");
                    }
                }
                else
                {
                    if (this.Portfolio[LeveragedSymbol].Invested)
                    {
                        this.Liquidate();
                        this.Log($"SELL >> {LeveragedSymbol} @ {this.Securities[LeveragedSymbol].Price}");
                    }
                }
            }
            finally
            {
                this.PreviousTrade = this.Time;
            }
        }
    }
}