Supported Indicators
Vega
Introduction
Option Vega indicator that calculate the Vega of an option
To view the implementation of this indicator, see the LEAN GitHub repository.
Using V Indicator
To create an automatic indicator for Vega, call the Vv helper method from the QCAlgorithm class. The Vv method creates a Vega object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.
public class VegaAlgorithm : QCAlgorithm
{
private Symbol _symbol, _option, _mirrorOption;
private Vega _v;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
AddOptionContract(_mirrorOption, Resolution.Daily);
_v = V(_option, _mirrorOption);
}
public override void OnData(Slice data)
{
if (_v.IsReady)
{
// The current value of _v is represented by itself (_v)
// or _v.Current.Value
Plot("Vega", "v", _v);
}
}
} class VegaAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._v = self.v(self._option, self._mirror_option)
def on_data(self, slice: Slice) -> None:
if self._v.is_ready:
# The current value of self._v is represented by self._v.current.value
self.plot("Vega", "v", self._v.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
You can manually create a Vega indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.
Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Updateupdate method. The indicator will only be ready after you prime it with enough data.
public class VegaAlgorithm : QCAlgorithm
{
private Symbol _symbol, _option, _mirrorOption;
private Vega _vega;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
var interestRateModel = new InterestRateProvider();
var dividendYieldModel = new DividendYieldProvider(_symbol);
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
AddOptionContract(_mirrorOption, Resolution.Daily);
_vega = new Vega(_option, interestRateModel, dividendYieldModel, _mirrorOption);
}
public override void OnData(Slice data)
{
if (data.Bars.TryGetValue(_symbol, out var bar))
_vega.Update(new IndicatorDataPoint(_symbol, bar.EndTime, bar.Close));
if (data.QuoteBars.TryGetValue(_option, out var quoteBar))
_vega.Update(new IndicatorDataPoint(_option, quoteBar.EndTime, quoteBar.Close));
if (data.QuoteBars.TryGetValue(_mirrorOption, out quoteBar))
_vega.Update(new IndicatorDataPoint(_mirrorOption, quoteBar.EndTime, quoteBar.Close));
if (_vega.IsReady)
{
// The current value of _vega is represented by itself (_vega)
// or _vega.Current.Value
Plot("Vega", "vega", _vega);
}
}
} class VegaAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
interest_rate_model = InterestRateProvider()
dividend_yield_model = DividendYieldProvider(self._symbol)
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._vega = Vega(self._option, interest_rate_model, dividend_yield_model, self._mirror_option)
def on_data(self, slice: Slice) -> None:
bar = slice.bars.get(self._symbol)
if bar:
self._vega.update(IndicatorDataPoint(self._symbol, bar.end_time, bar.close))
bar = slice.quote_bars.get(self._option)
if bar:
self._vega.update(IndicatorDataPoint(self._option, bar.end_time, bar.close))
bar = slice.quote_bars.get(self._mirror_option)
if bar:
self._vega.update(IndicatorDataPoint(self._mirror_option, bar.end_time, bar.close))
if self._vega.is_ready:
# The current value of self._vega is represented by self._vega.current.value
self.plot("Vega", "vega", self._vega.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the Vega indicator, call the IndicatorHistoryself.indicator_history method. This method resets your indicator, makes a history request, and updates the indicator with the historical data. Just like with regular history requests, the IndicatorHistoryindicator_history method supports time periods based on a trailing number of bars, a trailing period of time, or a defined period of time. If you don't provide a resolution argument, it defaults to match the resolution of the security subscription.
public class VegaAlgorithm : QCAlgorithm
{
private Symbol _symbol, _option, _mirrorOption;
private Vega _v;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 9, 20);
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_option = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920C00564000");
_mirrorOption = SymbolRepresentation.ParseOptionTickerOSI("SPY 240920P00564000");
AddOptionContract(_option, Resolution.Daily);
AddOptionContract(_mirrorOption, Resolution.Daily);
_v = V(_option, _mirrorOption);
var indicatorHistory = IndicatorHistory(_v, new[] { _symbol, _option, _mirrorOption }, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_v, new[] { _symbol, _option, _mirrorOption }, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_v, new[] { _symbol, _option, _mirrorOption }, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
}
} class VegaAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 9, 20)
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920C00564000");
self._mirror_option = SymbolRepresentation.parse_option_ticker_osi("SPY 240920P00564000");
self.add_option_contract(self._option, Resolution.DAILY);
self.add_option_contract(self._mirror_option, Resolution.DAILY);
self._v = self.v(self._option, self._mirror_option)
indicator_history = self.indicator_history(self._v, [self._symbol, self._option, self._mirror_option], 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._v, [self._symbol, self._option, self._mirror_option], timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._v, [self._symbol, self._option, self._mirror_option], datetime(2024, 7, 1), datetime(2024, 7, 5), Resolution.MINUTE)