private static decimal CalculateOtherFee(FeeParameter feeParameter) { decimal otherFee = feeParameter.TradePolicyDetail.OtherFeeClose; otherFee = FeeCalculator.CalculateLevy(feeParameter.Instrument.OtherFeeFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateOtherFee * otherFee, feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate); return(otherFee); }
internal void CalculateFee(ExecuteContext context) { var setting = this.GetHistorySetting(context); var instrument = setting.Item1; var closeTran = this.CloseOrder.Owner; var openTran = this.OpenOrder.Owner; var currencyRate = setting.Item5; var tradePolicyDetail = setting.Item3; var specialTradePolicyDetail = setting.Item4; decimal contractSize = !context.ShouldUseHistorySettings ? this.OpenOrder.Owner.ContractSize(context.TradeDay) : tradePolicyDetail.ContractSize; var account = setting.Item2; decimal pairRelationFactor = OrderRelation.PairRelationFactor; if (this.CloseOrder.Owner.Type == TransactionType.Pair) { pairRelationFactor = tradePolicyDetail.PairRelationFactor; } decimal commission = 0, levy = 0, otherFee = 0; if (this.CloseOrder.Owner.OrderType != OrderType.BinaryOption) { if (instrument.CommissionFormula.IsDependOnPL() || instrument.LevyFormula.IsDependOnPL()) { this.CalculatePL(context); } var feeParameter = new FeeParameter { Account = account, TradePolicyDetail = tradePolicyDetail, SpecialTradePolicyDetail = specialTradePolicyDetail, Instrument = instrument, CurrencyRate = currencyRate, ContractSize = contractSize, OpenOrderExecuteTime = openTran.ExecuteTime.Value, ClosedLot = this.ClosedLot, ExecutePrice = this.CloseOrder.ExecutePrice, TradePL = this.TradePL, Context = context, PairRelationFactor = pairRelationFactor }; OrderRelation.CalculateFee(feeParameter, out commission, out levy, out otherFee); } this.Commission = commission; this.Levy = levy; this.OtherFee = otherFee; }
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); }
private static decimal CalculateLevy(FeeParameter feeParameter) { decimal levy = feeParameter.TradePolicyDetail.LevyClose; if (!feeParameter.Instrument.LevyFormula.IsDependOnPL() && feeParameter.SpecialTradePolicyDetail != null && feeParameter.SpecialTradePolicyDetail.IsFractionLevyOn) { decimal fractionLevy = feeParameter.SpecialTradePolicyDetail.LevyClose; levy = FeeCalculator.CalculateLevy(feeParameter.Instrument.LevyFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateLevy * levy, (int)feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate) + FeeCalculator.CalculateLevy(feeParameter.Instrument.LevyFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateLevy * fractionLevy, feeParameter.ClosedLot - (int)feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate); } else { levy = FeeCalculator.CalculateLevy(feeParameter.Instrument.LevyFormula, feeParameter.Instrument.TradePLFormula, feeParameter.Account.RateLevy * levy, feeParameter.ClosedLot, feeParameter.ContractSize, feeParameter.ExecutePrice, feeParameter.CurrencyRate, feeParameter.TradePL); } if (!feeParameter.Instrument.LevyFormula.IsDependOnPL() && feeParameter.SpecialTradePolicyDetail != null) { CurrencyRate cgseLevyCurrencyRate = FeeCalculator.GetCGSELevyCurrencyRate(feeParameter.Account, feeParameter.Instrument, feeParameter.SpecialTradePolicyDetail, feeParameter.CurrencyRate, feeParameter.Context); levy += FeeCalculator.CalculateCGSELevy(feeParameter.ClosedLot, false, feeParameter.SpecialTradePolicyDetail, cgseLevyCurrencyRate); } return(levy); }
internal static void CalculateFee(FeeParameter feeParameter, out decimal commission, out decimal levy, out decimal otherFee) { commission = CalculateCommission(feeParameter); otherFee = CalculateOtherFee(feeParameter); levy = CalculateLevy(feeParameter); }