internal static void CalculateFee(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail, CurrencyRate currencyRate, DateTime tradeDayBeginTime, Settings.Account account, Settings.Instrument instrument, decimal contractSize, decimal pairRelationFactor, DateTime openOrderExecuteTime, decimal closedLot, Price executePrice, out decimal commission, out decimal levy) { bool isDayCloseRelation = openOrderExecuteTime >= tradeDayBeginTime; commission = pairRelationFactor * tradePolicyDetail.GetCommissionClose(isDayCloseRelation); levy = tradePolicyDetail.LevyClose; if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn) { decimal fractionCommission = pairRelationFactor * specialTradePolicyDetail.GetCommissionClose(isDayCloseRelation); commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, (int)closedLot, contractSize, executePrice, currencyRate) + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * fractionCommission, closedLot - (int)closedLot, contractSize, executePrice, currencyRate); } else { commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, closedLot, contractSize, executePrice, currencyRate); } if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionLevyOn) { decimal fractionLevy = specialTradePolicyDetail.LevyClose; levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, (int)closedLot, contractSize, executePrice, currencyRate) + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * fractionLevy, closedLot - (int)closedLot, contractSize, executePrice, currencyRate); } else { levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, closedLot, contractSize, executePrice, currencyRate); } }
protected override decimal CalculateCommission(ExecuteContext context) { decimal result = 0m; var setting = this.GetHistorySettings(context); var instrument = setting.Item1; var account = setting.Item2; var currencyRate = setting.Item5; var tradePolicyDetail = setting.Item3; if (instrument.CommissionFormula.TakeFeeAsCost()) { return(result); } var specialTradePolicyDetail = setting.Item4; decimal contractSize = !context.ShouldUseHistorySettings ? this.Tran.ContractSize(context.TradeDay) : tradePolicyDetail.ContractSize; if (!instrument.CommissionFormula.IsDependOnPL() && specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn) { result = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * tradePolicyDetail.CommissionOpen, (int)_order.Lot, contractSize, _order.ExecutePrice, currencyRate) + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * specialTradePolicyDetail.CommissionOpen, _order.Lot - (int)_order.Lot, contractSize, _order.ExecutePrice, currencyRate); } else { result = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * tradePolicyDetail.CommissionOpen, _order.Lot, contractSize, _order.ExecutePrice, currencyRate); } if (result >= 0) { result = Math.Max(result, tradePolicyDetail.MinCommissionOpen); } return(result); }
private static decimal CalculateCommission(FeeParameter feeParameter) { var context = feeParameter.Context; var tradeDay = context != null && context.ShouldUseHistorySettings ? Settings.Setting.Default.GetTradeDay(context.TradeDay) : Settings.Setting.Default.GetTradeDay(); bool isDayCloseRelation = feeParameter.OpenOrderExecuteTime >= tradeDay.BeginTime; decimal commission = feeParameter.PairRelationFactor * feeParameter.TradePolicyDetail.GetCommissionClose(isDayCloseRelation); if (!feeParameter.Instrument.CommissionFormula.IsDependOnPL() && feeParameter.SpecialTradePolicyDetail != null && feeParameter.SpecialTradePolicyDetail.IsFractionCommissionOn) { decimal fractionCommission = feeParameter.PairRelationFactor * feeParameter.SpecialTradePolicyDetail.GetCommissionClose(isDayCloseRelation); commission = FeeCalculator.CalculateCommission(feeParameter.Instrument.CommissionFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateCommission * commission, (int)feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate) + FeeCalculator.CalculateCommission(feeParameter.Instrument.CommissionFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateCommission * fractionCommission, feeParameter.ClosedLot - (int)feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate); } else { commission = FeeCalculator.CalculateCommission(feeParameter.Instrument.CommissionFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateCommission * commission, feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate, feeParameter.TradePL); } return(commission); }
internal static decimal CalculateCommission(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail, CurrencyRate currencyRate, DateTime tradeDayBeginTime, Settings.Account account, Settings.Instrument instrument, decimal contractSize, decimal pairRelationFactor, DateTime openOrderExecuteTime, decimal closeLot, Price closePrice) { bool isDayCloseRelation = openOrderExecuteTime >= tradeDayBeginTime; decimal commission = pairRelationFactor * tradePolicyDetail.GetCommissionClose(isDayCloseRelation); if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn) { decimal fractionCommission = pairRelationFactor * specialTradePolicyDetail.GetCommissionClose(isDayCloseRelation); commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, (int)closeLot, contractSize, closePrice, currencyRate) + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * fractionCommission, closeLot - (int)closeLot, contractSize, closePrice, currencyRate); } else { commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * commission, closeLot, contractSize, closePrice, currencyRate); } return(commission); }
private decimal CaculateFeeForCutting(decimal closedLot, Price cutPrice, ICollection <CuttingItem> cuttingItems) { if ((decimal)cutPrice == 0) { return(0m); } decimal commission = 0m, levy = 0m, otherFee = 0m; Settings.Instrument instrument = _owner.Setting; Settings.Account account = _owner.Owner.Setting(); TradePolicyDetail tradePolicyDetail = _owner.TradePolicyDetail(); SpecialTradePolicyDetail specialTradePolicyDetail = _owner.SpecialTradePolicyDetail(null); decimal contractSize = tradePolicyDetail.ContractSize; CurrencyRate currencyRate = _owner.CurrencyRate(null); if (instrument.ExchangeSystem == ExchangeSystem.Local && (account.RiskLevelAction == RiskLevelAction.CloseNetPosition || account.RiskLevelAction == RiskLevelAction.CloseAll)) { if (!instrument.CommissionFormula.TakeFeeAsCost() || !instrument.LevyFormula.TakeFeeAsCost() || !instrument.OtherFeeFormula.TakeFeeAsCost()) { foreach (CuttingItem eachCuttingItem in cuttingItems) { Price buyPrice, sellPrice, closePrice; if (eachCuttingItem.IsBuy) { buyPrice = cutPrice; sellPrice = eachCuttingItem.ExecutePrice; } else { sellPrice = cutPrice; buyPrice = eachCuttingItem.ExecutePrice; } closePrice = cutPrice; decimal subCommission = 0m, subLevy = 0m, subOtherFee = 0m; decimal tradePL = TradePLCalculator.Calculate(instrument.TradePLFormula, eachCuttingItem.CuttingLot, eachCuttingItem.ContractSize, (decimal)buyPrice, (decimal)sellPrice, (decimal)closePrice, _owner.Currency(null).Decimals); var feeParameter = new FeeParameter() { Account = account, TradePolicyDetail = tradePolicyDetail, SpecialTradePolicyDetail = specialTradePolicyDetail, Instrument = instrument, CurrencyRate = currencyRate, ContractSize = contractSize, OpenOrderExecuteTime = eachCuttingItem.ExecuteTime, ClosedLot = eachCuttingItem.CuttingLot, ExecutePrice = cutPrice, TradePL = tradePL }; OrderRelation.CalculateFee(feeParameter, out subCommission, out subLevy, out subOtherFee); commission += subCommission; levy += subLevy; otherFee += subOtherFee; } } if (instrument.LevyFormula.TakeFeeAsCost()) { levy = this.CalculateFeeCommon(account.RateLevy, tradePolicyDetail.LevyClose, closedLot, contractSize); } if (instrument.OtherFeeFormula.TakeFeeAsCost()) { otherFee = this.CalculateFeeCommon(account.RateOtherFee, tradePolicyDetail.OtherFeeClose, closedLot, contractSize); } if (instrument.CommissionFormula.TakeFeeAsCost()) { commission = this.CalculateFeeCommon(account.RateCommission, tradePolicyDetail.CommissionCloseD, closedLot, contractSize); } else { if (commission >= 0) { commission = Math.Max(commission, tradePolicyDetail.MinCommissionClose); } } } else { if (instrument.CommissionFormula.TakeFeeAsCost()) //Adjust PricePips { commission = this.CalculateFeeCommon(account.RateCommission, tradePolicyDetail.CommissionOpen, closedLot, contractSize); } else { if (!instrument.CommissionFormula.IsDependOnPL() && specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn) { commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * tradePolicyDetail.CommissionOpen, (int)closedLot, contractSize, cutPrice, currencyRate) + FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * tradePolicyDetail.CommissionOpen, closedLot - (int)closedLot, contractSize, cutPrice, currencyRate); } else { commission = FeeCalculator.CalculateCommission(instrument.CommissionFormula, instrument.TradePLFormula, account.RateCommission * tradePolicyDetail.CommissionOpen, closedLot, contractSize, cutPrice, currencyRate); } if (commission >= 0) { commission = Math.Max(commission, tradePolicyDetail.MinCommissionOpen); } } if (instrument.LevyFormula.TakeFeeAsCost()) //Adjust PricePips { levy = this.CalculateFeeCommon(account.RateLevy, tradePolicyDetail.LevyOpen, closedLot, contractSize); } else { if (!instrument.LevyFormula.IsDependOnPL() && specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionCommissionOn) { levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * tradePolicyDetail.LevyOpen, (int)closedLot , contractSize, cutPrice, currencyRate) + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * tradePolicyDetail.LevyOpen, closedLot - (int)closedLot , contractSize, cutPrice, currencyRate); } else { levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * tradePolicyDetail.LevyOpen, closedLot, contractSize, cutPrice, currencyRate); } if (!instrument.LevyFormula.IsDependOnPL() && specialTradePolicyDetail != null) { CurrencyRate cgseLevyCurrencyRate = FeeCalculator.GetCGSELevyCurrencyRate(account, instrument, specialTradePolicyDetail, currencyRate, null); levy += FeeCalculator.CalculateCGSELevy(closedLot, true, specialTradePolicyDetail, cgseLevyCurrencyRate); } } if (instrument.OtherFeeFormula.TakeFeeAsCost()) { otherFee = this.CalculateFeeCommon(account.RateOtherFee, tradePolicyDetail.OtherFeeOpen, closedLot, contractSize); } else { otherFee = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateOtherFee * tradePolicyDetail.OtherFeeOpen, closedLot, contractSize, cutPrice, currencyRate); } } return(commission + levy + otherFee);; }