/// <summary> /// Get the maximum market order quantity to obtain a delta in the buying power used by a security. /// The deltas sign defines the position side to apply it to, positive long, negative short. /// </summary> /// <param name="parameters">An object containing the portfolio, the security and the delta buying power</param> /// <returns>Returns the maximum allowed market order quantity and if zero, also the reason</returns> /// <remarks>Used by the margin call model to reduce the position by a delta percent.</remarks> public virtual GetMaximumOrderQuantityResult GetMaximumOrderQuantityForDeltaBuyingPower( GetMaximumOrderQuantityForDeltaBuyingPowerParameters parameters) { var usedBuyingPower = parameters.Security.BuyingPowerModel.GetReservedBuyingPowerForPosition( new ReservedBuyingPowerForPositionParameters(parameters.Security)).AbsoluteUsedBuyingPower; var signedUsedBuyingPower = usedBuyingPower * (parameters.Security.Holdings.IsLong ? 1 : -1); var targetBuyingPower = signedUsedBuyingPower + parameters.DeltaBuyingPower; var target = 0m; if (parameters.Portfolio.TotalPortfolioValue != 0) { target = targetBuyingPower / parameters.Portfolio.TotalPortfolioValue; } return(GetMaximumOrderQuantityForTargetBuyingPower( new GetMaximumOrderQuantityForTargetBuyingPowerParameters(parameters.Portfolio, parameters.Security, target, parameters.SilenceNonErrorReasons))); }
/// <summary> /// Get the maximum market order quantity to obtain a delta in the buying power used by a security. /// The deltas sign defines the position side to apply it to, positive long, negative short. /// </summary> /// <param name="parameters">An object containing the portfolio, the security and the delta buying power</param> /// <returns>Returns the maximum allowed market order quantity and if zero, also the reason</returns> /// <remarks>Used by the margin call model to reduce the position by a delta percent.</remarks> public override GetMaximumOrderQuantityResult GetMaximumOrderQuantityForDeltaBuyingPower( GetMaximumOrderQuantityForDeltaBuyingPowerParameters parameters) { throw new NotImplementedException( $"The {nameof(CashBuyingPowerModel)} does not require '{nameof(GetMaximumOrderQuantityForDeltaBuyingPower)}'."); }