Beispiel #1
0
        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 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);
            }
        }
Beispiel #3
0
        protected override decimal CalculateLevy(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;
            decimal contractSize      = !context.ShouldUseHistorySettings ? this.Tran.ContractSize(context.TradeDay) : tradePolicyDetail.ContractSize;

            if (instrument.LevyFormula.TakeFeeAsCost())
            {
                return(result);
            }
            var specialTradePolicyDetail = setting.Item4;

            if (!instrument.LevyFormula.IsDependOnPL() && specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionLevyOn)
            {
                result = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * tradePolicyDetail.LevyOpen, (int)_order.Lot, contractSize, _order.ExecutePrice, currencyRate)
                         + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * specialTradePolicyDetail.LevyOpen, _order.Lot - (int)_order.Lot, contractSize, _order.ExecutePrice, currencyRate);
            }
            else
            {
                result = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * tradePolicyDetail.LevyOpen, _order.Lot, contractSize, _order.ExecutePrice, currencyRate);
            }

            if (!instrument.LevyFormula.IsDependOnPL() && specialTradePolicyDetail != null)
            {
                var cgseLevyCurrencyRate = specialTradePolicyDetail.GetCGSELevyCurrencyRate(account, instrument, currencyRate, context);
                result += FeeCalculator.CalculateCGSELevy(_order.Lot, true, specialTradePolicyDetail, cgseLevyCurrencyRate);
            }
            return(result);
        }
Beispiel #4
0
        protected override decimal CalculateOtherFee(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;
            decimal contractSize      = !context.ShouldUseHistorySettings ? this.Tran.ContractSize(context.TradeDay) : tradePolicyDetail.ContractSize;

            if (instrument.OtherFeeFormula.TakeFeeAsCost())
            {
                return(result);
            }
            result = FeeCalculator.CalculateLevy(instrument.OtherFeeFormula, instrument.TradePLFormula, account.RateOtherFee * tradePolicyDetail.OtherFeeOpen, _order.Lot, contractSize, _order.ExecutePrice, currencyRate);
            return(result);
        }
        internal static decimal CalculateLevy(TradePolicyDetail tradePolicyDetail, SpecialTradePolicyDetail specialTradePolicyDetail,
                                              CurrencyRate currencyRate, Settings.Account account, Settings.Instrument instrument, decimal contractSize, decimal closeLot, Price closePrice)
        {
            decimal levy = tradePolicyDetail.LevyClose;

            if (specialTradePolicyDetail != null && specialTradePolicyDetail.IsFractionLevyOn)
            {
                decimal fractionLevy = specialTradePolicyDetail.LevyClose;

                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, (int)closeLot, contractSize, closePrice, currencyRate)
                       + FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * fractionLevy, closeLot - (int)closeLot, contractSize, closePrice, currencyRate);
            }
            else
            {
                levy = FeeCalculator.CalculateLevy(instrument.LevyFormula, instrument.TradePLFormula, account.RateLevy * levy, closeLot, contractSize, closePrice, currencyRate);
            }

            return(levy);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);;
        }