Exemplo n.º 1
0
        private decimal CalculateOrderPledge(PhysicalOrder order)
        {
            decimal orderDebit  = this.CalculateOrderDebit(order);
            decimal marketValue = MarketValueCalculator.CalculateMarkValue(order.LotBalance, this.GetLivePrice(order.IsBuy), this.TradePolicyDetail.DiscountOfOdd, (int)Instrument.TradePLFormula, order.Owner.ContractSize(this.TradeDay));

            marketValue = marketValue.Exchange(CurrencyRate.RateIn, CurrencyRate.RateOut, this.AccountCurrencyDecimals, null);
            marketValue = marketValue * (orderDebit == 0 ? this.TradePolicyDetail.ValueDiscountAsMargin : this.TradePolicyDetail.InstalmentPledgeDiscount);
            return(marketValue - orderDebit);
        }
Exemplo n.º 2
0
        internal void CalculateOriginValue(ExecuteContext context)
        {
            var     tran        = this.Owner;
            var     instrument  = tran.SettingInstrument();
            decimal originValue = MarketValueCalculator.CalculateValue(instrument.TradePLFormula, this.Lot, this.ExecutePrice, tran.TradePolicyDetail(context.TradeDay).DiscountOfOdd, tran.ContractSize(context.TradeDay));

            this.PhysicalOriginValue = this.IsBuy ? tran.CurrencyRate(null).Exchange(originValue, ExchangeDirection.RateOut) : tran.CurrencyRate(null).Exchange(originValue, ExchangeDirection.RateIn);
            if (this.IsOpen)
            {
                this.PhysicalOriginValueBalance = this.PhysicalOriginValue;
            }
            else
            {
                this.CalculateFrozenLotAndFund(context);
            }
        }
Exemplo n.º 3
0
 internal void PayOff(DateTime?tradeDay)
 {
     this.PaidPledgeBalance = -this.PhysicalOriginValueBalance;
     if (!this.IsPartialPaymentPhysicalOrder)
     {
         //this.AddBill(new TransactionBill(this.AccountId, -this.Necessary, BillType.Margin, BillOwnerType.Order));
         //this.AddBill(new TransactionBill(this.AccountId, -this.TradePLFloat, BillType.TradePLFloat, BillOwnerType.Order));
         //this.AddBill(new TransactionBill(this.AccountId, -this.PaidAmount, BillType.PhysicalPaidAmount, BillOwnerType.Order));
         this.PhysicalFloating.CalculateNecessary(this.LotBalance);
         this.PhysicalFloating.CalculateTradePL(this.Owner.AccountInstrument.GetQuotation());
         decimal marketAsValue = 0m;
         MarketValueCalculator.CalculateMarketValue(this, this.ExecutePrice, tradeDay, out marketAsValue);
         //this.AddBill(new TransactionBill(this.AccountId, this.Necessary, BillType.Margin, BillOwnerType.Order));
         //this.AddBill(new TransactionBill(this.AccountId, this.TradePLFloat, BillType.TradePLFloat, BillOwnerType.Order));
         //this.AddBill(new TransactionBill(this.AccountId, marketAsValue, BillType.PhysicalMarketAsValue, BillOwnerType.Order));
     }
 }
Exemplo n.º 4
0
        internal static decimal CalculatePreCheckBalance(this Instrument instrument)
        {
            if (!instrument.IsPhysical)
            {
                return(0);
            }
            Price     buy       = null;
            Account   account   = instrument.Owner;
            Quotation quotation = QuotationProvider.GetLatestQuotation(instrument.Id, account);

            Debug.Assert(quotation != null);
            buy = quotation.BuyOnCustomerSide;
            decimal           preCheckBalance   = 0m;
            TradePolicyDetail tradePolicyDetail = instrument.TradePolicyDetail;

            foreach (Transaction tran in account.GetTransactions(instrument.Id))
            {
                foreach (PhysicalOrder order in tran.Orders)
                {
                    if (order.PhysicalTradeSide == PhysicalTradeSide.Buy && order.IsOpen)
                    {
                        if (order.Phase == OrderPhase.Placed || order.Phase == OrderPhase.Placing)
                        {
                            var     price       = order.SetPrice == null ? buy : order.SetPrice;
                            decimal marketValue = MarketValueCalculator.CalculateValue(instrument.Setting.TradePLFormula, order.Lot, price,
                                                                                       tradePolicyDetail.DiscountOfOdd, tradePolicyDetail.ContractSize);

                            if (order.IsInstalment)
                            {
                                decimal instalmentAdministrationFee = order.CalculateInstalmentAdministrationFee(marketValue);
                                decimal downPayment = order.CalculatePaidAmount(marketValue);
                                preCheckBalance += (instalmentAdministrationFee + downPayment);
                            }
                            else
                            {
                                preCheckBalance += marketValue;
                            }
                        }
                    }
                }
            }
            return(preCheckBalance);
        }
Exemplo n.º 5
0
        private static decimal CalculateMarketValue(Transaction tran, decimal originShortSellLot, DateTime?tradeDay)
        {
            decimal totalMarketValue   = 0m;
            var     tradePolicyDetail  = tran.TradePolicyDetail(tradeDay);
            decimal contractSize       = tran.ContractSize(tradeDay) == 0 ? tradePolicyDetail.ContractSize : tran.ContractSize(tradeDay);
            decimal remainShortSellLot = originShortSellLot;

            foreach (PhysicalOrder order in tran.Orders)
            {
                if (!order.IsPhysical)
                {
                    continue;
                }
                if (order.IsOpen && order.PhysicalTradeSide == PhysicalTradeSide.Buy)
                {
                    if (remainShortSellLot < order.LotBalance)
                    {
                        decimal lot         = order.LotBalance - remainShortSellLot;
                        var     quotation   = tran.AccountInstrument.GetQuotation(tran.SubmitorQuotePolicyProvider);
                        decimal marketValue = MarketValueCalculator.CalculateValue(tran.SettingInstrument(tradeDay).TradePLFormula,
                                                                                   lot, quotation.SellPrice, tradePolicyDetail.DiscountOfOdd, contractSize);
                        if (tran.Owner.Setting(tradeDay).IsMultiCurrency)
                        {
                            int decimals = tran.AccountInstrument.Currency(tradeDay).Decimals;
                            marketValue = Math.Round(marketValue, decimals, MidpointRounding.AwayFromZero);
                        }
                        else
                        {
                            var currencyRate = tran.CurrencyRate(tradeDay);
                            marketValue = currencyRate.Exchange(marketValue);
                        }
                        totalMarketValue += marketValue;
                    }
                    remainShortSellLot -= order.LotBalance;
                    if (remainShortSellLot < 0)
                    {
                        remainShortSellLot = 0;
                    }
                }
            }
            return(totalMarketValue);
        }
Exemplo n.º 6
0
        internal void LockForDelivery(decimal deliveryLot)
        {
            this.DeliveryLockLot += deliveryLot;
            Quotation quotation = _owner.Owner.AccountInstrument.GetQuotation();
            Price     price     = quotation == null ? _owner.ExecutePrice : (_owner.IsBuy ? quotation.SellPrice : quotation.BuyPrice);
            decimal   valueAsMargin;

            MarketValueCalculator.CalculateMarketValue(_owner, price, null, out valueAsMargin);
            var account = _owner.Owner.Owner;

            if (account.IsMultiCurrency)
            {
                var fund = account.GetOrCreateFund(_owner.Owner.CurrencyId);
                fund.AddValueAsMargin(valueAsMargin);
            }
            else
            {
                var fund         = account.GetOrCreateFund(account.Setting().CurrencyId);
                var currencyRate = Settings.Setting.Default.GetCurrencyRate(_owner.Owner.CurrencyId, account.Setting().CurrencyId);
                fund.AddValueAsMargin(currencyRate.Exchange(valueAsMargin));
            }
        }
Exemplo n.º 7
0
        internal override decimal CalculatePrecheckBalance()
        {
            var     physicalOrder = (Physical.PhysicalOrder)_order;
            decimal result        = 0m;

            if (physicalOrder.PhysicalTradeSide == PhysicalTradeSide.Buy && _order.IsOpen && (_order.Phase == OrderPhase.Placed || _order.Phase == OrderPhase.Placing))
            {
                var     quotation   = _order.Owner.AccountInstrument.GetQuotation();
                var     price       = _order.SetPrice == null ? quotation.BuyPrice : _order.SetPrice;
                decimal marketValue = MarketValueCalculator.CalculateValue(_order.Owner.SettingInstrument().TradePLFormula, _order.Lot, price, _order.Owner.TradePolicyDetail().DiscountOfOdd, _order.Owner.TradePolicyDetail().ContractSize);
                if (physicalOrder.IsInstalment)
                {
                    decimal instalmentAdministrationFee = physicalOrder.CalculateInstalmentAdministrationFee(marketValue);
                    decimal downPayment = physicalOrder.CalculatePaidAmountForPledge(marketValue);
                    result = instalmentAdministrationFee + downPayment;
                }
                else
                {
                    result = marketValue;
                }
            }
            return(result);
        }