Hi all, 

Just sharing how to get the RSI of the VIX.

 

import numpy as np from QuantConnect.Algorithm import * from QuantConnect import * from QuantConnect import Chart, DataNormalizationMode from QuantConnect.Orders import OrderDirection from QuantConnect.Securities import BuyingPowerModel from QuantConnect.Securities.Option import OptionPriceModels from QuantConnect.Securities.Option import OptionStrategies from QuantConnect.Data.Custom.CBOE import CBOE from System import * from System import TimeSpan from System.Drawing import Color from datetime import timedelta from lib import CustomBuyingPowerModel from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") # ---------------------------------------------------------------------- # # Bull Put Credit Spread Algorithm # # ---------------------------------------------------------------------- class OptionsAlgorithm(QCAlgorithm): # ---------------------------------------------------------------------- # Initialize QuantConnect Algorithm # ---------------------------------------------------------------------- def Initialize(self): # Base QuantConnect Parameters self.SetStartDate(2019, 1, 1) self.SetEndDate(2020, 1, 1) self.SetCash(150000) # data self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw)) self.equity = self.AddEquity("SPY", Resolution.Minute) self.equity.SetDataNormalizationMode(DataNormalizationMode.Raw) self.vix = self.AddData(CBOE, "VIX", Resolution.Daily) self.rsi = RelativeStrengthIndex(10) # Charting overlayPlot = Chart("Overlay Plot") overlayPlot.AddSeries(Series("RSI", SeriesType.Line, "", Color.Aqua)) overlayPlot.AddSeries(Series("Over Bought", SeriesType.Line, "", Color.Navy)) overlayPlot.AddSeries(Series("Over Sold", SeriesType.Line, "", Color.Navy)) overlayPlot.AddSeries(Series("Mid", SeriesType.Line, "", Color.Navy)) self.AddChart(overlayPlot) # Set warmup for RSI self.SetWarmUp(TimeSpan.FromDays(30)) # ---------------------------------------------------------------------- # Primary Data function # ---------------------------------------------------------------------- def OnData(self, slice): if self.Time.hour == 9 and self.Time.minute == 31: if self.IsWarmingUp: return self.rsi.Update(self.Time, self.vix.Close) rsiCurr = self.rsi.Current.Value self.Plot("Overlay Plot", "RSI", rsiCurr) self.Plot("Overlay Plot", "Over Bought", 80) self.Plot("Overlay Plot", "Over Sold", 20) self.Plot("Overlay Plot", "Mid", 50)using QuantConnect.Data; using QuantConnect.Data.Custom.CBOE; using QuantConnect.Data.Custom; using QuantConnect.Indicators; using System.Collections.Generic; using System; using System.Linq; using System.Drawing; using QuantConnect.Securities; using QuantConnect.Securities.Equity; using QuantConnect.Securities.Option; using QuantConnect.Data.Market; using QuantConnect.Orders; namespace QuantConnect.Algorithm.CSharp { public class VixRSI : QCAlgorithm { private Security _vix; private Equity _spx; private RelativeStrengthIndex _vixRSI; public override void Initialize() { //SetStartDate(2019, 2, 1); //SetEndDate(2020, 2, 24); SetStartDate(2017, 11, 1); SetEndDate(2018, 4, 10); SetCash(150000); //Set Strategy Cash // Add securities _vix = AddData<CBOE>("VIX"); _spx = AddEquity("SPY", Resolution.Minute); _vixRSI = new RelativeStrengthIndex(10); // Charting var stockPlot = new Chart("Trade Plot"); var mainRsi = new Series("RSI", SeriesType.Line, "", Color.Aqua); var Ob = new Series("Over Bought", SeriesType.Line, "", Color.Navy); var Os = new Series("Over Sold", SeriesType.Line, "", Color.Navy); var Om = new Series("Mid", SeriesType.Line, "", Color.Navy); stockPlot.AddSeries(mainRsi); stockPlot.AddSeries(Ob); stockPlot.AddSeries(Os); stockPlot.AddSeries(Om); AddChart(stockPlot); // Use the underlying equity as the benchmark SetBenchmark("SPY"); SetWarmUp(TimeSpan.FromDays(30)); } public override void OnData(Slice data) { // Check entry once a day if (Time.Hour == 10 && Time.Minute == 30) { if (IsWarmingUp) return; // Update RSI _vixRSI.Update(Time, _vix.Close); Plot("Trade Plot", "RSI", _vixRSI); Plot("Trade Plot", "Over Bought", 80); Plot("Trade Plot", "Over Sold", 20); Plot("Trade Plot", "Mid", 50); } } } }