コード例 #1
0
 /// <summary>
 /// Gets the total margin required to execute the specified order in units of the account currency including fees
 /// </summary>
 /// <param name="parameters">An object containing the portfolio, the security and the order</param>
 /// <returns>The total margin in terms of the currency quoted in the order</returns>
 public InitialMargin GetInitialMarginRequiredForOrder(InitialMarginRequiredForOrderParameters parameters)
 {
     using (Py.GIL())
     {
         return((_model.GetInitialMarginRequiredForOrder(parameters) as PyObject)
                .GetAndDispose <InitialMargin>());
     }
 }
コード例 #2
0
        /// <summary>
        /// Gets the total margin required to execute the specified order in units of the account currency including fees
        /// </summary>
        /// <param name="parameters">An object containing the portfolio, the security and the order</param>
        /// <returns>The total margin in terms of the currency quoted in the order</returns>
        protected override decimal GetInitialMarginRequiredForOrder(
            InitialMarginRequiredForOrderParameters parameters)
        {
            //Get the order value from the non-abstract order classes (MarketOrder, LimitOrder, StopMarketOrder)
            //Market order is approximated from the current security price and set in the MarketOrder Method in QCAlgorithm.
            var orderFees = parameters.Security.FeeModel.GetOrderFee(
                new OrderFeeParameters(parameters.Security, parameters.Order));
            var value      = parameters.Order.GetValue(parameters.Security);
            var orderValue = value * GetInitialMarginRequirement(parameters.Security, value);

            return(orderValue + Math.Sign(orderValue) * orderFees.Value.Amount);
        }
コード例 #3
0
        /// <summary>
        /// Gets the total margin required to execute the specified order in units of the account currency including fees
        /// </summary>
        /// <param name="parameters">An object containing the portfolio, the security and the order</param>
        /// <returns>The total margin in terms of the currency quoted in the order</returns>
        protected override decimal GetInitialMarginRequiredForOrder(
            InitialMarginRequiredForOrderParameters parameters)
        {
            //Get the order value from the non-abstract order classes (MarketOrder, LimitOrder, StopMarketOrder)
            //Market order is approximated from the current security price and set in the MarketOrder Method in QCAlgorithm.

            var fees = parameters.Security.FeeModel.GetOrderFee(
                new OrderFeeParameters(parameters.Security,
                                       parameters.Order)).Value;
            var feesInAccountCurrency = parameters.CurrencyConverter.
                                        ConvertToAccountCurrency(fees).Amount;

            var orderMargin = GetInitialMarginRequirement(parameters.Security, parameters.Order.Quantity);

            return(orderMargin + Math.Sign(orderMargin) * feesInAccountCurrency);
        }
コード例 #4
0
        public InitialMargin GetInitialMarginRequiredForOrder(InitialMarginRequiredForOrderParameters parameters)
        {
            reentry = true;
            EnsureSecurityExists(parameters.Security);
            var expected = SecurityModel.GetInitialMarginRequiredForOrder(parameters);

            if (reentry)
            {
                return(expected);
            }

            var actual = PositionGroupModel.GetInitialMarginRequiredForOrder(new PositionGroupInitialMarginForOrderParameters(
                                                                                 Portfolio, new PositionGroup(PositionGroupModel, new Position(parameters.Security, parameters.Order.Quantity)), parameters.Order
                                                                                 ));

            Assert.AreEqual(expected.Value, actual.Value,
                            $"{PositionGroupModel.GetType().Name}:{nameof(GetInitialMarginRequiredForOrder)}"
                            );

            reentry = false;
            return(expected);
        }
コード例 #5
0
 public new decimal GetInitialMarginRequiredForOrder(
     InitialMarginRequiredForOrderParameters parameters)
 {
     return(base.GetInitialMarginRequiredForOrder(parameters).Value);
 }