예제 #1
0
 private void CalculateCommonForPhysicalOrder(PhysicalOrder order, TradeDayCommonResult result)
 {
     if (order.Instalment != null && order.Instalment.Period > 1)
     {
         decimal interestRate, remainsAmount;
         result.InstalmentInterest = PhysicalReset.InstalmentCalculator.CalculateInstalmentInterest(_info, order, out interestRate, out remainsAmount);
     }
 }
예제 #2
0
        private OrderResetResult CreateResetResult(Order order, Dictionary <Guid, TradeDayCommonResult> commonDict, Dictionary <Guid, OpenOrderPLOfCurrentDay> openOrderPLOfCurrentDayDict, Dictionary <Guid, InterestStorage> notValuedPLDict, Dictionary <Guid, InterestStorage> valuedPLDict)
        {
            OrderResetResult     resetResult  = new OrderResetResult();
            TradeDayCommonResult commonResult = null;

            if (commonDict != null)
            {
                commonDict.TryGetValue(order.Id, out commonResult);
            }

            OpenOrderPLOfCurrentDay openOrderPLOfCurrentDay = null;

            if (openOrderPLOfCurrentDayDict != null)
            {
                openOrderPLOfCurrentDayDict.TryGetValue(order.Id, out openOrderPLOfCurrentDay);
            }

            InterestStorage interestStoragePLNotValued = InterestStorage.Empty;

            if (notValuedPLDict != null)
            {
                notValuedPLDict.TryGetValue(order.Id, out interestStoragePLNotValued);
            }

            InterestStorage interestStoragePLValued = InterestStorage.Empty;

            if (valuedPLDict != null)
            {
                valuedPLDict.TryGetValue(order.Id, out interestStoragePLValued);
            }
            resetResult.TradeDay   = _info.TradeDay;
            resetResult.OrderId    = order.Id;
            resetResult.LotBalance = order.LotBalance;
            resetResult.CurrencyId = _info.RateSetting.CurrencyId;
            Price livePrice = order.IsBuy ? _info.Settings.SellPrice : _info.Settings.BuyPrice;

            resetResult.Margin = Calculator.MarginCalculator.CalculateMargin((int)_info.Instrument.MarginFormula, order.LotBalance, order.Owner.ContractSize(_info.TradeDay), order.ExecutePrice, livePrice, _info.RateSetting.RateIn, _info.RateSetting.RateOut, _info.RateSetting.RoundDecimals.Common, _info.RateSetting.RoundDecimals.Instrument);

            resetResult.PerLot = commonResult == null ? InterestStorage.Empty : new InterestStorage(commonResult.InterestPerLot, commonResult.StoragePerLot);

            resetResult.FloatPL = commonResult == null ? InterestStorage.Empty : new InterestStorage(_exchanger.ExchangeByCommonWithInstrumentSourceDecimals(order.LotBalance * commonResult.InterestPerLot), _exchanger.ExchangeByCommonWithInstrumentSourceDecimals(order.LotBalance * commonResult.StoragePerLot));

            resetResult.DayNotValuedPL = openOrderPLOfCurrentDay == null ? InterestStorage.Empty : new InterestStorage(openOrderPLOfCurrentDay.DayNotValued);

            resetResult.NotValuedPL = interestStoragePLNotValued + (openOrderPLOfCurrentDay == null ? InterestStorage.Empty : openOrderPLOfCurrentDay.NotValued);

            resetResult.ValuedPL = interestStoragePLValued + (openOrderPLOfCurrentDay == null ? InterestStorage.Empty : openOrderPLOfCurrentDay.Valued);

            if (_info.Instrument.Category == InstrumentCategory.Physical)
            {
                Physical.PhysicalOrder physicalOrder = (Physical.PhysicalOrder)order;
                resetResult.PhysicalPaidAmount         = physicalOrder.PaidAmount;
                resetResult.PaidPledgeBalance          = physicalOrder.PaidPledgeBalance;
                resetResult.PhysicalOriginValueBalance = physicalOrder.PhysicalOriginValueBalance;
                resetResult.InstalmentInterest         = commonResult == null ? 0m : commonResult.InstalmentInterest;
            }
            return(resetResult);
        }
예제 #3
0
        private TradeDayCommonResult CalculateCommonForOrder(Order order, DateTime tradeDay)
        {
            TradeDayCommonResult result          = new TradeDayCommonResult();
            OrderDayHistory      orderDayHistory = ResetManager.Default.GetOrderDayHistory(order.Id, tradeDay.AddDays(-1));

            result.StoragePerLot     = InterestAndStorageCalculater.CalculateStoragePerLot(order, orderDayHistory == null ? 0m : orderDayHistory.StoragePerLot, _info);
            result.InterestPerLot    = InterestAndStorageCalculater.CalculateInterestPerLot(order, orderDayHistory == null ? 0m : orderDayHistory.InterestPerLot, _info);
            result.InterestYearDays  = _info.Instrument.InterestYearDays;
            result.InterestValueDate = order.InterestValueDate;
            if (order.IsPhysical)
            {
                this.CalculateCommonForPhysicalOrder((PhysicalOrder)order, result);
            }
            return(result);
        }
예제 #4
0
        private Dictionary <Guid, TradeDayCommonResult> CalculateCommon()
        {
            Dictionary <Guid, TradeDayCommonResult> result = new Dictionary <Guid, TradeDayCommonResult>();

            foreach (var eachOrder in _info.OpenOrders)
            {
#if TEST
                Debug.Assert(eachOrder.Id != Guid.Parse("853603af-e6b3-4d39-b0e7-aadfc4c6b894"));
#endif
                if (!eachOrder.ShouldCalculate(_info.AffectedOrders))
                {
                    continue;
                }
                TradeDayCommonResult commonResult = this.CalculateCommonForOrder(eachOrder, _info.TradeDay);
                if (!_info.Settings.IsUseSettlementPriceForInterest && commonResult.InterestPerLot == 0m && commonResult.StoragePerLot == 0m && commonResult.InstalmentInterest == 0m)
                {
                    continue;
                }
                Debug.Assert(!result.ContainsKey(eachOrder.Id));
                result.Add(eachOrder.Id, commonResult);
            }
            return(result);
        }