Exemple #1
0
 private void CalculateFloatPL(ref NecessaryAndQuantity necessaryAndQuantity, Quotation quotation)
 {
     if (!this.DoCalculateFloatPL(ref necessaryAndQuantity, quotation))
     {
         _owner.InvalidateCache();
         this.DoCalculateFloatPL(ref necessaryAndQuantity, quotation);
     }
 }
Exemple #2
0
        protected virtual void CalculateOrderFloatPL(Order order, ref NecessaryAndQuantity necessaryAndQuantity, Quotation quotation)
        {
            var oldNecessary = order.Necessary;

            order.CalculateFloatPL(quotation);
            necessaryAndQuantity.needCalculateNecessary |= this.IsNecessaryChanged(oldNecessary, order);
            this.AddUpNecessaryAndQuantity(order, ref necessaryAndQuantity);
            this.AddUpCalculatedFloatPL(order);
        }
Exemple #3
0
 protected override void AddUpNecessaryAndQuantity(Order order, ref NecessaryAndQuantity necessaryAndQuantity)
 {
     if (order.IsBuy)
     {
         necessaryAndQuantity.buyNecessarySum += order.Necessary;
         necessaryAndQuantity.buyQuantitySum  += order.QuantityBalance;
     }
     else
     {
         necessaryAndQuantity.sellNecessarySum += order.Necessary;
         necessaryAndQuantity.sellQuantitySum  += order.QuantityBalance;
     }
 }
Exemple #4
0
 private bool DoCalculateFloatPL(ref NecessaryAndQuantity necessaryAndQuantity, Quotation quotation)
 {
     foreach (Order order in _owner.ExecutedAndHasPositionOrders)
     {
         if (order.Phase != OrderPhase.Executed || order.ExecutePrice == null)
         {
             Logger.ErrorFormat("order.Id = {0}, tranId ={1}, accountId = {2} order.Phase = {3}, order.ExecutePrice = {4} invalid order", order.Id, order.Owner.Id, order.Owner.AccountId,
                                order.Phase, order.ExecutePrice);
             return(false);
         }
         this.CalculateOrderFloatPL(order, ref necessaryAndQuantity, quotation);
     }
     return(true);
 }
Exemple #5
0
        private void CalculateNecessary(ref NecessaryAndQuantity necessaryAndQuantity, DateTime baseTime)
        {
            decimal netNecessary = 0, hedgeNecessary = 0;

            this.CalculateNetAndHedgeNecessary(necessaryAndQuantity.buyNecessarySum, necessaryAndQuantity.sellNecessarySum, necessaryAndQuantity.buyQuantitySum, necessaryAndQuantity.sellQuantitySum,
                                               ref necessaryAndQuantity.partialPhysicalNecessarySum, out netNecessary, out hedgeNecessary);
            _riskData.NetNecessary   = netNecessary;
            _riskData.HedgeNecessary = hedgeNecessary;
            TradePolicy tradePolicy = _owner.Owner.Setting().TradePolicy();
            int         decimals    = Math.Min(_owner.Currency(null).Decimals, this.GetTradePolicyDetail().NecessaryRound);

            _riskData.Necessary = Math.Round(netNecessary + hedgeNecessary, decimals, MidpointRounding.AwayFromZero);
            this.CalculateMinEquitities(netNecessary, hedgeNecessary, baseTime, decimals);
            _riskData.NecessaryFillingOpenOrder       = Math.Round(tradePolicy.OpenNecessaryPolicy.Calculate(netNecessary, hedgeNecessary), decimals, MidpointRounding.AwayFromZero);
            _riskData.NecessaryFillingCloseOrder      = Math.Round(tradePolicy.CloseNecessaryPolicy.Calculate(netNecessary, hedgeNecessary), decimals, MidpointRounding.AwayFromZero);
            _riskData.PartialPaymentPhysicalNecessary = necessaryAndQuantity.partialPhysicalNecessarySum;
        }
Exemple #6
0
        public virtual void Calculate(DateTime baseTime, CalculateType calculateType, Quotation quotation)
        {
            if (_owner.ExecutedAndHasPositionOrders.Count == 0)
            {
                _riskData.Clear();
                return;
            }
            _riskData.ClearFloatingPL();
            NecessaryAndQuantity necessaryAndQuantity = new NecessaryAndQuantity();

            this.CalculateFloatPL(ref necessaryAndQuantity, quotation);
            if (calculateType != CalculateType.CheckRiskForQuotation || necessaryAndQuantity.needCalculateNecessary)
            {
                _riskData.ClearNecessary();
                this.CalculateNecessary(ref necessaryAndQuantity, baseTime);
            }

            if (this.ShouldCalculateLockOrderTradePLFloat(_owner.Owner.Setting(), necessaryAndQuantity.buyQuantitySum, necessaryAndQuantity.sellQuantitySum))
            {
                _riskData.LockOrderTradePLFloat = this.CalculateLockOrderTradePLFloat(necessaryAndQuantity.buyQuantitySum, necessaryAndQuantity.sellQuantitySum);
            }
            _riskData.RiskCredit = this.CalculateRiskCredit();
        }
Exemple #7
0
 protected abstract void AddUpNecessaryAndQuantity(Order order, ref NecessaryAndQuantity necessaryAndQuantity);