コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public void IsDiscountAdded()
        {
            string[] merchants = { "TELIA", "CIRCLE_K", "NETTO", "7-ELEVEN" };

            FeeCalculator    SUT = new FeeCalculator();
            ITransactionData transaction;

            foreach (string merchant in merchants)
            {
                transaction = new TransactionData()
                {
                    MerchantName = merchant,
                    Fee          = 1.0m
                };

                transaction.Fee = SUT.AddDiscount(transaction);

                switch (merchant)
                {
                case "TELIA":
                    Assert.AreEqual(0.9m, transaction.Fee);
                    break;

                case "CIRCLE_K":
                    Assert.AreEqual(0.8m, transaction.Fee);
                    break;

                default:
                    Assert.AreEqual(1.0m, transaction.Fee);
                    break;
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        internal decimal CalculateInstalmentAdministrationFee(decimal marketValue, ExecuteContext context)
        {
            var setting                = this.GetHistorySetting(_owner, context);
            var currencyRate           = setting.Item1;
            var instalmentPolicyDetail = setting.Item2;

            return(FeeCalculator.CaculateInstalmentAdministrationFee(marketValue, _owner.Lot, instalmentPolicyDetail, currencyRate));
        }
コード例 #7
0
        public void FeeCalculator_ShouldAddMonthlyFee_WhenAtLeastOneTransaction()
        {
            // We check following requirementInvoice Fee should be included in the fee for first transaction of the month

            // Arrange
            var merchants = new Dictionary <string, Merchant>();

            merchants.Add(sevenEleven, new Merchant()
            {
                DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 1
            });
            merchants.Add(circleK, new Merchant()
            {
                DiscountPercentage = 0, Name = circleK, FeeAsPercentage = 2
            });

            List <Transaction> transactions = new List <Transaction>
            {
                new Transaction {
                    DoneOn = new DateTime(2018, 9, 1), Amount = 100, Owner = merchants[sevenEleven]
                },
                new Transaction {
                    DoneOn = new DateTime(2018, 9, 19), Amount = 100, Owner = merchants[sevenEleven]
                },
                new Transaction {
                    DoneOn = new DateTime(2018, 10, 19), Amount = 100, Owner = merchants[circleK]
                },
            };

            var calculator = new FeeCalculator();

            // Act
            calculator.InitializeFeeCalculation();
            var processedFirstTransaction  = calculator.CalculateFee(transactions[0]);
            var processedSecondTransaction = calculator.CalculateFee(transactions[1]);
            var processedThirdTransaction  = calculator.CalculateFee(transactions[2]);

            // Assert

            // Month #9
            Assert.Equal(30M, processedFirstTransaction.Fee);
            Assert.Equal(sevenEleven, processedFirstTransaction.RelatedTransaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 9, 1), processedFirstTransaction.RelatedTransaction.DoneOn);

            Assert.Equal(1M, processedSecondTransaction.Fee);
            Assert.Equal(sevenEleven, processedSecondTransaction.RelatedTransaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 9, 19), processedSecondTransaction.RelatedTransaction.DoneOn);

            // Month #10
            Assert.Equal(31M, processedThirdTransaction.Fee);
            Assert.Equal(circleK, processedThirdTransaction.RelatedTransaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 10, 19), processedThirdTransaction.RelatedTransaction.DoneOn);
        }
コード例 #8
0
        public void Calulate_RetrunsSumOfFees_ForGivenFees()
        {
            // Arrange
            IEnumerable <IFee> fees = CreateFees();
            var sut = new FeeCalculator();

            // Act
            int actual = sut.Calulate(fees);

            // Assert
            Assert.AreEqual(6,
                            actual);
        }
コード例 #9
0
        public void IsBasicFeeAdded()
        {
            Random           randomNumber = new Random();
            IFeeCalculator   SUT          = new FeeCalculator();
            ITransactionData transaction  = new TransactionData();

            for (int i = 0; i < 100; i++)
            {
                transaction.Amount = (decimal)(randomNumber.NextDouble() * 200);
                transaction.Fee    = SUT.AddBasicFee(transaction);

                Assert.AreEqual(transaction.Amount / 100, transaction.Fee);
            }
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public void CalculateFeeTest()
        {
            string wendyJson                = Resource.GetResourceAsString("Wendy.json");
            var    invoiceHistory           = JsonUtil.DeserializeJson <Model.InvoiceHistory>(wendyJson);
            var    invoiceHistoryForAsserts = JsonUtil.DeserializeJson <Model.InvoiceHistory>(wendyJson);

            var consumptionCalc = new ConsumptionCalculator(invoiceHistory);
            var feeCalc         = new FeeCalculator(invoiceHistory);

            consumptionCalc.CalculateConsumption();

            {
                int invoiceId = 0;  // balanced
                feeCalc.CalculateFee(invoiceId);
                AssertInvoicesFee(invoiceHistoryForAsserts.Invoices.GetInvoiceById(invoiceId), invoiceHistory.Invoices.GetInvoiceById(invoiceId));
            }

            {
                int invoiceId = 14; // estimated
                feeCalc.CalculateFee(invoiceId);
                AssertInvoicesFee(invoiceHistoryForAsserts.Invoices.GetInvoiceById(invoiceId), invoiceHistory.Invoices.GetInvoiceById(invoiceId));
            }

            {
                int invoiceId = 15; // estimated
                feeCalc.CalculateFee(invoiceId);
                AssertInvoicesFee(invoiceHistoryForAsserts.Invoices.GetInvoiceById(invoiceId), invoiceHistory.Invoices.GetInvoiceById(invoiceId));
            }

            {
                int invoiceId = 16; // estimated
                feeCalc.CalculateFee(invoiceId);
                AssertInvoicesFee(invoiceHistoryForAsserts.Invoices.GetInvoiceById(invoiceId), invoiceHistory.Invoices.GetInvoiceById(invoiceId));
            }

            {
                int invoiceId = 17; // balanced
                feeCalc.CalculateFee(invoiceId);
                AssertInvoicesFee(invoiceHistoryForAsserts.Invoices.GetInvoiceById(invoiceId), invoiceHistory.Invoices.GetInvoiceById(invoiceId));
            }
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public void FeeCalculator_ShouldNotAddMonthlyFee_WhenFeeIsZero()
        {
            // IWe check following requirement-If transaction fee is 0 after applying discounts, InvoiceFee should not be added

            // Arrange
            var merchants = new Dictionary <string, Merchant>();

            merchants.Add(sevenEleven, new Merchant()
            {
                DiscountPercentage = 0, Name = sevenEleven, FeeAsPercentage = 0
            });

            List <Transaction> transactions = new List <Transaction>
            {
                new Transaction {
                    DoneOn = new DateTime(2018, 9, 1), Amount = 100, Owner = merchants[sevenEleven]
                },
                new Transaction {
                    DoneOn = new DateTime(2018, 9, 19), Amount = 100, Owner = merchants[sevenEleven]
                },
            };

            var calculator = new FeeCalculator();

            // Act
            calculator.InitializeFeeCalculation();
            var processedFirstTransactions = calculator.CalculateFee(transactions[0]);
            var processedSecondTransaction = calculator.CalculateFee(transactions[1]);

            // Assert

            // Month #9
            Assert.Equal(0, processedFirstTransactions.Fee);
            Assert.Equal(sevenEleven, processedFirstTransactions.RelatedTransaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 9, 1), processedFirstTransactions.RelatedTransaction.DoneOn);

            Assert.Equal(0, processedSecondTransaction.Fee);
            Assert.Equal(sevenEleven, processedSecondTransaction.RelatedTransaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 9, 19), processedSecondTransaction.RelatedTransaction.DoneOn);
        }
コード例 #16
0
        public void IsMothlyFeeAdded()
        {
            decimal fee1 = 0m;
            decimal fee2 = 0m;


            FeeCalculator    SUT         = new FeeCalculator();
            ITransactionData transaction = new TransactionData()
            {
                Date         = new DateTime(2020, 5, 25),
                MerchantName = "TELIA",
                Fee          = 1.2m
            };

            fee1 = SUT.AddMonthlyFee(transaction);

            transaction.Date = transaction.Date.AddMonths(1);
            transaction.Fee  = 1.2m;
            fee2             = SUT.AddMonthlyFee(transaction);

            Assert.AreEqual(fee1, fee2);


            // Test if monthly fee is added if the basic fee was 0 and now 1.2.
            SUT         = new FeeCalculator();
            transaction = new TransactionData()
            {
                Date         = new DateTime(2020, 5, 25),
                MerchantName = "TELIA",
                Fee          = 0
            };
            fee1 = SUT.AddMonthlyFee(transaction);
            Assert.AreEqual(0m, fee1);

            transaction.Fee  = 1.2m;
            transaction.Date = new DateTime(2020, 5, 26);
            fee2             = SUT.AddMonthlyFee(transaction);
            Assert.AreEqual(30.2m, (fee2 - fee1));
        }
コード例 #17
0
        public InternalTransferPaymentTransactions MakeInternalTransfer(Wallet toWallet, decimal amount)
        {
            CheckIfWalletIsBlocked();
            toWallet.CheckIfWalletIsBlocked();
            decimal feeAmount = FeeCalculator.CalculateFee(this, amount);
            bool    isWithdrawalLimitExceeded = LimitPaymentTransactionCalculator.IsWithdrawalLimitExceed(this, amount);

            if (isWithdrawalLimitExceeded)
            {
                throw new LimitExceededException();
            }
            bool isDepositLimitExceeded = LimitPaymentTransactionCalculator.IsDepositLimitExceed(toWallet, amount);

            if (isDepositLimitExceeded)
            {
                throw new LimitExceededException();
            }
            if (CurrentAmount < amount + feeAmount)
            {
                throw new NotEnoughAmountException();
            }
            string internalTransferId = Guid.NewGuid().ToString();
            var    deposit            = new DepositInternalTransferPaymentTransaction(toWallet, this, amount, internalTransferId);
            var    withdrawal         = new WithdrawalInternalTransferPaymentTransaction(this, toWallet, amount, internalTransferId);
            FeeInternalTransferPaymentTransaction feePaymentTransaction = new FeeInternalTransferPaymentTransaction(this, toWallet, feeAmount, internalTransferId);

            this.CurrentAmount     -= amount;
            toWallet.CurrentAmount += amount;
            PaymentTransactions.Add(withdrawal);
            toWallet.PaymentTransactions.Add(deposit);
            var internalTransferPaymentTransactions = new InternalTransferPaymentTransactions(deposit, withdrawal, feePaymentTransaction);

            if (internalTransferPaymentTransactions.HasFee())
            {
                this.CurrentAmount -= feeAmount;
                PaymentTransactions.Add(feePaymentTransaction);
            }
            return(internalTransferPaymentTransactions);
        }
コード例 #18
0
        public void FeeCalculator_ShouldCalculateFee_WhenDiscountProvided(string merchantName, string stringifiedTransactionDate, decimal percentageFee, decimal transactionAmount, decimal discount, decimal expectedFee)
        {
            // Arrange
            var      calculator = new FeeCalculator();
            DateTime transactionDate;
            var      transactionDateValid = DateTime.TryParseExact(stringifiedTransactionDate, "yyyy-MM-dd", null, DateTimeStyles.None, out transactionDate);
            var      merchant             = new Merchant()
            {
                Name = merchantName, FeeAsPercentage = percentageFee, DiscountPercentage = discount
            };
            var transaction = new Transaction()
            {
                Owner = merchant, Amount = transactionAmount, DoneOn = transactionDate
            };

            // Act
            calculator.InitializeFeeCalculation();
            var processedTransaction = calculator.CalculateFee(transaction);

            // Assert
            Assert.True(transactionDateValid);
            Assert.Equal(expectedFee, processedTransaction.Fee);
        }
コード例 #19
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);
        }
コード例 #20
0
ファイル: CuttingFee.cs プロジェクト: dreamsql/Outter
        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);;
        }
コード例 #21
0
 public FeeCalculatorTests()
 {
     calculator = new FeeCalculator(IntegrationSetup.Mainnet.Fetcher);
 }
コード例 #22
0
        public Builder FlatExchangeFeeRate(decimal flatExchangeFeeRate)
        {
            var calculator = new FeeCalculator(flatExchangeFeeRate, 1);

            return(new Builder(_weightings, _buyRule, _sellRule, _buyInCompleteQuantity, calculator));
        }
コード例 #23
0
        /// <summary>
        /// The cost per trade/transaction.
        /// </summary>
        /// <param name="premium">A numerical value that represents the cost of each transaction.</param>
        /// <returns></returns>
        public Builder Premium(decimal premium)
        {
            var calculator = new FeeCalculator(0, premium);

            return(new Builder(_weightings, _buyRule, _sellRule, _buyInCompleteQuantity, calculator));
        }
コード例 #24
0
        public Builder PremiumAndFees(decimal premium, decimal flatExchangeFeeRate)
        {
            var calculator = new FeeCalculator(flatExchangeFeeRate, premium);

            return(new Builder(_weightings, _buyRule, _sellRule, _buyInCompleteQuantity, calculator));
        }