Exemplo n.º 1
0
        private void CalculatePL(OrderDayHistory orderDayHistory, Dictionary <Guid, InterestStorage> dict, Exchanger exchanger)
        {
            var             interestPL = exchanger.ExchangeByCommonDecimals(orderDayHistory.DayInterestPLNotValued);
            var             storagePL  = exchanger.ExchangeByCommonDecimals(orderDayHistory.DayStoragePLNotValued);
            InterestStorage interestStoragePL;

            if (!dict.TryGetValue(orderDayHistory.OrderID, out interestStoragePL))
            {
                dict.Add(orderDayHistory.OrderID, new InterestStorage(interestPL, storagePL));
            }
            else
            {
                dict[orderDayHistory.OrderID] = new InterestStorage(interestStoragePL.Interest + interestPL, interestStoragePL.Storage + storagePL);
            }
        }
Exemplo n.º 2
0
        private static decimal CalculatePhysicalTradePL(PhysicalOrderRelation orderRelation, Exchanger exchanger)
        {
            decimal result = 0m;

            if (orderRelation.PhysicalValueMatureDay == null || orderRelation.RealPhysicalValueMatureDate == orderRelation.PhysicalValueMatureDay)
            {
                result = exchanger.ExchangeByCommonDecimals(orderRelation.TradePL);
            }
            return(result);
        }
Exemplo n.º 3
0
        internal static Dictionary <Guid, OpenOrderPLOfCurrentDay> Calculate(TradeDayInfo tradeDayInfo, Dictionary <Guid, TradeDayCommonResult> resetCommonResultDict, Exchanger exchanger)
        {
            if (tradeDayInfo.Settings.ValueDate == null && !tradeDayInfo.Settings.UseCompatibleMode)
            {
                return(null);
            }
            Dictionary <Guid, OpenOrderPLOfCurrentDay> result = new Dictionary <Guid, OpenOrderPLOfCurrentDay>();

            foreach (var eachPair in resetCommonResultDict)
            {
                var orderId           = eachPair.Key;
                var commonResetResult = eachPair.Value;
                if (!orderId.ShouldCalculate(tradeDayInfo.AffectedOrders))
                {
                    continue;
                }
                var eachOrder = tradeDayInfo.GetOrder(orderId);
                if (!IsOpenOrderOfCurrentDay(eachOrder, tradeDayInfo))
                {
                    continue;
                }
                OpenOrderPLOfCurrentDay openOrderPLOfCurrentDay = new OpenOrderPLOfCurrentDay();
                int decimals = tradeDayInfo.Settings.IsInterestUseAccountCurrency ? tradeDayInfo.RateSetting.RoundDecimals.Max : tradeDayInfo.RateSetting.RoundDecimals.Instrument;
                var storage  = Math.Round(eachOrder.LotBalance * commonResetResult.StoragePerLot, decimals, MidpointRounding.AwayFromZero);
                var interest = Math.Round(eachOrder.LotBalance * commonResetResult.InterestPerLot, decimals, MidpointRounding.AwayFromZero);
                openOrderPLOfCurrentDay.DayNotValued += tradeDayInfo.Settings.ShouldValueCurrentDayPL ? InterestStorage.Empty : new InterestStorage(interest, storage);

                var exchangeStorage  = exchanger.ExchangeByCommonDecimals(storage);
                var exchangeInterest = exchanger.ExchangeByCommonDecimals(interest);
                openOrderPLOfCurrentDay.NotValued += tradeDayInfo.Settings.ShouldValueCurrentDayPL ? InterestStorage.Empty : new InterestStorage(exchangeInterest, exchangeStorage);

                bool    isInterestValued = (eachOrder.InterestValueDate ?? tradeDayInfo.TradeDay) <= tradeDayInfo.TradeDay;
                decimal interestPLValued = tradeDayInfo.Settings.ShouldValueCurrentDayPL && isInterestValued ? exchangeInterest : 0;
                decimal storagePLValued  = tradeDayInfo.Settings.ShouldValueCurrentDayPL ? exchangeStorage : 0;
                openOrderPLOfCurrentDay.Valued += new InterestStorage(interestPLValued, storagePLValued);

                openOrderPLOfCurrentDay.IsInterestValued = isInterestValued;
                openOrderPLOfCurrentDay.IsStorageValued  = true;
                result.Add(orderId, openOrderPLOfCurrentDay);
            }
            return(result);
        }
Exemplo n.º 4
0
 private static void CalculateNotValuedOrderRelationPL(TradeDayInfo tradeDayInfo, Exchanger exchanger, Dictionary <Guid, OrderResetResult> resetOrderDict, List <Guid> affectedOrders)
 {
     foreach (var eachOrderRelation in tradeDayInfo.OrderRelations)
     {
         Order closeOrder = eachOrderRelation.CloseOrder;
         if (!closeOrder.ShouldCalculate(affectedOrders))
         {
             continue;
         }
         PhysicalOrder         physicalCloseOrder    = closeOrder as PhysicalOrder;
         PhysicalOrderRelation physicalOrderRelation = eachOrderRelation as PhysicalOrderRelation;
         if (closeOrder.Phase == OrderPhase.Executed && !closeOrder.IsOpen && closeOrder.ExecuteTime <= tradeDayInfo.Settings.ResetTime && eachOrderRelation.ValueTime == null)
         {
             OrderResetResult resetResult = CreateOrderResetResult(closeOrder, tradeDayInfo, resetOrderDict);
             resetResult.NotValuedPL      += new InterestStorage(exchanger.ExchangeByCommonDecimals(eachOrderRelation.InterestPL), exchanger.ExchangeByCommonDecimals(eachOrderRelation.StoragePL));
             resetResult.TradePLNotValued += exchanger.ExchangeByCommonDecimals(eachOrderRelation.TradePL);
             if (physicalOrderRelation != null)
             {
                 resetResult.PhysicalTradePLNotValued += CalculatePhysicalTradePL(physicalOrderRelation, exchanger);
             }
         }
     }
 }