private void HandleVixData(Slice slice) { if (!slice.ContainsKey(_cboeVix)) { return; } if (_vix != null && (_vix as TradeBar).Time.Day == slice.Time.Day) { return; } _vix = slice.Get <CBOE>(_cboeVix); var vixHistories = History <CBOE>(_cboeVix, 35, Resolution.Daily) .Cast <TradeBar>(); if (vixHistories.Any()) { var momentum = vixHistories .OrderByDescending(x => x.Time) .Take(5) .Select(x => x.Price) .Average() / vixHistories .OrderBy(x => x.Time) .Take(5) .Select(x => x.Price) .Average(); _tooVolatile = momentum > 2; Plot("VIX-momentum", "momentum", momentum); } Plot("VIX", "price", _vix.Price); }
/// <summary> /// Reads the data, which in this case is fake incremental data /// </summary> /// <param name="config">Subscription configuration</param> /// <param name="line">Line of data</param> /// <param name="date">Date of the request</param> /// <param name="isLiveMode">Is live mode</param> /// <returns>Incremental BaseData instance</returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { var vix = new CBOE(); _step += 0.10m; var open = _start + _step; var close = _start + _step + 0.02m; var high = close; var low = open; return(new IncrementallyGeneratedCustomData { Open = open, High = high, Low = low, Close = close, Time = date, Symbol = new Symbol( SecurityIdentifier.GenerateBase(typeof(IncrementallyGeneratedCustomData), "VIX", Market.USA, false), "VIX"), Period = vix.Period, DataType = vix.DataType }); }