Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
using System.Collections.Concurrent;

namespace QuantConnect.Algorithm.CSharp
{
    public class MomentumInvest : QCAlgorithm
    {
    	public ConcurrentDictionary<Symbol, SelectionData> stateData = new ConcurrentDictionary<Symbol, SelectionData>();
    	public int momPeriod = 130;

		public class SelectionData
		{
		    // stock selection data
		    public Symbol symbol;
		    public MomentumPercent momP;
		    
		    public SelectionData(){}
		    
		    public SelectionData(Symbol _symbol)
		    {
		    	symbol = _symbol;
		    }
		    
		    public void newMomentumIndicators(Symbol _symbol, int _period)
		    {
		        momP = new MomentumPercent(_symbol, _period);
		    }
		
		    public bool Update(DateTime _time, decimal _value)
		    {
		        return momP.Update(_time, _value);;
		    }
		}

        public override void Initialize()
        {
            SetStartDate(2018, 12, 1);
            SetEndDate(2019,2,1);
            
            SetCash(100000);

			UniverseSettings.Resolution = Resolution.Daily;
	
			AddSecurity(SecurityType.Equity, "GOV", Resolution.Daily);
			
			var history = History("GOV", momPeriod, Resolution.Daily);
			SelectionData indicatorData = new SelectionData("GOV");
	    	indicatorData.newMomentumIndicators("GOV", momPeriod);
	    	
	    	foreach (TradeBar tradeBar in history)
            {
                indicatorData.Update(tradeBar.EndTime, tradeBar.Close);
            }
	    	
	    	stateData.TryAdd("GOV", indicatorData);
        }
        

        public override void OnData(Slice data)
        {
        	if(data.SymbolChangedEvents.ContainsKey("GOV"))
        	{
        		Debug(data.SymbolChangedEvents["GOV"].OldSymbol);
        		Debug(data.SymbolChangedEvents["GOV"].NewSymbol);
        	}
        	
        	if(data.Splits.ContainsKey("OPI") )
        	{
        		var spySplit = data.Splits["GOV"];
        	
		        if (spySplit.Type == SplitType.Warning)
		        {
		        	Debug("GOV will be splitted EOD");
		        }
		        
		        if (spySplit.Type == SplitType.SplitOccurred)
		        {
		        	Debug("Split type:"+ spySplit.Type+", Split factor: "+spySplit.SplitFactor+", Reference price: "+spySplit.ReferencePrice);
		        }
        	}
        	
        	// update the momentum indicators daily
        	foreach(var selectionData in stateData.Values)
        	{
        		if(data.ContainsKey(selectionData.symbol) && data[selectionData.symbol] != null)
        		{
        			selectionData.Update(data[selectionData.symbol].EndTime, data[selectionData.symbol].Close);
        			
        			Debug("Close: "+data[selectionData.symbol].Close+" Indicator: "+stateData[selectionData.symbol].momP);
        		}
        	}
        }
    }
}