Пример #1
0
        public PositionRowView(IFundPosition position)
        {
            key = position.Key;
            instrumentName = position.Size.Underlying.DisplayName;
            size = position.Size.Quantity;
            value = position.CurrentBaseValue;
            modelAllocation = Math.Round(100m * position.ModelAllocation, 4);

            if (position.Size.Underlying.IsWithPrice)
            {
                IInstrumentsWithPrices instrument = (IInstrumentsWithPrices)position.Size.Underlying;
                isin = instrument.Isin;
                IsCloseable = instrument.IsTradeable;
                if (instrument.CurrentPrice != null)
                {
                    price = instrument.CurrentPrice.Price;
                    priceDate = instrument.CurrentPrice.Date;
                }
                if (instrument.CurrencyNominal.ExchangeRate != null)
                    exchangeRate = instrument.CurrencyNominal.ExchangeRate.Rate;
                else
                {
                    if (instrument.CurrencyNominal.IsBase)
                        exchangeRate = 1M;
                }
                if (instrument.SecCategory.Key == SecCategories.Bond)
                {
                    IBond bond = (IBond)instrument;
                    if (bond != null && bond.DoesPayInterest)
                    {
                        AccruedInterest = position.
                            Get(v => v.BondCouponPayments).
                            Get(w => w.ActivePayment).
                            Get(x => x.DailyCalculations.
                            Get(y => y.LastCalculation).
                            Get(z => z.CalculatedAccruedInterestUpToDate));

                        ShowAccruedInterest = (AccruedInterest != null && AccruedInterest.IsNotZero);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dividendDetails">The details of the cash dividend (date, price)</param>
        /// <param name="units">The total number of units over which dividend is paid</param>
        public BondCouponPayment(IFundPosition position,
            ICouponHistory couponHistory,
            IMemorialBooking journalEntry)
            : base(position.Account, journalEntry, "")
        {
            if (position == null)
                throw new ApplicationException("The position is mandatory.");

            if (couponHistory == null)
                throw new ApplicationException("The coupon history item is mandatory.");

            if (position.Instrument.SecCategory.Key != SecCategories.Bond)
                throw new ApplicationException("The Bond is mandatory.");

            this.Position = position;
            this.CouponHistory = couponHistory;
            this.Description = couponHistory.Description;
            this.Status = BondCouponPaymentStati.Active;
            // Only print the nota after the Booking Settles
            this.IsNotarizable = false;

            IBondCouponPaymentComponent newComponent = new BondCouponPaymentComponent(this, BookingComponentTypes.AccruedInterest, this.CreationDate);
            this.Components.Add(newComponent);
        }
Пример #3
0
 internal void Add(IFundPosition pos)
 {
     PositionComparer pc = getPos((IInstrument)pos.InstrumentOfPosition);
     if (parent.Account.BaseCurrency.Equals(pos.CurrentValue.Underlying))
         pc.ActualPositionValue = pos.CurrentValue;
     else
         pc.ActualPositionValue = pos.CurrentValue.CurrentBaseAmount;
     pc.ActualPositionSize = pos.Size;
     if (pos.InstrumentOfPosition.CurrentPrice != null)
         pc.LastPrice = pos.InstrumentOfPosition.CurrentPrice.Price;
 }
Пример #4
0
 public static List<IFundPositionTx> GetPositionTransactions(IDalSession session, IFundPosition position)
 {
     return GetPositionTransactions(session, position, true);
 }
Пример #5
0
 public static List<IFundPositionTx> GetPositionTransactions(IDalSession session, IFundPosition position, int[] positionTxIds)
 {
     List<ICriterion> expressions = new List<ICriterion>();
     expressions.Add(Expression.Eq("ParentPosition.Key", position.Key));
     expressions.Add(Expression.In("Key", positionTxIds));
     return session.GetTypedList<FundPositionTx, IFundPositionTx>(expressions);
 }
Пример #6
0
        public static List<IFundPositionTx> GetPositionTransactions(IDalSession session, IFundPosition position, bool retrieveNonClientDisplayable)
        {
            Hashtable parameters = new Hashtable();
            Hashtable parameterLists = new Hashtable(1);
            parameters.Add("accountId", position.Account.Key);
            if (!retrieveNonClientDisplayable)
                parameters.Add("showStornos", false);
            parameterLists.Add("pedigree", position.InstrumentOfPosition.GetInstrumentPedigree()
                                                                        .Cast<IInstrument>().Select(i => i.Key).ToList());

            return session.GetTypedListByNamedQuery<IFundPositionTx>(
                "B4F.TotalGiro.Accounts.Portfolios.FundPositions.GetFundPositionTxs",
                parameters,
                parameterLists);
        }
Пример #7
0
        private static bool processBondPosition(
            IFundPosition pos, IExchange exchange, DateTime upToDate,
            IList<IBondCouponPaymentDailyCalculation> oldCalculations, IGLLookupRecords lookups, 
            IDalSession session)
        {
            bool success = false;
            IBond bond = pos.Instrument as IBond;
            if (bond == null || bond.SecCategory.Key != SecCategories.Bond)
                throw new ApplicationException(string.Format("The instrument {0} is not a bond.", pos.Instrument.DisplayIsinWithName));

            if (bond.DoesPayInterest)
            {
                DateTime calcDate;
                if (Util.IsNotNullDate(pos.LastBondCouponCalcDate))
                    calcDate = pos.LastBondCouponCalcDate.AddDays(1);
                else
                    calcDate = pos.OpenDate;

                while (calcDate <= upToDate)
                {
                    if (exchange == null)
                        exchange = bond.DefaultExchange ?? bond.HomeExchange;

                    InstrumentSize size = pos.PositionTransactions.Where(x => x.TransactionDate <= calcDate).Select(x => x.Size).Sum();
                    if (size != null && size.IsNotZero)
                    {
                        if (!Util.IsWeekendOrHoliday(calcDate, exchange.ExchangeHolidays))
                        {
                            DateTime settlementDate = bond.GetSettlementDate(calcDate, exchange);

                            IBondCouponPayment bip = null;
                            DateTime lastCouponDate = bond.LastCouponDate(settlementDate);
                            if (Util.IsNullDate(lastCouponDate))
                                lastCouponDate = bond.IssueDate;
                            DateTime nextCouponDate = bond.NextCouponDate(settlementDate);
                            if ((bond.IsPerpetual || bond.MaturityDate >= settlementDate) &&
                                Util.IsNotNullDate(lastCouponDate) && lastCouponDate <= settlementDate &&
                                Util.IsNotNullDate(nextCouponDate) && nextCouponDate >= settlementDate)
                            {
                                // Per position -> Does have an Active BondCouponPayment
                                bip = pos.BondCouponPayments.GetBondCouponPaymentByDate(settlementDate);
                                if (bip == null)
                                {
                                    ICouponHistory couponHistory = bond.Coupons.GetCouponByDate(settlementDate);
                                    if (couponHistory == null)
                                    {
                                        couponHistory = new CouponHistory(bond, lastCouponDate, nextCouponDate);
                                        bond.Coupons.AddCoupon(couponHistory);
                                    }
                                    int journalID = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get("DefaultAccruedInterestJournal")));
                                    IJournal journal = JournalMapper.GetJournal(session, journalID);
                                    string nextJournalEntryNumber = JournalEntryMapper.GetNextJournalEntryNumber(session, journal);
                                    IMemorialBooking memorialBooking = new MemorialBooking(journal, nextJournalEntryNumber);
                                    memorialBooking.TransactionDate = couponHistory.EndAccrualDate;
                                    bip = new BondCouponPayment(pos, couponHistory, memorialBooking);
                                    pos.BondCouponPayments.AddPayment(bip);
                                }
                                if (bip != null)
                                {
                                    // Add interest accrual
                                    bip.CalculateDailyInterest(size, calcDate, settlementDate,
                                        oldCalculations != null && oldCalculations.Count > 0 ? oldCalculations.Where(x => x.CalcDate == calcDate).ToList() : null,
                                        lookups);
                                }
                            }

                            // If coupon payment date equals settlementDate -> set to status -> to-be-settled
                            if (bip != null && nextCouponDate <= settlementDate)
                                bip.SetToBeSettled(calcDate, settlementDate);

                            // If coupon payment date -> pay (unsettled to settled)
                            // Settle the interest
                            List<IBondCouponPayment> bipsToBeSettled  = pos.BondCouponPayments.ToBeSettledPayments(calcDate);
                            if (bipsToBeSettled != null && bipsToBeSettled.Count > 0)
                            {
                                foreach (IBondCouponPayment bipToBeSettled in bipsToBeSettled)
                                    bipToBeSettled.SettleInterest(calcDate);
                            }
                            success = true;
                        }
                        pos.LastBondCouponCalcDate = calcDate;
                    }
                    calcDate = calcDate.AddDays(1);
                }
            }
            return success;
        }