Ejemplo n.º 1
0
 public PortfolioDevelopmentCash(PortfolioDevelopment parent, ValuationCashTypes valuationCashType, string cashTypeDescription, Money amount)
 {
     this.parent = parent;
     this.valuationCashType = valuationCashType;
     this.cashTypeDescription = cashTypeDescription;
     this.amount = amount;
 }
Ejemplo n.º 2
0
 public static PortfolioDevelopment GetPortfolioDevelopment(IDalSession session, IAccountTypeInternal account, DateTime startDate, DateTime endDate, int modelID)
 {
     IList<IValuation> valuations = GetValuations(session, account.Key, new DateTime[] { startDate.AddDays(-1), endDate }, true, ValuationTypesFilterOptions.All);
     IList<ISecurityValuationMutation> securityMutations = GetSecurityValuationMutations(session, account.Key, startDate, endDate);
     IList<IValuationCashMutation> cashMutations = GetValuationCashMutations(session, account.Key, startDate, endDate);
     IList<IDepositWithdrawal> depositsWithdrawals = GetDepositsWithdrawals(session, account.Key, startDate, endDate);
     IList<ValuationCashType> valuationCashTypes = GetValuationCashTypes(session);
     PortfolioDevelopment portDev = new PortfolioDevelopment(account, valuations, securityMutations, cashMutations, depositsWithdrawals, valuationCashTypes, startDate, endDate, modelID);
     return portDev;
 }
Ejemplo n.º 3
0
        // Makes a dataset with multiple datatables for all reports
        private static DataSet getQuarterReportDataSet(IDalSession session, bool portfolioDevelopment, bool portfolioOverview, bool transactionOverview,
            bool moneyMutations, ICustomerAccount account, DateTime beginDate, DateTime endDate)
        {
            int months = Util.DateDiff(DateInterval.Month, beginDate, endDate) + 1;
            DateTime[] monthDates = new DateTime[months];
            IInstrumentsCategories defaultInstrumentCategory = null;

            //Makes a datearray for 1 year for header graph
            for (int i = 0; i < months; i++)
            {
                monthDates[i] = Util.GetLastDayOfMonth(beginDate.AddMonths(i));
            }

            IList<IValuation> valuationsEndDate = ValuationMapper.GetValuations(session, account.Key, new DateTime[] { endDate });

            DataSet ds = new DataSet();
            ds.Tables.Add(getHeaderTable(account));

            // Model at the end of the period
            IModelHistory histModel = AccountMapper.GetHistoricalModel(session, account, endDate);
            DataTable dtModel = new IModelHistory[] { histModel }
                .Select(c => new
                {
                    ModelPortfolio_ModelName =
                        c.ModelPortfolio.ModelName
                })
                .ToDataTable("Model");
            ds.Tables.Add(dtModel);

            // Used for Plot Graph -> Portfolio Development
            DataTable dtTotalPortfolioValues = ValuationMapper.GetValuationsTotalPortfolio(session, account.Key, monthDates)
                .Select(c => new
                {
                    c.Date,
                    TotalValue_Quantity =
                        c.TotalValue.Quantity
                })
                .ToDataTable("TotalPortfolioValues");
            ds.Tables.Add(dtTotalPortfolioValues);

            // Used for Pie Chart -> Portfolio Asset Breakup
            PortfolioBreakUp breakUp = new PortfolioBreakUp(valuationsEndDate, endDate);
            PortfolioBreakUpDetail[] breakUpDetails = new PortfolioBreakUpDetail[breakUp.BreakUpDetails.Count];
            breakUp.BreakUpDetails.CopyTo(breakUpDetails, 0);
            DataTable dtPortfolioAssetClassBreakUp = breakUpDetails
                .Select(c => new
                {
                    AssetClass_AssetName =
                        c.AssetClass.AssetName,
                    BreakUpValue_Quantity =
                        c.BreakUpValue.Quantity,
                    c.BreakUpPercentage
                })
                .ToDataTable("PortfolioAssetClassBreakUp");
            ds.Tables.Add(dtPortfolioAssetClassBreakUp);

            if (portfolioDevelopment)
            {
                PortfolioDevelopment portfolioDev = ValuationMapper.GetPortfolioDevelopment(session, account, beginDate, endDate, histModel.ModelPortfolioKey);
                DataTable dtPortfolioDev = new PortfolioDevelopment[] { portfolioDev }
                    .Select(c => new
                    {
                        TotalValueBegin_Quantity =
                            c.TotalValueBegin.Quantity,
                        TotalValueEnd_Quantity =
                            c.TotalValueEnd.Quantity,
                        TotalValueDifference_Quantity =
                            c.TotalValueDifference.Quantity,
                        c.InvestmentReturnPercentage,
                        RealisedAmount_Quantity =
                            c.RealisedAmount.Quantity,
                        UnRealisedAmount_Quantity =
                            c.UnRealisedAmount.Quantity,
                        UnRealisedAmountPreviousPeriod_Quantity =
                            c.UnRealisedAmountPreviousPeriod.Quantity,
                        Withdrawals_Quantity =
                            c.Withdrawals.Quantity,
                        Deposits_Quantity =
                            c.Deposits.Quantity,
                        c.BenchMarkPerformance,
                        c.BenchMarkValue,
                        c.IBoxxTarget,
                        c.MSCIWorldTarget,
                        c.CompositeTarget
                    })
                    .ToDataTable("PortfolioDevelopment");
                ds.Tables.Add(dtPortfolioDev);

                PortfolioDevelopmentCash[] portCash = new PortfolioDevelopmentCash[portfolioDev.CashMovements.Count];
                portfolioDev.CashMovements.CopyTo(portCash, 0);
                DataTable dtPortfolioCashDev = portCash
                    .Select(c => new
                    {
                        c.ValuationCashTypeDescription,
                        Amount_Quantity =
                            c.Amount.Quantity,
                        c.IsIncome
                    })
                    .ToDataTable("PortfolioCashDevelopment");
                ds.Tables.Add(dtPortfolioCashDev);
            }

            if (portfolioOverview)
            {
                // get the default InstrumentCategory
                getDefaultInstrumentCategory(session, ref defaultInstrumentCategory);
                ValuationMutation.defaultInstrumentCategory = defaultInstrumentCategory;

                DataTable dtPortfolioOverview = ValuationMapper.GetValuationsPortfolioOverview(valuationsEndDate)
                    .Select(c => new
                    {
                        Instrument_IsCash =
                            c.Instrument.IsCash,
                        ValuationMutation_Position_AssetClass_Key =
                            c.AssetClass.Key,
                        ValuationMutation_Position_AssetClass_AssetName =
                            c.AssetClass.AssetName,
                        c.DisplayInstrumentsCategory,
                        Instrument_Name =
                            c.Instrument.Name,
                        CurrencyNominal_Symbol =
                            c.CurrencyNominal.Symbol,
                        CurrencyNominal_BaseCurrency_Symbol =
                            c.CurrencyNominal.BaseCurrency.Symbol,
                        Size_Quantity =
                            c.Size.Quantity,
                        CostPrice_DisplayQuantity =
                            c.CostPrice.DisplayQuantity,
                        BookValue_Quantity =
                            c.BookValue.Quantity,
                        MarketPrice_DisplayQuantity =
                            c.MarketPrice.DisplayQuantity,
                        BaseMarketValue_Quantity =
                            c.BaseMarketValue.Quantity,
                        UnRealisedAmountToDate_Quantity =
                            c.UnRealisedAmountToDate.Quantity
                    })
                    .ToDataTable("PortfolioOverview");
                ds.Tables.Add(dtPortfolioOverview);
                ValuationMutation.defaultInstrumentCategory = null;

                // get historical exrates
                ArrayList currencyList = new ArrayList();
                foreach (IValuation valuation in valuationsEndDate)
                {
                    if (!currencyList.Contains(valuation.CostPrice.Underlying))
                        currencyList.Add(valuation.CostPrice.Underlying);
                }
                ICurrency[] currencies = new ICurrency[currencyList.Count];
                currencyList.CopyTo(currencies, 0);
                DataTable dtHistoricalExchangeRates = HistoricalExRateMapper.GetHistoricalExRates(session, currencies, endDate)
                    .Select(c => new
                    {
                        Currency_Symbol =
                            c.Currency.Symbol,
                        c.Rate
                    })
                    .ToDataTable("HistoricalExchangeRates");
                ds.Tables.Add(dtHistoricalExchangeRates);
            }

            if (transactionOverview)
            {
                DataTable dtTransactionOverview = ValuationMapper.GetSecurityValuationMutations(session, account.Key, beginDate, endDate)
                    .Select(c => new
                    {
                        Position_AssetClass_Key =
                            c.Position.AssetClass.Key,
                        Position_AssetClass_AssetName =
                            c.Position.AssetClass.AssetName,
                        Instrument_Name =
                            c.Instrument.Name,
                        SizeChange_Quantity =
                            c.SizeChange.Quantity,
                        c.Date,
                        BookChange_Quantity =
                            c.BookChange.Quantity,
                        TotalBaseTradeAmount_Quantity =
                            c.TotalBaseTradeAmount.Quantity,
                        BaseRealisedAmount_Quantity =
                            c.BaseRealisedAmount.Quantity,
                        BaseCommission_Quantity =
                            c.BaseCommission.Quantity
                    })
                    .ToDataTable("TransactionOverview");
                ds.Tables.Add(dtTransactionOverview);
            }

            if (moneyMutations)
            {
                // cache the TransactionType descriptions
                ValuationMutation.defaultInstrumentCategory = defaultInstrumentCategory;

                //    AccountMapper.GetCashPositionTransactions(session, account, beginDate, endDate, false),
                //    "TransactionTypeID, ParentTransaction.TransactionTypeDescription, Description, TransactionDate, Amount.Quantity, Amount.Underlying.ToCurrency.AltSymbol, SideValue, " +
                //    "SizeQuantity, TradedInstrument.Name, PriceQuantity, PriceCurrency.AltSymbol, CommissionQuantity, CommissionCurrency.AltSymbol, ServiceChargeQuantity, ServiceChargeCurrency.AltSymbol, " +
                //    "ForeignCashMoneyOrderValueQuantity, ForeignCashMoneyOrderBaseValueQuantity, ForeignCashMoneyOrderCurrency.AltSymbol, ForeignCashMoneyOrderExRate, CashGeneratingInstrument.Name, TaxQuantity, FullDescription",
                List<ICashMutationView> lines = AccountMapper.GetCashPositionTransactions(session, account, beginDate, endDate, false);
                DataTable dtMoneyMutations = lines.Select(c => new
                {
                    Key =
                        c.Key,
                    c.Account.Number,
                    CashMutationViewTypeID =
                        (int)c.CashMutationViewType,
                    c.TypeID,
                    c.TypeDescription,
                    Description =
                        c.FullDescription,
                    c.TransactionDate,
                    BaseAmount =
                        c.Amount.BaseAmount.Quantity
                })
                .ToDataTable("MoneyMutations");
                ds.Tables.Add(dtMoneyMutations);

                // Get Cash Position startdate -1 (day before) & end date
                ICurrency baseCur = account.AccountOwner.StichtingDetails.BaseCurrency;
                IList moneyPositionStartAndEndDate = ValuationMapper.GetValuations(session, account.Key, baseCur.Key, new DateTime[] { beginDate.AddDays(-1), endDate }, true);

                DataTable dtMoneyPositionStartAndEndDate = new DataTable("MoneyPositionStartAndEndDate");
                dtMoneyPositionStartAndEndDate.Columns.Add("Date", typeof(DateTime));
                dtMoneyPositionStartAndEndDate.Columns.Add("Size_Quantity", typeof(decimal));
                decimal valStartDate = 0M;
                decimal valEndDate = 0M;
                foreach (IValuation val in moneyPositionStartAndEndDate)
                {
                    if (val.Date.Equals(beginDate.AddDays(-1)))
                        valStartDate = val.Size.Quantity;
                    else if (val.Date.Equals(endDate))
                        valEndDate = val.Size.Quantity;
                }
                Util.AddNewRowToDataTableWhenRecordNotExists(dtMoneyPositionStartAndEndDate, beginDate.AddDays(-1), valStartDate);
                Util.AddNewRowToDataTableWhenRecordNotExists(dtMoneyPositionStartAndEndDate, endDate, valEndDate);
                ds.Tables.Add(dtMoneyPositionStartAndEndDate);
            }

            return ds;
        }