Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
7.835%
Drawdown
8.500%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0.984
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.003
Beta
0.616
Annual Standard Deviation
0.079
Annual Variance
0.006
Information Ratio
-1.088
Tracking Error
0.049
Treynor Ratio
0.126
Total Fees
$1.00
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Consolidators - Creating custom timespan events.
    *
    *   Consolidators are tools inside of LEAN to merge data into single bars. They are 
    *   very flexible and can generate events which trigger from any timespan.
    */
    public class ConsolidatorAlgorithm : QCAlgorithm
    {
        TradeBar _spyDaily;
        
        public override void Initialize()
        {
            SetStartDate(2013, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000);
            
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);
            
            // define our daily trade bar consolidator. we can access the daily bar
            // from the DataConsolidated events
            var dailyConsolidator = new TradeBarConsolidator(TimeSpan.FromDays(1));
            
            // attach our event handler. the event handler is a function that will be called each time we produce
            // a new consolidated piece of data.
            dailyConsolidator.DataConsolidated += OnDataDaily;

            // this call adds our daily consolidator to the manager to receive updates from the engine
            SubscriptionManager.AddConsolidator("SPY", dailyConsolidator);
        }


        /// <summary>
        /// This is our event handler for our daily trade bar defined above in Initialize(). So each time the consolidator
        /// produces a new daily bar, this function will be called automatically. The 'sender' parameter will be the
        /// instance of the IDataConsolidator that invoked the event, but you'll almost never need that!
        /// </summary>
        private void OnDataDaily(object sender, TradeBar consolidated)
        {
            _spyDaily = consolidated;
            Log(consolidated.Time.ToString("o") + " >> SPY >> LONG  >> 100 >> " + Portfolio["SPY"].Quantity);
        }


        //Traditional 1 minute events here:
        public void OnData(TradeBars data) 
        {   
            if (!Portfolio.HoldStock) 
            {
                Order("SPY",  100);
            }
        }
    }
}