/// <summary> /// Provides a convenience method for creating an option Symbol. /// </summary> /// <param name="underlying">The underlying ticker</param> /// <param name="market">The market the underlying resides in</param> /// <param name="style">The option style (American, European, ect..)</param> /// <param name="right">The option right (Put/Call)</param> /// <param name="strike">The option strike price</param> /// <param name="expiry">The option expiry date</param> /// <param name="alias">An alias to be used for the symbol cache. Required when /// adding the same security from diferent markets</param> /// <param name="mapSymbol">Specifies if symbol should be mapped using map file provider</param> /// <returns>A new Symbol object for the specified option contract</returns> public static Symbol CreateOption(string underlying, string market, OptionStyle style, OptionRight right, decimal strike, DateTime expiry, string alias = null, bool mapSymbol = true) { var underlyingSid = SecurityIdentifier.GenerateEquity(underlying, market, mapSymbol); var underlyingSymbol = new Symbol(underlyingSid, underlying); return(CreateOption(underlyingSymbol, market, style, right, strike, expiry, alias)); }
/// <summary> /// Provides a convenience method for creating an option Symbol. /// </summary> /// <param name="underlying">The underlying ticker</param> /// <param name="market">The market the underlying resides in</param> /// <param name="style">The option style (American, European, ect..)</param> /// <param name="right">The option right (Put/Call)</param> /// <param name="strike">The option strike price</param> /// <param name="expiry">The option expiry date</param> /// <param name="alias">An alias to be used for the symbol cache. Required when /// adding the same security from diferent markets</param> /// <returns>A new Symbol object for the specified option contract</returns> public static Symbol CreateOption(string underlying, string market, OptionStyle style, OptionRight right, decimal strike, DateTime expiry, string alias = null) { var sid = SecurityIdentifier.GenerateOption(expiry, underlying, market, strike, right, style); alias = alias ?? string.Format("{0}_{1}_{2}_{3}", underlying, right.ToString()[0], strike.SmartRounding(), expiry.ToString("yyyyMMdd")); return(new Symbol(sid, alias)); }
private static Symbol CreateOptionSymbol(string symbol, OptionRight right, decimal strike, DateTime expiry) { return(Symbol.CreateOption(symbol, Market.USA, OptionStyle.American, right, strike, expiry)); }
/// <summary> /// Provides a convenience method for creating an option Symbol using SecurityIdentifier. /// </summary> /// <param name="underlyingSymbol">The underlying security symbol</param> /// <param name="market">The market the underlying resides in</param> /// <param name="style">The option style (American, European, ect..)</param> /// <param name="right">The option right (Put/Call)</param> /// <param name="strike">The option strike price</param> /// <param name="expiry">The option expiry date</param> /// <param name="alias">An alias to be used for the symbol cache. Required when /// adding the same security from diferent markets</param> /// <returns>A new Symbol object for the specified option contract</returns> public static Symbol CreateOption(Symbol underlyingSymbol, string market, OptionStyle style, OptionRight right, decimal strike, DateTime expiry, string alias = null) { var sid = SecurityIdentifier.GenerateOption(expiry, underlyingSymbol.ID, market, strike, right, style); if (expiry == SecurityIdentifier.DefaultDate) { alias = alias ?? "?" + underlyingSymbol.Value.ToUpper(); } else { var sym = underlyingSymbol.Value; if (sym.Length > 5) { sym += " "; } alias = alias ?? SymbolRepresentation.GenerateOptionTickerOSI(sym, sid.OptionRight, sid.StrikePrice, sid.Date); } return(new Symbol(sid, alias, underlyingSymbol)); }
public CoveredOptionStrategy(QCAlgorithm Algo, Option Option, OptionRight Side = OptionRight.Put, int MaxTiers = 3, int PositionSizeStart = 1, int minDaysRemaining = 15) : base(Algo, Option, MaxTiers, PositionSizeStart, 0, minDaysRemaining) { _Side = Side; }
/// <summary> /// Generic generate method. This method should be used carefully as some parameters are not required and /// some parameters mean different things for different security types /// </summary> private static SecurityIdentifier Generate(DateTime date, string symbol, SecurityType securityType, string market, decimal strike = 0, OptionRight optionRight = 0, OptionStyle optionStyle = 0, SecurityIdentifier underlying = null, bool forceSymbolToUpper = true) { if ((ulong)securityType >= SecurityTypeWidth || securityType < 0) { throw new ArgumentOutOfRangeException(nameof(securityType), "securityType must be between 0 and 99"); } if ((int)optionRight > 1 || optionRight < 0) { throw new ArgumentOutOfRangeException(nameof(optionRight), "optionType must be either 0 or 1"); } // normalize input strings market = market.ToLowerInvariant(); symbol = forceSymbolToUpper ? symbol.LazyToUpper() : symbol; if (securityType == SecurityType.FutureOption) { // Futures options tickers might not match, so we need // to map the provided future Symbol to the actual future option Symbol. symbol = FuturesOptionsSymbolMappings.Map(symbol); } var marketIdentifier = QuantConnect.Market.Encode(market); if (!marketIdentifier.HasValue) { throw new ArgumentOutOfRangeException(nameof(market), "The specified market wasn't found in the markets lookup. " + $"Requested: {market}. You can add markets by calling QuantConnect.Market.AddMarket(string,ushort)" ); } var days = (ulong)date.ToOADate() * DaysOffset; var marketCode = (ulong)marketIdentifier * MarketOffset; ulong strikeScale; var strk = NormalizeStrike(strike, out strikeScale) * StrikeOffset; strikeScale *= StrikeScaleOffset; var style = (ulong)optionStyle * OptionStyleOffset; var putcall = (ulong)optionRight * PutCallOffset; var otherData = putcall + days + style + strk + strikeScale + marketCode + (ulong)securityType; var result = new SecurityIdentifier(symbol, otherData, underlying ?? Empty); // we already have these so lets set them. Massive performance improvement! switch (securityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Future: result._date = date; break; case SecurityType.Option: case SecurityType.IndexOption: case SecurityType.FutureOption: result._date = date; result._strikePrice = strike; result._optionRight = optionRight; result._optionStyle = optionStyle; break; } return(result); }
public FactoryRight(OptionRight right) { this.right = right; }
/// <summary> /// Converts a CoinAPI symbol id to a Lean symbol instance /// </summary> /// <param name="brokerageSymbol">The CoinAPI symbol id</param> /// <param name="securityType">The security type</param> /// <param name="market">The market</param> /// <param name="expirationDate">Expiration date of the security (if applicable)</param> /// <param name="strike">The strike of the security (if applicable)</param> /// <param name="optionRight">The option right of the security (if applicable)</param> /// <returns>A new Lean Symbol instance</returns> public Symbol GetLeanSymbol(string brokerageSymbol, SecurityType securityType, string market, DateTime expirationDate = new DateTime(), decimal strike = 0, OptionRight optionRight = OptionRight.Call) { var parts = brokerageSymbol.Split('_'); if (parts.Length != 4 || parts[1] != "SPOT") { throw new Exception($"CoinApiSymbolMapper.GetLeanSymbol(): Unsupported SymbolId: {brokerageSymbol}"); } string symbolMarket; if (!MapExchangeIdsToMarkets.TryGetValue(parts[0], out symbolMarket)) { throw new Exception($"CoinApiSymbolMapper.GetLeanSymbol(): Unsupported ExchangeId: {parts[0]}"); } var baseCurrency = ConvertCoinApiCurrencyToLeanCurrency(parts[2], symbolMarket); var quoteCurrency = ConvertCoinApiCurrencyToLeanCurrency(parts[3], symbolMarket); var ticker = baseCurrency + quoteCurrency; return(Symbol.Create(ticker, SecurityType.Crypto, symbolMarket)); }
public Symbol this[OptionRight right, decimal strike, DateTime expiration] => Symbol.CreateOption(Underlying, Market.USA, OptionStyle.American, right, strike, expiration);
public Symbol this[OptionRight right, decimal strike, int weeks = 0] => Symbol.CreateOption(Underlying, Market.USA, OptionStyle.American, right, strike, ReferenceDate.AddDays(7 * weeks));
public Symbol this[Symbol underlying, OptionRight right, decimal strike, DateTime expiration] => Symbol.CreateOption(underlying, underlying.ID.Market, OptionStyle.American, right, strike, expiration);
/// <summary> /// Converts an Oanda symbol to a Lean symbol instance /// </summary> /// <param name="brokerageSymbol">The Oanda symbol</param> /// <param name="securityType">The security type</param> /// <param name="market">The market</param> /// <param name="expirationDate">Expiration date of the security(if applicable)</param> /// <param name="strike">The strike of the security (if applicable)</param> /// <param name="optionRight">The option right of the security (if applicable)</param> /// <returns>A new Lean Symbol instance</returns> public Symbol GetLeanSymbol(string brokerageSymbol, SecurityType securityType, string market, DateTime expirationDate = default(DateTime), decimal strike = 0, OptionRight optionRight = 0) { if (string.IsNullOrWhiteSpace(brokerageSymbol)) { throw new ArgumentException("Invalid Oanda symbol: " + brokerageSymbol); } if (!IsKnownBrokerageSymbol(brokerageSymbol)) { throw new ArgumentException("Unknown Oanda symbol: " + brokerageSymbol); } if (securityType != SecurityType.Forex && securityType != SecurityType.Cfd) { throw new ArgumentException("Invalid security type: " + securityType); } if (market != Market.Oanda) { throw new ArgumentException("Invalid market: " + market); } return(Symbol.Create(ConvertOandaSymbolToLeanSymbol(brokerageSymbol), GetBrokerageSecurityType(brokerageSymbol), Market.Oanda)); }
public void SymbolHashForOptionsBackwardsCompatibilityFractionalNumber(OptionStyle style, OptionRight right, string expected) { var equity = Symbol.Create("AAPL", SecurityType.Equity, Market.USA); var option = Symbol.CreateOption( equity, Market.USA, style, right, 0.01m, // strike decimal precision is limited to 4 decimal places only new DateTime(2020, 5, 21)); Assert.AreEqual(expected, option.ID.ToString()); Assert.AreEqual(0.01m, option.ID.StrikePrice); }
/// <summary> /// Converts IQFeed ticker to a Lean symbol instance /// </summary> /// <param name="ticker">IQFeed ticker</param> /// <param name="securityType">The security type</param> /// <param name="market">The market</param> /// <param name="expirationDate">Expiration date of the security(if applicable)</param> /// <param name="strike">The strike of the security (if applicable)</param> /// <param name="optionRight">The option right of the security (if applicable)</param> /// <returns>A new Lean Symbol instance</returns> public Symbol GetLeanSymbol(string ticker, SecurityType securityType, string market, DateTime expirationDate = default(DateTime), decimal strike = 0, OptionRight optionRight = 0) { return(_tickers.ContainsKey(ticker) ? _tickers[ticker] : Symbol.Empty); }
public static Symbol WithRight(this Symbol symbol, OptionRight right) { return(Symbol.CreateOption(symbol.Underlying, symbol.ID.Market, symbol.ID.OptionStyle, right, symbol.ID.StrikePrice, symbol.ID.Date)); }
public void SymbolHashForOptionsBackwardsCompatibilityWholeNumber(OptionStyle style, OptionRight right, string expected) { var equity = Symbol.Create("AAPL", SecurityType.Equity, Market.USA); var option = Symbol.CreateOption( equity, Market.USA, style, right, 100m, new DateTime(2020, 5, 21)); Assert.AreEqual(expected, option.ID.ToString()); Assert.AreEqual(100m, option.ID.StrikePrice); }
/// <summary> /// Converts an Bitfinex symbol to a Lean symbol instance /// </summary> /// <param name="brokerageSymbol">The Bitfinex symbol</param> /// <param name="securityType">The security type</param> /// <param name="market">The market</param> /// <param name="expirationDate">Expiration date of the security(if applicable)</param> /// <param name="strike">The strike of the security (if applicable)</param> /// <param name="optionRight">The option right of the security (if applicable)</param> /// <returns>A new Lean Symbol instance</returns> public Symbol GetLeanSymbol(string brokerageSymbol, SecurityType securityType, string market, DateTime expirationDate = default(DateTime), decimal strike = 0, OptionRight optionRight = 0) { if (string.IsNullOrWhiteSpace(brokerageSymbol)) { throw new ArgumentException($"Invalid Bitfinex symbol: {brokerageSymbol}"); } if (!IsKnownBrokerageSymbol(brokerageSymbol)) { throw new ArgumentException($"Unknown Bitfinex symbol: {brokerageSymbol}"); } if (securityType != SecurityType.Crypto) { throw new ArgumentException($"Invalid security type: {securityType}"); } if (market != Market.Bitfinex) { throw new ArgumentException($"Invalid market: {market}"); } return(Symbol.Create(ConvertBitfinexSymbolToLeanSymbol(brokerageSymbol), GetBrokerageSecurityType(brokerageSymbol), Market.Bitfinex)); }