예제 #1
0
        private static ITransactionNTM transferPosition(IDalSession session, IPositionTransferDetail detail, IAccountTypeInternal account, bool transferOut)
        {
            IAccountTypeInternal AcctA = account;
            IAccount AcctB = account.DefaultAccountforTransfer;

            Price Price = detail.TransferPrice;
            ICurrency currency = detail.TransferPrice.Underlying;
            Money CounterValueSize = Price.Amount.ZeroedAmount();
            decimal ExRate = detail.ExchangeRate;
            DateTime TransactionDate = detail.TransferDate;
            string ExternalSource = transferOut ? detail.ParentTransfer.DescriptionAccountA : detail.ParentTransfer.DescriptionAccountA;
            Side txSide = transferOut ? Side.XO : Side.XI;
            InstrumentSize ValueSize = transferOut ? detail.PositionSize.Abs().Negate() : detail.PositionSize.Abs();

            ITradingJournalEntry tradingJournalEntry = TransactionAdapter.GetNewTradingJournalEntry(session, currency.Symbol, TransactionDate);
            IGLLookupRecords lookups = GlLookupRecordMapper.GetGLLookupRecords(session, BookingComponentParentTypes.Transaction);
            ListOfTransactionComponents[] txcomps = new ListOfTransactionComponents[0];

            TransactionNTM ntm = new TransactionNTM(AcctA, AcctB, ValueSize, Price, ExRate,
                                    TransactionDate, TransactionDate.AddHours(10), 0M, txSide,
                                    tradingJournalEntry, lookups, txcomps, ExternalSource);
            IInternalEmployeeLogin employee = detail.ParentTransfer.CreatedBy;
            ntm.Approve(employee);
            return ntm;
        }
예제 #2
0
 public override ITransaction Storno(IAccountTypeInternal stornoAccount, IInternalEmployeeLogin employee, string reason, ITradingJournalEntry tradingJournalEntry)
 {
     ITransactionNTM newStorno = new TransactionNTM();
     this.storno(stornoAccount, employee, reason, tradingJournalEntry, newStorno);
     return newStorno;
 }
예제 #3
0
        public static int LichtenDividend(int dividendKey)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                int successCount = 0;
                IDividendHistory history = DividendHistoryMapper.GetDividendHistory(session, dividendKey);
                int todoCount = -1;
                if (history.NeedsStockDividend && !history.IsGelicht)
                {
                    if (history.SettlementDate > DateTime.Today)
                        throw new ApplicationException("The settlement date is in the future.");

                    todoCount = history.StockDividends.Where(x => !x.IsGelicht).Count();
                    //IList<IHistoricalPosition> stockDivPositions = B4F.TotalGiro.MIS.StoredPositions.StoredPositionTransactionMapper.GetAccountsWithPositionByDate(session, history.SettlementDate, history.StockDividend.Key);

                    if (todoCount > 0)
                    {
                        IInternalEmployeeLogin employee = LoginMapper.GetCurrentEmployee(session);
                        int journalId = int.Parse((string)(System.Configuration.ConfigurationManager.AppSettings.Get(@"DefaultDividendJournal")));
                        IJournal journal = JournalMapper.GetJournal(session, journalId);
                        IGLLookupRecords lookups = GlLookupRecordMapper.GetGLLookupRecords(session, BookingComponentParentTypes.CashDividend);
                        DateTime transactionDate = history.SettlementDate;
                        IStockDividend instDiv = history.StockDividend;
                        Price price = instDiv.CurrentPrice.Get(e => e.Price);
                        IFeeFactory feeFactory = null;

                        foreach (int stDivId in history.StockDividends.Where(x => !x.IsGelicht).Select(x => x.Key))
                        {
                            IDalSession session2 = NHSessionFactory.CreateSession();
                            ICorporateActionStockDividend stDiv = (ICorporateActionStockDividend)TransactionMapper.GetTransaction(session2, stDivId);
                            ITradingJournalEntry tradingJournalEntry = getNewStockDividendBooking(session2, journal, transactionDate);
                            IAccountTypeCustomer account = (IAccountTypeCustomer)stDiv.AccountA;
                            ICorporateActionExecution corpaExec = new CorporateActionExecution(
                                account, account.DefaultAccountforTransfer,
                                new InstrumentSize(stDiv.ValueSize.Quantity * -1M, instDiv), price,
                                instDiv.CurrencyNominal.ExchangeRate.Rate, transactionDate,
                                history, tradingJournalEntry, "Lichten van " + instDiv.DisplayIsinWithName );

                            if (history.DividendType == DividendTypes.Cash)
                            {
                                if (feeFactory == null)
                                    feeFactory = FeeFactory.GetInstance(session, FeeFactoryInstanceTypes.Commission);
                                IMemorialBooking dividendBooking = getNewCashDividendBooking(session2, journal, transactionDate);
                                ICashDividend newBooking = new CashDividend(account,
                                    dividendBooking, history.Description, history.TaxPercentage,
                                    history, stDiv.ValueSize, lookups);
                                executeBooking(newBooking, feeFactory);

                                corpaExec.CounterBooking = newBooking;
                            }
                            else
                            {
                                InstrumentSize size = new InstrumentSize(stDiv.ValueSize.Quantity, instDiv.Underlying);
                                ITransactionNTM ntm = new TransactionNTM(account, account.DefaultAccountforTransfer,
                                        size, instDiv.Underlying.CurrentPrice.Get(e => e.Price), instDiv.CurrencyNominal.ExchangeRate.Rate,
                                        transactionDate, transactionDate, 0M, size.Sign ? Side.XI : Side.XO,
                                        tradingJournalEntry, null, null, "Stock dividend " + instDiv.Underlying.DisplayIsinWithName);
                                ntm.Approve(employee);

                                corpaExec.CounterTransaction = ntm;
                            }
                            corpaExec.Approve(employee);
                            stDiv.IsGelicht = true;
                            session2.BeginTransaction();
                            if (session2.Insert(corpaExec) && session2.Update(stDiv))
                            {
                                if (session2.CommitTransaction())
                                    successCount++;
                            }
                        }
                    }
                    if (todoCount == successCount)
                    {
                        history.IsGelicht = true;
                        session.InsertOrUpdate(history);
                    }
                }
                return dividendKey;
            }
        }