Overall Statistics
Total Trades
272
Average Win
8.93%
Average Loss
-3.18%
Compounding Annual Return
66.060%
Drawdown
34.100%
Expectancy
1.169
Net Profit
1166.270%
Sharpe Ratio
1.225
Loss Rate
43%
Win Rate
57%
Profit-Loss Ratio
2.80
Alpha
0.493
Beta
0.049
Annual Standard Deviation
0.406
Annual Variance
0.165
Information Ratio
0.957
Tracking Error
0.42
Treynor Ratio
10.213
Total Fees
$3428.79
//Copyright Warren Harding 2016, granted to the public domain.
//Use entirely at your own risk.
//Custom algorithm development: warrencharding@yahoo.com.
//Do not remove this copyright notice.
namespace QuantConnect 
{   
    public class TQQQSQQQ : QCAlgorithm
    {
    	StandardDeviation std;
    	int indicatorPeriod=390;
    	Resolution resolution=Resolution.Minute;
        public override void Initialize() 
        {
        	// backtest parameters
            SetStartDate(2012, 8, 11);         
            SetEndDate(2017, 8, 11);
            
            // cash allocation
            SetCash(25000);
            
            AddEquity("TQQQ", resolution,Market.USA,true,1m,true);
            AddEquity("SQQQ", resolution,Market.USA,true,1m,true);
            
            std = STD("TQQQ", indicatorPeriod, resolution);
        	var history = History("TQQQ", indicatorPeriod, resolution);
            foreach (var tradeBar in history)
            {
            	std.Update(tradeBar.EndTime, tradeBar.Close);
            }
        }

        public override void OnData(Slice data) 
        {
        	if (std<1.2m)
        	{
    			SetHoldings("SQQQ", 0);
    			SetHoldings("TQQQ", 1.0);
        	}
        	else
        	{
    			SetHoldings("TQQQ", 0);
    			SetHoldings("SQQQ", 1.0);
        	}
        }
    }
}