Ejemplo n.º 1
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                SecuritiesDIM security = _priceService.GetSecurityInfo(_sysSecurityPricesVM.SelectedSecurity.Symbol, _sysSecurityPricesVM.SelectedSecurity.AssetClass.Name);
                var           results  = await _priceService.AddDailyPrices(security);

                if (results > 0)
                {
                    MessageBox.Show($"{results} prices have been saved for {_sysSecurityPricesVM.SelectedSecurity.SecurityName}", "Information");
                    await _sysSecurityPricesVM.Load();
                }
                else
                {
                    MessageBox.Show($"No new prices found for {_sysSecurityPricesVM.SelectedSecurity.SecurityName}", "Information");
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Your API Key might not be valid. Please investigate", "Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 2
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                if (_importVM.dgCSVSecurities.Count != 0)
                {
                    Dictionary <string, int> assetClassMap = _importService.AssetClassMap();
                    Dictionary <string, int> currencyMap   = _importService.CurrencyMap();

                    List <SecuritiesDIM> newSecurities = new List <SecuritiesDIM>();
                    foreach (SecurityImportDataCSV data in _importVM.dgCSVSecurities)
                    {
                        SecuritiesDIM newSecurity = new SecuritiesDIM
                        {
                            AssetClassId       = assetClassMap[data.AssetClass],
                            CurrencyId         = currencyMap[data.Currency],
                            SecurityName       = data.Name,
                            FMPSymbol          = data.FMPSymbol,
                            ISIN               = data.ISIN,
                            Symbol             = data.Symbol,
                            AlphaVantageSymbol = data.AVSymbol
                        };
                        newSecurities.Add(newSecurity);
                    }

                    await _importService.AddImportedSecurities(newSecurities);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 3
0
 public async Task UpdateSecurityInfo(SecuritiesDIM security)
 {
     using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
     {
         context.Securities.Update(security);
         await context.SaveChangesAsync();
     }
 }
Ejemplo n.º 4
0
 public async Task DeleteSecurityInfo(string symbol)
 {
     using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
     {
         SecuritiesDIM security = context.Securities.Where(s => s.Symbol == symbol).FirstOrDefault();
         context.Securities.Remove(security);
         await context.SaveChangesAsync();
     }
 }
 public EquityPosition(SecuritiesDIM security, CustodiansDIM custodian)
 {
     this.Security      = security;
     this.Custodian     = custodian;
     _averageCost       = 0;
     _netQuantity       = 0;
     _realisedPnL       = 0;
     _positionBreakdown = new List <PositionSnapshot>();
     _openLots          = new Queue <TaxLotsOpen>();
 }
Ejemplo n.º 6
0
        public async Task <SecuritiesDIM> AddSecurityInfo(SecuritiesDIM security)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <SecuritiesDIM> res = await context.Securities.AddAsync(security);

                await context.SaveChangesAsync();

                return(res.Entity);
            }
        }
Ejemplo n.º 7
0
 public void ChangeAssetClassCommand()
 {
     _securitiesList = _allSecuritiesList.Where(s => s.AssetClass.Name == AssetClass).ToList();
     if (_securitiesList.Count > 0)
     {
         _SelectedSecurity = _securitiesList[0];
         OnPropertyChanged(nameof(SelectedSecurity));
         Load();
         OnPropertyChanged(nameof(dgSecurityPrices));
     }
     OnPropertyChanged(nameof(SecuritiesList));
 }
Ejemplo n.º 8
0
        public override async Task ExecuteAsync(object parameter)
        {
            if (string.IsNullOrWhiteSpace(_SecurityManagerVM.SecurityName) || string.IsNullOrWhiteSpace(_SecurityManagerVM.SecuritySymbol))
            {
                throw new ArgumentException("You must provide a security name and symbol");
            }
            // currency and asset class objects
            CurrenciesDIM currency   = _staticReferences.GetCurrency(_SecurityManagerVM.Currency);
            AssetClassDIM assetClass = _staticReferences.GetAssetClass(_SecurityManagerVM.AssetClass);

            try
            {
                SecuritiesDIM newSecurity = new SecuritiesDIM
                {
                    AssetClassId       = assetClass.AssetClassId,
                    Symbol             = _SecurityManagerVM.SecuritySymbol,
                    CurrencyId         = currency.CurrencyId,
                    SecurityName       = _SecurityManagerVM.SecurityName,
                    AlphaVantageSymbol = _SecurityManagerVM.AVSymbol,
                    FMPSymbol          = _SecurityManagerVM.FMPSymbol,
                    ISIN = _SecurityManagerVM.ISIN
                };
                var savedSecurity = await _adminService.AddSecurityInfo(newSecurity);

                if (savedSecurity.SecurityId != 0)
                {
                    MessageBox.Show($"{_SecurityManagerVM.SecurityName} has been saved.");
                    _SecurityManagerVM.ResetValues();
                }
                else
                {
                    MessageBox.Show($"ERROR INVNOTSAVED");
                    _SecurityManagerVM.CloseAction();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        private string GenerateURI(SecuritiesDIM security)
        {
            string assetClass = security.AssetClass.Name;
            string symbol     = security.AlphaVantageSymbol;
            string uri;

            if (assetClass == "FX")
            {
                string from_symbol = symbol.Substring(0, 3);
                string to_symbol   = symbol.Substring(3);
                uri = $"function=FX_DAILY&from_symbol={from_symbol}&to_symbol={to_symbol}";
            }
            else if (assetClass == "Cryptocurrency")
            {
                // This isnt perfect yet I need to figure out how to deserialise the ClosePrice
                uri = $"function=DIGITAL_CURRENCY_DAILY&symbol={symbol}&market=USD";
            }
            else
            {
                uri = $"function=TIME_SERIES_DAILY&symbol={symbol}";
            }
            return(uri);
        }
        public async Task <IEnumerable <AVSecurityPriceData> > GetPricesAsync(SecuritiesDIM security)
        {
            string uri        = GenerateURI(security);
            string connection = $"{BASE_ADDRESS_QUERY}/query?apikey={_apiKeyAV}&{uri}&datatype=csv";
            string response   = await connection.GetStringFromUrlAsync();

            string assetClass = security.AssetClass.Name;
            IEnumerable <AVSecurityPriceData> result;

            if (assetClass == "Cryptocurrency")
            {
                result = response.FromCsv <List <AVCryptoPriceData> >();
            }
            else if (assetClass == "FX")
            {
                result = response.FromCsv <List <AVFXPriceData> >();
            }
            else
            {
                result = response.FromCsv <List <AVEquityPriceData> >();
            }
            return(result);
        }
Ejemplo n.º 11
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                // cash symbol would be something like EURc name = EUR CASH
                SecuritiesDIM      security     = _transactionService.GetSecurityInfo(_addCashTradeWindowVM.Symbol);
                TransactionTypeDIM tradeType    = _transactionService.GetTradeType(_addCashTradeWindowVM.CashType);
                CustodiansDIM      custodian    = _transactionService.GetCustodian(_addCashTradeWindowVM.Custodian);
                TransactionsBO     newCashTrade = new TransactionsBO
                {
                    SecurityId        = security.SecurityId,
                    Quantity          = _addCashTradeWindowVM.Quantity,
                    Price             = _addCashTradeWindowVM.Price,
                    TradeAmount       = _addCashTradeWindowVM.CashAmount,
                    TradeDate         = _addCashTradeWindowVM.TradeDate,
                    SettleDate        = _addCashTradeWindowVM.SettleDate,
                    CreatedDate       = _addCashTradeWindowVM.CreatedDate,
                    LastModified      = _addCashTradeWindowVM.LastModifiedDate,
                    Fees              = _addCashTradeWindowVM.Fees,
                    isActive          = _addCashTradeWindowVM.isActive,
                    isLocked          = _addCashTradeWindowVM.isLocked,
                    isCashTransaction = true,
                    FundId            = _addCashTradeWindowVM.FundId,
                    TransactionTypeId = tradeType.TransactionTypeId,
                    CurrencyId        = security.CurrencyId,
                    Comment           = _addCashTradeWindowVM.Notes,
                    CustodianId       = custodian.CustodianId
                };
                await _transactionService.CreateTransaction(newCashTrade);

                _addCashTradeWindowVM.CloseAction();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 12
0
        public async Task <int> AddDailyPrices(SecuritiesDIM security)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                string avKey = context.AppSettings.Where(ap => ap.SettingName == "AlphaVantageAPI").First().SettingValue;
                AlphaVantageConnection            avConn    = _dataFactory.CreateAlphaVantageClient(avKey);
                IEnumerable <AVSecurityPriceData> allPrices = await avConn.GetPricesAsync(security);

                HashSet <DateTime> existingDates = context.SecurityPriceData.Where(spd => spd.Security.Symbol == security.Symbol).Select(spd => spd.Date).ToHashSet();
                string             assetClass    = security.AssetClass.Name;
                int pricesSaved = 0;
                foreach (AVSecurityPriceData price in allPrices)
                {
                    if (!existingDates.Contains(price.TimeStamp))
                    {
                        // i should the indirect quote therefore i inverse the price here...
                        if (assetClass == "FX")
                        {
                            price.Close = 1 / price.Close;
                        }
                        if (security.Currency.Symbol == "GBP" && assetClass != "FX")
                        {
                            price.Close /= 100;
                        }
                        SecurityPriceStore newPrice = new SecurityPriceStore {
                            Date = price.TimeStamp, ClosePrice = price.Close, SecurityId = security.SecurityId, PriceSource = price.PriceSource
                        };
                        context.SecurityPriceData.Add(newPrice);
                        pricesSaved += 1;
                    }
                }
                await context.SaveChangesAsync();

                return(pricesSaved);
            }
        }
Ejemplo n.º 13
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
            }
        }
Ejemplo n.º 14
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                if (_fundInitialiseVM.dgSeedingInvestors.Count == 0)
                {
                    throw new ArgumentException("Your fund must have initial investors.");
                }
                if (_fundInitialiseVM.dgSeedingInvestors.Count != _fundInitialiseVM.dgSeedingInvestors.ToHashSet().Count)
                {
                    throw new ArgumentException("You must net an investors seed capital.");
                }

                Fund updateFund = _fundInitialiseVM.TargetFund;
                updateFund.IsInitialised = true;

                string             cashSymbol = $"{updateFund.BaseCurrency}c";
                SecuritiesDIM      security   = _staticReferences.GetSecurityInfo(cashSymbol);
                TransactionTypeDIM tradeType  = _staticReferences.GetTransactionType("Deposit");
                CustodiansDIM      custodian  = _staticReferences.GetCustodian(_fundInitialiseVM.Custodian);

                List <TransferAgencyBO>     subscriptions    = new List <TransferAgencyBO>();
                List <TransactionsBO>       transactions     = new List <TransactionsBO>();
                List <FundInvestorBO>       fundInvestors    = new List <FundInvestorBO>();
                List <InvestorHoldingsFACT> investorHoldings = new List <InvestorHoldingsFACT>();

                foreach (SeedingInvestor seedInvestor in _fundInitialiseVM.dgSeedingInvestors)
                {
                    if (seedInvestor.SeedAmount >= updateFund.MinimumInvestment)
                    {
                        FundInvestorBO fundInvestor = new FundInvestorBO
                        {
                            InceptionDate = updateFund.LaunchDate,
                            FundId        = updateFund.FundId,
                            InvestorId    = seedInvestor.InvestorId
                        };
                        // The highwatermark is only applicable if the fund has a highwatermark...
                        fundInvestor.HighWaterMark = (updateFund.HasHighWaterMark) ? _fundInitialiseVM.NavPrice : (decimal?)null;
                        fundInvestors.Add(fundInvestor);

                        InvestorHoldingsFACT investor = new InvestorHoldingsFACT
                        {
                            ManagementFeesAccrued  = decimal.Zero,
                            PerformanceFeesAccrued = decimal.Zero,
                            FundId       = updateFund.FundId,
                            HoldingDate  = updateFund.LaunchDate,
                            InvestorId   = seedInvestor.InvestorId,
                            AverageCost  = _fundInitialiseVM.NavPrice,
                            Units        = seedInvestor.SeedAmount / _fundInitialiseVM.NavPrice,
                            NetValuation = seedInvestor.SeedAmount,
                        };
                        investor.HighWaterMark = (updateFund.HasHighWaterMark) ? _fundInitialiseVM.NavPrice : (decimal?)null;
                        investorHoldings.Add(investor);
                        // hwm
                        TransferAgencyBO newSubscription = new TransferAgencyBO
                        {
                            TradeAmount           = seedInvestor.SeedAmount,
                            NAVPrice              = _fundInitialiseVM.NavPrice,
                            TransactionDate       = updateFund.LaunchDate,
                            TransactionSettleDate = updateFund.LaunchDate,
                            Currency              = updateFund.BaseCurrency,
                            FundId       = updateFund.FundId,
                            Fees         = 0,
                            IssueType    = "Subscription",
                            Units        = seedInvestor.SeedAmount / _fundInitialiseVM.NavPrice,
                            IsNavFinal   = true,
                            FundInvestor = fundInvestor
                        };
                        subscriptions.Add(newSubscription);
                        TransactionsBO newTransaction = new TransactionsBO
                        {
                            SecurityId        = security.SecurityId,
                            Quantity          = seedInvestor.SeedAmount,
                            Price             = decimal.One,
                            TradeAmount       = seedInvestor.SeedAmount,
                            TradeDate         = updateFund.LaunchDate,
                            SettleDate        = updateFund.LaunchDate,
                            CreatedDate       = DateTime.Now,
                            LastModified      = DateTime.Now,
                            Fees              = decimal.Zero,
                            isActive          = true,
                            isLocked          = true,
                            isCashTransaction = false,
                            FundId            = updateFund.FundId,
                            TransactionTypeId = tradeType.TransactionTypeId,
                            CurrencyId        = security.CurrencyId,
                            Comment           = "Initial Subscription",
                            CustodianId       = custodian.CustodianId
                        };
                        transactions.Add(newTransaction);
                    }
                    else
                    {
                        throw new ArgumentException("The seed amount must be greater than the Funds minimum investment");
                    }
                }

                int PeriodId = _staticReferences.GetPeriod(updateFund.LaunchDate, updateFund.FundId).PeriodId;
                NAVPriceStoreFACT initialNav = new NAVPriceStoreFACT
                {
                    FinalisedDate     = updateFund.LaunchDate,
                    NAVPrice          = _fundInitialiseVM.NavPrice,
                    FundId            = updateFund.FundId,
                    NetAssetValue     = subscriptions.Sum(ni => ni.TradeAmount),
                    SharesOutstanding = subscriptions.Sum(ni => ni.Units),
                    Currency          = updateFund.BaseCurrency,
                    NAVPeriodId       = PeriodId
                };
                await _investorService.InitialiseFundAction(updateFund, subscriptions, transactions, initialNav, fundInvestors, investorHoldings);

                _fundInitialiseVM.CloseAction();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 15
0
        public async Task <TransactionsBO> CreateFXTransaction(ForexDTO fxTransaction)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                SecuritiesDIM fxSecurity = context.Securities.AsNoTracking().Where(s => s.Symbol == fxTransaction.Symbol).FirstOrDefault();
                AssetClassDIM assetClass = context.AssetClasses.AsNoTracking().Where(a => a.Name == "FXForward").FirstOrDefault();
                CustodiansDIM custodian  = context.Custodians.AsNoTracking().Where(c => c.Name == fxTransaction.Custodian).FirstOrDefault();
                IEnumerable <TransactionTypeDIM> transactionTypes = context.TransactionTypes;
                List <CurrenciesDIM>             currencies       = context.Currencies.AsNoTracking().ToList();

                CurrenciesDIM buyCurrency  = context.Currencies.AsNoTracking().Where(c => c.Symbol == fxTransaction.BuyCurrency).First();
                CurrenciesDIM sellCurrency = context.Currencies.AsNoTracking().Where(c => c.Symbol == fxTransaction.SellCurrency).First();
                if (fxSecurity == null)
                {
                    fxSecurity = new SecuritiesDIM
                    {
                        AssetClassId = assetClass.AssetClassId,
                        CurrencyId   = buyCurrency.CurrencyId,
                        SecurityName = fxTransaction.Name,
                        Symbol       = fxTransaction.Symbol
                    };
                    context.Securities.Add(fxSecurity);
                }
                // Created LinkedTransactions Here
                LinkedTradesBO linkReference  = new LinkedTradesBO();
                TransactionsBO refTransaction = new TransactionsBO
                {
                    Security          = fxSecurity,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = 0,
                    Price             = fxTransaction.Price,
                    Quantity          = fxTransaction.BuyAmount,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXTrade").First().TransactionTypeId,
                    Comment           = "",
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.TradeDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                TransactionsBO refTransactionCollapse = new TransactionsBO
                {
                    Security          = fxSecurity,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = 0,
                    Price             = fxTransaction.Price,
                    Quantity          = fxTransaction.BuyAmount * -1,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXTradeCollapse").First().TransactionTypeId,
                    Comment           = "",
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                EntityEntry <TransactionsBO> res = await context.Transactions.AddAsync(refTransaction);

                context.Transactions.Add(refTransactionCollapse);

                SecuritiesDIM fxBuySecurity  = context.Securities.AsNoTracking().Where(s => s.Symbol == $"{fxTransaction.BuyCurrency}c").FirstOrDefault();
                SecuritiesDIM fxSellSecurity = context.Securities.AsNoTracking().Where(s => s.Symbol == $"{fxTransaction.SellCurrency}c").FirstOrDefault();

                TransactionsBO fxBuyLegCash = new TransactionsBO
                {
                    SecurityId        = fxBuySecurity.SecurityId,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = fxTransaction.BuyAmount,
                    Price             = 1,
                    Quantity          = fxTransaction.BuyAmount,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXBuy").First().TransactionTypeId,
                    Comment           = fxTransaction.Description,
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                TransactionsBO fxSellLegCash = new TransactionsBO
                {
                    SecurityId        = fxSellSecurity.SecurityId,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = fxTransaction.SellAmount,
                    Price             = 1,
                    Quantity          = fxTransaction.SellAmount,
                    CurrencyId        = sellCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXSell").First().TransactionTypeId,
                    Comment           = fxTransaction.Description,
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                context.Transactions.Add(fxBuyLegCash);
                context.Transactions.Add(fxSellLegCash);

                await context.SaveChangesAsync();

                return(refTransaction);
            }
        }
Ejemplo n.º 16
0
        public static void SeedPortfolio(PortfolioAceDbContext context)
        {
            CurrenciesDIM[] SeedCurrencies = new CurrenciesDIM[]
            {
                new CurrenciesDIM {
                    CurrencyId = 1, Name = "PoundSterling", Symbol = "GBP"
                },
                new CurrenciesDIM {
                    CurrencyId = 2, Name = "Euro", Symbol = "EUR"
                },
                new CurrenciesDIM {
                    CurrencyId = 3, Name = "UnitedStatesDollar", Symbol = "USD"
                },
                new CurrenciesDIM {
                    CurrencyId = 4, Name = "JapaneseYen", Symbol = "JPY"
                },
                new CurrenciesDIM {
                    CurrencyId = 5, Name = "IndianRupee", Symbol = "INR"
                },
                new CurrenciesDIM {
                    CurrencyId = 6, Name = "SwissFranc", Symbol = "CHF"
                },
                new CurrenciesDIM {
                    CurrencyId = 7, Name = "CanadianDollar", Symbol = "CAD"
                },
                new CurrenciesDIM {
                    CurrencyId = 8, Name = "AustralianDollar", Symbol = "AUD"
                }
            };

            TransactionTypeDIM[] SeedTransactionTypes = new TransactionTypeDIM[]
            {
                new TransactionTypeDIM {
                    TransactionTypeId = 1, TypeName = "Trade", TypeClass = "SecurityTrade", Direction = "None"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 2, TypeName = "Dividends", TypeClass = "SecurityTrade", Direction = "None"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 3, TypeName = "Income", TypeClass = "CashTrade", Direction = "Inflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 4, TypeName = "Expense", TypeClass = "CashTrade", Direction = "Outflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 5, TypeName = "Deposit", TypeClass = "CashTrade", Direction = "Inflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 6, TypeName = "Withdrawal", TypeClass = "CashTrade", Direction = "Outflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 7, TypeName = "Interest", TypeClass = "CashTrade", Direction = "None"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 8, TypeName = "ManagementFee", TypeClass = "CashTrade", Direction = "Outflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 9, TypeName = "PerformanceFee", TypeClass = "CashTrade", Direction = "Outflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 10, TypeName = "Miscellaneous", TypeClass = "CashTrade", Direction = "None"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 11, TypeName = "FXBuy", TypeClass = "CashTrade", Direction = "Inflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 12, TypeName = "FXSell", TypeClass = "CashTrade", Direction = "Outflow"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 13, TypeName = "FXTrade", TypeClass = "FXTrade", Direction = "None"
                },
                new TransactionTypeDIM {
                    TransactionTypeId = 14, TypeName = "FXTradeCollapse", TypeClass = "FXTrade", Direction = "None"
                }
            };

            AssetClassDIM[] SeedAssetClasses = new AssetClassDIM[]
            {
                new AssetClassDIM {
                    AssetClassId = 1, Name = "Equity"
                },
                new AssetClassDIM {
                    AssetClassId = 2, Name = "Cryptocurrency"
                },
                new AssetClassDIM {
                    AssetClassId = 3, Name = "FX"
                },
                new AssetClassDIM {
                    AssetClassId = 4, Name = "Cash"
                },
                new AssetClassDIM {
                    AssetClassId = 5, Name = "InterestRate"
                },
                new AssetClassDIM {
                    AssetClassId = 6, Name = "FXForward"
                },
            };

            SecuritiesDIM[] seedSecurities = new SecuritiesDIM[]
            {
                new SecuritiesDIM {
                    SecurityId = 1, SecurityName = "CASH GBP", Symbol = "GBPc", AssetClassId = 4, CurrencyId = 1
                },
                new SecuritiesDIM {
                    SecurityId = 2, SecurityName = "CASH EURO", Symbol = "EURc", AssetClassId = 4, CurrencyId = 2
                },
                new SecuritiesDIM {
                    SecurityId = 3, SecurityName = "CASH USD", Symbol = "USDc", AssetClassId = 4, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 4, SecurityName = "CASH JPY", Symbol = "JPYc", AssetClassId = 4, CurrencyId = 4
                },
                new SecuritiesDIM {
                    SecurityId = 5, SecurityName = "CASH INR", Symbol = "INRc", AssetClassId = 4, CurrencyId = 5
                },
                new SecuritiesDIM {
                    SecurityId = 6, SecurityName = "CASH CHF", Symbol = "CHFc", AssetClassId = 4, CurrencyId = 6
                },
                new SecuritiesDIM {
                    SecurityId = 7, SecurityName = "CASH CAD", Symbol = "CADc", AssetClassId = 4, CurrencyId = 7
                },
                new SecuritiesDIM {
                    SecurityId = 8, SecurityName = "CASH AUD", Symbol = "AUDc", AssetClassId = 4, CurrencyId = 8
                },
                new SecuritiesDIM {
                    SecurityId = 9, SecurityName = "BOE Base Rate", Symbol = "GBP_IRBASE", AssetClassId = 5, CurrencyId = 1
                },
                new SecuritiesDIM {
                    SecurityId = 10, SecurityName = "ECB Main Refinancing Rate", Symbol = "EUR_IRBASE", AssetClassId = 5, CurrencyId = 2
                },
                new SecuritiesDIM {
                    SecurityId = 11, SecurityName = "Federal Funds Rate", Symbol = "USD_IRBASE", AssetClassId = 5, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 12, SecurityName = "BOJ Mutan Rate", Symbol = "JPY_IRBASE", AssetClassId = 5, CurrencyId = 4
                },
                new SecuritiesDIM {
                    SecurityId = 13, SecurityName = "BOI Repurchase Rate", Symbol = "INR_IRBASE", AssetClassId = 5, CurrencyId = 5
                },
                new SecuritiesDIM {
                    SecurityId = 14, SecurityName = "SNB Policy Rate", Symbol = "CHF_IRBASE", AssetClassId = 5, CurrencyId = 6
                },
                new SecuritiesDIM {
                    SecurityId = 15, SecurityName = "BOC Policy Rate", Symbol = "CAD_IRBASE", AssetClassId = 5, CurrencyId = 7
                },
                new SecuritiesDIM {
                    SecurityId = 16, SecurityName = "RBA Cash Rate Target", Symbol = "AUD_IRBASE", AssetClassId = 5, CurrencyId = 8
                },
                new SecuritiesDIM {
                    SecurityId = 17, SecurityName = "Apple", Symbol = "AAPL", AssetClassId = 1, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 18, SecurityName = "Microsoft Corporation", Symbol = "MSFT", AssetClassId = 1, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 19, SecurityName = "Advanced Micro Devices", Symbol = "AMD", AssetClassId = 1, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 20, SecurityName = "Bitcoin", Symbol = "BTC", AssetClassId = 2, CurrencyId = 3
                },
                new SecuritiesDIM {
                    SecurityId = 21, SecurityName = "FX FWD USD/GBP 03/12/20", Symbol = "USDGBP031220", AssetClassId = 6, CurrencyId = 3
                }
            };

            NavFrequencyDIM[] SeedNavFrequencies = new NavFrequencyDIM[]
            {
                new NavFrequencyDIM {
                    NavFrequencyId = 1, Frequency = "Daily"
                },
                new NavFrequencyDIM {
                    NavFrequencyId = 2, Frequency = "Monthly"
                }
            };

            IssueTypesDIM[] SeedIssueTypes = new IssueTypesDIM[]
            {
                new IssueTypesDIM {
                    IssueTypeID = 1, TypeName = "Subscription"
                },
                new IssueTypesDIM {
                    IssueTypeID = 2, TypeName = "Redemption"
                }
            };

            CustodiansDIM[] SeedCustodians = new CustodiansDIM[]
            {
                new CustodiansDIM {
                    CustodianId = 1, Name = "Default", Symbol = "Default"
                }
            };

            context.Currencies.AddRange(SeedCurrencies);
            context.TransactionTypes.AddRange(SeedTransactionTypes);
            context.AssetClasses.AddRange(SeedAssetClasses);
            context.Securities.AddRange(seedSecurities);
            context.NavFrequencies.AddRange(SeedNavFrequencies);
            context.IssueTypes.AddRange(SeedIssueTypes);
            context.Custodians.AddRange(SeedCustodians);
            context.SaveChanges();
        }