/// <summary> /// Gets a new buying power model for the security, returning the default model with the security's configured leverage. /// For cash accounts, leverage = 1 is used. /// </summary> /// <param name="security">The security to get a buying power model for</param> /// <returns>The buying power model for this brokerage/security</returns> public virtual IBuyingPowerModel GetBuyingPowerModel(Security security) { var leverage = GetLeverage(security); IBuyingPowerModel model; switch (security.Type) { case SecurityType.Crypto: model = new CashBuyingPowerModel(); break; case SecurityType.Forex: case SecurityType.Cfd: model = new SecurityMarginModel(leverage, RequiredFreeBuyingPowerPercent); break; case SecurityType.Option: model = new OptionMarginModel(RequiredFreeBuyingPowerPercent); break; case SecurityType.FutureOption: model = new FuturesOptionsMarginModel(RequiredFreeBuyingPowerPercent, (Option)security); break; case SecurityType.Future: model = new FutureMarginModel(RequiredFreeBuyingPowerPercent, security); break; default: model = new SecurityMarginModel(leverage, RequiredFreeBuyingPowerPercent); break; } return(model); }
/// <summary> /// Constructor for the future option security /// </summary> /// <param name="symbol">Symbol of the future option</param> /// <param name="exchangeHours">Exchange hours of the future option</param> /// <param name="quoteCurrency">Quoted currency of the future option</param> /// <param name="symbolProperties">Symbol properties of the future option</param> /// <param name="currencyConverter">Currency converter</param> /// <param name="registeredTypes">Provides all data types registered to the algorithm</param> /// <param name="securityCache">Cache of security objects</param> /// <param name="underlying">Future underlying security</param> public FutureOption(Symbol symbol, SecurityExchangeHours exchangeHours, Cash quoteCurrency, OptionSymbolProperties symbolProperties, ICurrencyConverter currencyConverter, IRegisteredSecurityDataTypesProvider registeredTypes, SecurityCache securityCache, Security underlying) : base(symbol, quoteCurrency, symbolProperties, new OptionExchange(exchangeHours), securityCache, new OptionPortfolioModel(), new ImmediateFillModel(), new InteractiveBrokersFeeModel(), new ConstantSlippageModel(0), new ImmediateSettlementModel(), Securities.VolatilityModel.Null, null, new OptionDataFilter(), new SecurityPriceVariationModel(), currencyConverter, registeredTypes, underlying ) { BuyingPowerModel = new FuturesOptionsMarginModel(0, this); }
public void MarginRequirementEs(decimal strike, double expected, OptionRight optionRight, PositionSide positionSide, decimal underlyingRequirement) { var tz = TimeZones.NewYork; var expDate = new DateTime(2021, 3, 19); // For this symbol we dont have any history, but only one date and margins line var ticker = QuantConnect.Securities.Futures.Indices.SP500EMini; var future = Symbol.CreateFuture(ticker, Market.Globex, expDate); var symbol = Symbol.CreateOption(future, Market.Globex, OptionStyle.American, optionRight, strike, new DateTime(2021, 3, 19)); var futureSecurity = new Future( SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), future, Resolution.Minute, tz, tz, true, false, false), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); var optionSecurity = new QuantConnect.Securities.FutureOption.FutureOption(symbol, SecurityExchangeHours.AlwaysOpen(tz), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null, new SecurityCache(), futureSecurity ); optionSecurity.Underlying.SetMarketPrice(new Tick { Value = 4172, Time = new DateTime(2001, 01, 07) }); var marginRequirement = FuturesOptionsMarginModel.GetMarginRequirement(optionSecurity, underlyingRequirement, positionSide); Log.Debug($"Side {positionSide}. Right {optionRight}. Strike {strike}. Margin: {marginRequirement}"); Assert.AreEqual(expected, marginRequirement, (double)underlyingRequirement * 0.30d); }
public void MarginWithNoFutureOptionHoldings() { const decimal price = 1.2345m; var time = new DateTime(2020, 10, 14); var expDate = new DateTime(2021, 3, 19); var tz = TimeZones.NewYork; // For this symbol we dont have any history, but only one date and margins line var ticker = QuantConnect.Securities.Futures.Indices.SP500EMini; var future = Symbol.CreateFuture(ticker, Market.CME, expDate); var symbol = Symbol.CreateOption(future, Market.CME, OptionStyle.American, OptionRight.Call, 2550m, new DateTime(2021, 3, 19)); var optionSecurity = new Option( SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, tz, tz, true, false, false), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); optionSecurity.Underlying = new Future( SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), future, Resolution.Minute, tz, tz, true, false, false), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); optionSecurity.Underlying.SetMarketPrice(new Tick { Value = price, Time = time }); optionSecurity.Underlying.Holdings.SetHoldings(1.5m, 1); var futureBuyingPowerModel = new FutureMarginModel(security: optionSecurity.Underlying); var futureOptionBuyingPowerModel = new FuturesOptionsMarginModel(futureOption: optionSecurity); // we don't hold FOPs! Assert.AreEqual(0m, futureOptionBuyingPowerModel.GetMaintenanceMargin(optionSecurity)); Assert.AreNotEqual(0m, futureBuyingPowerModel.GetMaintenanceMargin(optionSecurity.Underlying)); Assert.AreNotEqual(0m, futureOptionBuyingPowerModel.GetInitialMarginRequirement(optionSecurity, 10)); Assert.AreEqual( futureBuyingPowerModel.GetInitialMarginRequirement(optionSecurity.Underlying, 10) * FuturesOptionsMarginModel.FixedMarginMultiplier, futureOptionBuyingPowerModel.GetInitialMarginRequirement(optionSecurity, 10)); }
public void MarginRequirementsAreSetCorrectly() { var expDate = new DateTime(2021, 3, 19); var tz = TimeZones.NewYork; // For this symbol we dont have any history, but only one date and margins line var ticker = QuantConnect.Securities.Futures.Indices.SP500EMini; var future = Symbol.CreateFuture(ticker, Market.CME, expDate); var symbol = Symbol.CreateOption(future, Market.CME, OptionStyle.American, OptionRight.Call, 2550m, new DateTime(2021, 3, 19)); var futureSecurity = new Future( SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), future, Resolution.Minute, tz, tz, true, false, false), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null ); var optionSecurity = new QuantConnect.Securities.FutureOption.FutureOption(symbol, SecurityExchangeHours.AlwaysOpen(tz), new Cash(Currencies.USD, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null, new SecurityCache(), futureSecurity ); var futureMarginModel = new FuturesOptionsMarginModel(futureOption: optionSecurity); optionSecurity.Underlying.SetMarketPrice(new Tick { Value = 1500, Time = new DateTime(2001, 01, 07) }); var initialIntradayMarginRequirement = futureMarginModel.InitialIntradayMarginRequirement; var maintenanceIntradayMarginRequirement = futureMarginModel.MaintenanceIntradayMarginRequirement; var initialOvernightMarginRequirement = futureMarginModel.MaintenanceOvernightMarginRequirement; var maintenanceOvernightMarginRequirement = futureMarginModel.InitialOvernightMarginRequirement; Assert.AreNotEqual(0, initialIntradayMarginRequirement); Assert.AreNotEqual(0, maintenanceIntradayMarginRequirement); Assert.AreNotEqual(0, initialOvernightMarginRequirement); Assert.AreNotEqual(0, maintenanceOvernightMarginRequirement); }