Пример #1
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);
        }
Пример #2
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);;
        }