Пример #1
0
 public NavSummaryViewModel(NavValuations navValuation, ITransferAgencyService investorService, IStaticReferences staticReferences)
 {
     _navValuation     = navValuation;
     _investorService  = investorService;
     _staticReferences = staticReferences;
     LockNavCommand    = new LockNavCommand(this, _navValuation, _investorService);
     UnlockNavCommand  = new UnlockNavCommand(this, _investorService);
 }
Пример #2
0
        public void CreateNavSummaryWindow(NavValuations navValuation)
        {
            Window view = new NavSummaryWindow();
            ViewModelWindowBase viewModel = new NavSummaryViewModel(navValuation, _investorService, _staticReferences);

            view = ApplyWindowAttributes(view, viewModel);
            view.ShowDialog();
        }
Пример #3
0
        public async Task LockNav(NavValuations navValuations)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                DateTime             asOfDate = navValuations.AsOfDate;
                int                  fundId   = navValuations.fund.FundId;
                AccountingPeriodsDIM period   = context.Periods.Where(p => p.FundId == fundId && p.AccountingDate == asOfDate).FirstOrDefault();
                period.isLocked = true;
                context.Entry(period).CurrentValues.SetValues(period);

                List <TransactionsBO> allTransactions;
                if (navValuations.fund.NAVFrequency == "Daily")
                {
                    allTransactions = navValuations.fund.Transactions.Where(t => t.TradeDate == asOfDate).ToList();
                }
                else
                {
                    allTransactions = navValuations.fund.Transactions.Where(t => t.TradeDate.Month == asOfDate.Month).ToList();
                }
                foreach (TransactionsBO transaction in allTransactions)
                {
                    transaction.isLocked = true;
                }
                context.Transactions.UpdateRange(allTransactions);

                NAVPriceStoreFACT newNavPrice = new NAVPriceStoreFACT
                {
                    FinalisedDate     = asOfDate,
                    Currency          = navValuations.fund.BaseCurrency,
                    FundId            = fundId,
                    NAVPeriodId       = period.PeriodId,
                    SharesOutstanding = navValuations.SharesOutstanding,
                    NetAssetValue     = navValuations.NetAssetValue,
                    NAVPrice          = navValuations.NetAssetValuePerShare,
                };
                context.NavPriceData.Add(newNavPrice);

                List <PositionFACT> newPositions = new List <PositionFACT>();
                foreach (ValuedSecurityPosition secPosition in navValuations.SecurityPositions)
                {
                    PositionFACT newPosition = new PositionFACT
                    {
                        PositionDate  = secPosition.AsOfDate,
                        SecurityId    = secPosition.Position.Security.SecurityId,
                        AssetClassId  = secPosition.Position.Security.AssetClassId,
                        FundId        = fundId,
                        AverageCost   = secPosition.Position.AverageCost,
                        CurrencyId    = secPosition.Position.Security.CurrencyId,
                        MarketValue   = secPosition.MarketValueBase,
                        Price         = secPosition.MarketPrice,
                        Quantity      = secPosition.Position.NetQuantity,
                        RealisedPnl   = secPosition.Position.RealisedPnL,
                        UnrealisedPnl = secPosition.UnrealisedPnl
                    };
                    newPositions.Add(newPosition);
                }
                foreach (ValuedCashPosition cashPosition in navValuations.CashPositions)
                {
                    string        currencySecSymbol = $"{cashPosition.CashPosition.Currency.Symbol}c";
                    SecuritiesDIM securitisedCash   = context.Securities.AsNoTracking().Where(s => s.Symbol == currencySecSymbol).Include(s => s.AssetClass).FirstOrDefault();

                    PositionFACT newPosition = new PositionFACT
                    {
                        PositionDate  = cashPosition.AsOfDate,
                        SecurityId    = securitisedCash.SecurityId,
                        AssetClassId  = securitisedCash.AssetClassId,
                        FundId        = fundId,
                        AverageCost   = 1,
                        CurrencyId    = cashPosition.CashPosition.Currency.CurrencyId,
                        MarketValue   = cashPosition.MarketValueBase,
                        Price         = cashPosition.fxRate,
                        Quantity      = cashPosition.CashPosition.NetQuantity,
                        RealisedPnl   = 0,
                        UnrealisedPnl = 0
                    };
                    newPositions.Add(newPosition);
                }

                await context.Positions.AddRangeAsync(newPositions);

                List <InvestorHoldingsFACT> newHoldings = new List <InvestorHoldingsFACT>();
                foreach (ClientHoldingValuation clientHolding in navValuations.ClientHoldings)
                {
                    InvestorHoldingsFACT newHolding = new InvestorHoldingsFACT
                    {
                        NetValuation          = clientHolding.NetValuation,
                        AverageCost           = clientHolding.Holding.AverageCost,
                        HighWaterMark         = clientHolding.Holding.Investor.HighWaterMark,
                        ManagementFeesAccrued = clientHolding.ManagementFeesAccrued,
                        Units = clientHolding.Holding.Units,
                        PerformanceFeesAccrued = clientHolding.PerformanceFeesAccrued,
                        HoldingDate            = asOfDate,
                        FundId     = fundId,
                        InvestorId = clientHolding.Holding.Investor.InvestorId
                    };
                    newHoldings.Add(newHolding);
                }
                await context.InvestorHoldings.AddRangeAsync(newHoldings);

                var pendingTAs = navValuations.fund.TransferAgent.Where(ta => !ta.IsNavFinal && ta.TransactionDate == asOfDate).ToList();
                foreach (var pendingTA in pendingTAs)
                {
                    SecuritiesDIM      security = context.Securities.AsNoTracking().Where(s => s.Symbol == $"{pendingTA.Currency}c").First();
                    int                secId    = security.SecurityId;
                    int                currId   = security.CurrencyId;
                    TransactionTypeDIM tradeType;
                    int                custodianId = context.Custodians.AsNoTracking().Where(c => c.Name == "Default").First().CustodianId; // FOR NOW TODO

                    if (pendingTA.IssueType == "Subscription")
                    {
                        //add tradeamount..
                        pendingTA.Units      = pendingTA.TradeAmount / navValuations.NetAssetValuePerShare;
                        pendingTA.NAVPrice   = navValuations.NetAssetValuePerShare;
                        pendingTA.IsNavFinal = true;
                        tradeType            = context.TransactionTypes.AsNoTracking().Where(tt => tt.TypeName == "Deposit").First();
                    }
                    else
                    {
                        pendingTA.TradeAmount = pendingTA.Units * navValuations.NetAssetValuePerShare;
                        pendingTA.NAVPrice    = navValuations.NetAssetValuePerShare;
                        pendingTA.IsNavFinal  = true;
                        tradeType             = context.TransactionTypes.AsNoTracking().Where(tt => tt.TypeName == "Withdrawal").First();
                        //reduce units..
                    }
                    // id need to create deposit and withdrawals here as well as save these updated TAs

                    // I need to set main custodian for a fund where all subs and reds initially go to.TODO
                    TransactionsBO newCashTrade = new TransactionsBO
                    {
                        SecurityId        = secId,
                        Quantity          = pendingTA.Units,
                        Price             = pendingTA.NAVPrice,
                        TradeAmount       = pendingTA.TradeAmount,
                        TradeDate         = pendingTA.TransactionDate,
                        SettleDate        = pendingTA.TransactionSettleDate,
                        CreatedDate       = DateTime.Now,
                        LastModified      = DateTime.Now,
                        Fees              = decimal.Zero,
                        isActive          = true,
                        isLocked          = true,
                        isCashTransaction = false,
                        FundId            = fundId,
                        TransactionTypeId = tradeType.TransactionTypeId,
                        CurrencyId        = currId,
                        Comment           = pendingTA.IssueType.ToUpper(),
                        CustodianId       = custodianId
                    };

                    context.Transactions.Add(newCashTrade);
                    context.TransferAgent.Update(pendingTA);
                }

                await context.SaveChangesAsync();

                // Lock all transactions with this trade Date... DONE
                // Add to Position SnapShot Fact Table... DONE
                // Lock Period... DONE
                // Update TransferAgent Fact Table.... DONE
                // NavPrices DONE
            }
        }
Пример #4
0
 public LockNavCommand(NavSummaryViewModel navValuationVM, NavValuations navValuation, ITransferAgencyService investorService)
 {
     _navValuation    = navValuation;
     _investorService = investorService;
     _navValuationVM  = navValuationVM;
 }