예제 #1
0
        public void TestMarginForSymbolWithHistory()
        {
            const decimal price   = 1.2345m;
            var           time    = new DateTime(2013, 1, 1);
            var           expDate = new DateTime(2017, 1, 1);
            var           tz      = TimeZones.NewYork;

            // For this symbol we dont have history
            var ticker = Futures.Financials.EuroDollar;
            var symbol = Symbol.CreateFuture(ticker, Market.USA, expDate);

            var futureSecurity = new Future(SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, tz, tz, true, false, false), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)));

            futureSecurity.SetMarketPrice(new Tick {
                Value = price, Time = time
            });
            futureSecurity.Holdings.SetHoldings(1.5m, 1);

            var marginModel = new FutureMarginModel();

            Assert.AreEqual(625m, marginModel.GetMaintenanceMargin(futureSecurity));

            // now we move forward to exact date when margin req changed
            time = new DateTime(2014, 06, 13);
            futureSecurity.SetMarketPrice(new Tick {
                Value = price, Time = time
            });
            Assert.AreEqual(725m, marginModel.GetMaintenanceMargin(futureSecurity));

            // now we fly beyond the last line of the history file (currently) to see how margin model resolves future dates
            time = new DateTime(2016, 06, 04);
            futureSecurity.SetMarketPrice(new Tick {
                Value = price, Time = time
            });
            Assert.AreEqual(585m, marginModel.GetMaintenanceMargin(futureSecurity));
        }
        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));
        }
예제 #3
0
        public void TestMarginForSymbolWithNoHistory()
        {
            const decimal price   = 1.2345m;
            var           time    = new DateTime(2016, 1, 1);
            var           expDate = new DateTime(2017, 1, 1);
            var           tz      = TimeZones.NewYork;

            // For this symbol we dont have any history at all
            var ticker = "NOT-A-SYMBOL";
            var symbol = Symbol.CreateFuture(ticker, Market.USA, expDate);

            var futureSecurity = new Future(SecurityExchangeHours.AlwaysOpen(tz), new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, tz, tz, true, false, false), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)));

            futureSecurity.SetMarketPrice(new Tick {
                Value = price, Time = time
            });
            futureSecurity.Holdings.SetHoldings(1.5m, 1);

            var marginModel = new FutureMarginModel();

            Assert.AreEqual(0m, marginModel.GetMaintenanceMargin(futureSecurity));
        }