Overall Statistics
Total Trades
5
Average Win
32.53%
Average Loss
-7.21%
Compounding Annual Return
8.133%
Drawdown
24.800%
Expectancy
3.408
Net Profit
143.42%
Sharpe Ratio
0.712
Loss Rate
20%
Win Rate
80%
Profit-Loss Ratio
4.51
Alpha
0.048
Beta
0.391
Annual Standard Deviation
0.12
Annual Variance
0.014
Information Ratio
-0.067
Tracking Error
0.151
Treynor Ratio
0.219
Total Fees
$15.09
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Futures Example
    *
    *   QuantConnect allows importing generic data sources! This example demonstrates importing a futures
    *   data from the popular open data source Quandl.
    *
    *   QuantConnect has a special deal with Quandl giving you access to Stevens Continuous Futurs (SCF) for free. 
    *   If you'd like to download SCF for local backtesting, you can download it through Quandl.com.
    */
    public class QCUQuandlFutures : QCAlgorithm
    {
        string SPY = "SPY";
        string ACWI = "ACWI";
        string Tbill = "BIL";
        string Bonds = "AGG";

        Momentum _momSPY;
        Momentum _momACWI;
        Momentum _momTbill;
        DateTime sampledToday = DateTime.Now;
        
        

        
        public override void Initialize()
        {
            SetStartDate(2004, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000);
            
            AddSecurity(SecurityType.Equity, SPY, Resolution.Minute);
            Securities[SPY].SetDataNormalizationMode(DataNormalizationMode.TotalReturn);            
            AddSecurity(SecurityType.Equity, ACWI, Resolution.Minute);
            Securities[ACWI].SetDataNormalizationMode(DataNormalizationMode.TotalReturn);            
            AddSecurity(SecurityType.Equity, Tbill, Resolution.Minute);
            Securities[Tbill].SetDataNormalizationMode(DataNormalizationMode.TotalReturn);            
            AddSecurity(SecurityType.Equity, Bonds, Resolution.Minute);
            Securities[Bonds].SetDataNormalizationMode(DataNormalizationMode.TotalReturn);            
            
            _momSPY = MOM(SPY, 252, Resolution.Daily);
            _momACWI = MOM(ACWI, 252, Resolution.Daily);
            _momTbill = MOM(Tbill, 252, Resolution.Daily);
        }
           
        
     
        //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
        public void OnData(TradeBars data) 
        {
            if (!_momSPY.IsReady) return;
            
            //One data point per m:
            if (sampledToday.Month == data.Time.Month) return;
            
            //Only take one data point per day (opening price)
            sampledToday = data.Time;
            decimal holdingPercent = .5m;
            
            string etf;
            decimal _momStrong;
            
            if (_momSPY >= _momACWI)
            {
                etf = SPY;
                _momStrong = _momSPY;
            } else
            {
                etf = ACWI;
                _momStrong = _momACWI;
            }
           
            if (_momStrong > _momTbill)
            {
                if(Portfolio[etf].Quantity > 0) return;
                
                Liquidate();
                SetHoldings(etf, holdingPercent);
                Log("Set Holdings to " + Portfolio[etf].Quantity + "of " + etf);
            } else
            {
                if(Portfolio[Bonds].Quantity > 0) return;
                
                Liquidate();
                SetHoldings(Bonds, holdingPercent);
                Log("Set Holdings to " + Portfolio[Bonds].Quantity + "of " + Bonds);
            }
        }
    }
}