示例#1
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);
            }
        }
        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);
        }
示例#3
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);
        }
示例#4
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);
        }