示例#1
0
        private decimal CalculateValuedOpenOrderPL()
        {
            decimal result = 0m;

            foreach (var eachOrderResetResult in _resetResultDict.Values)
            {
                var eachOrder = _info.GetOrder(eachOrderResetResult.OrderId);
                if (!eachOrder.IsOpen)
                {
                    continue;
                }
                result += eachOrderResetResult.ValuedPL.Interest + eachOrderResetResult.ValuedPL.Storage;
            }
            return(result);
        }
示例#2
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);
        }