Overall Statistics
namespace QuantConnect 
{
    /*
    *   QuantConnect University: How can I model a basket of securities
    *   
    *   Combining securities into a single symbol.
    */
    public class BasketAlgorithm : QCAlgorithm
    {
        TradeBar _basket = new TradeBar();
        public static List<string> _symbols = new List<string>() { "SPY", "AAPL", "IBM" };
        
        public override void Initialize() 
        {
            SetStartDate(2013, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            SetCash(25000); 
            foreach (var symbol in _symbols) 
            {
                AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
            }
        }
        
        //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
        public override void OnData(Slice data)
        {
            if (data.Bars.Count != _symbols.Count) return;
            
            //Build the basket value:
            _basket.Open = (from bar in data.Bars.Values select bar.Open).Sum();
            _basket.High = (from bar in data.Bars.Values select bar.High).Sum();
            _basket.Low = (from bar in data.Bars.Values select bar.High).Sum();
            _basket.Close = (from bar in data.Bars.Values select bar.Close).Sum();
            
            //Basket value here:
            if (!Portfolio.HoldStock)
            {
                BasketBuy(0.5m);
            }
        }
        
        public void BasketBuy(decimal fraction) 
        {
            var symbolFraction = fraction / _symbols.Count;
            foreach(var symbol in _symbols)
            {
                SetHoldings(symbol, symbolFraction);
            }
        }
    }
}