Exemplo n.º 1
0
 public Dictionary <string, ApplicationSettings> GetAllSettings()
 {
     using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
     {
         return(context.AppSettings.ToDictionary(s => s.SettingName));
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public PortfolioSeedDataFixture()
        {
            // The Database should have a different name each time..
            Action <DbContextOptionsBuilder> configureDbContext = db => db.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            PortfolioAceDbContextFactory factory = new PortfolioAceDbContextFactory(configureDbContext);

            PortfolioContext = factory.CreateDbContext();
            TestSeeds.SeedPortfolio(PortfolioContext);
        }
Exemplo n.º 4
0
 public List <PositionFACT> GetAllStoredPositions(DateTime date, int FundId, bool onlyActive = false)
 {
     using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
     {
         if (onlyActive)
         {
             return(context.Positions.Where(p => p.Quantity != 0 && p.FundId == FundId && p.PositionDate == date)
                    .AsNoTracking()
                    .Include(p => p.AssetClass)
                    .Include(p => p.Security)
                    .ToList());
         }
         else
         {
             return(context.Positions.Where(p => p.FundId == FundId && p.PositionDate == date)
                    .AsNoTracking()
                    .Include(p => p.AssetClass)
                    .Include(p => p.Security)
                    .ToList());
         }
     }
 }
Exemplo n.º 5
0
        public void DummyServiceTest3()
        {
            Action <DbContextOptionsBuilder> configureDbContext = db => db.UseInMemoryDatabase(databaseName: "DummyServiceTest3");
            PortfolioAceDbContextFactory     factory            = new PortfolioAceDbContextFactory(configureDbContext);

            using (PortfolioAceDbContext context = factory.CreateDbContext())
            {
                TestSeeds.SeedPortfolio(context);
            }
            IAdminService aService = new AdminService(factory);
            bool          res      = aService.SecurityExists("MSFT", "Cryptocurrency");

            Assert.False(res);
        }
Exemplo n.º 6
0
        public async Task AddImportedPrices(Dictionary <string, List <SecurityPriceStore> > newPrices)
        {
            /* Use the symbol (Key) to get a hashset of all the currently saved dates.
             * get all the prices from the list (Value) and check if they already exist in the hashset.
             * if they dont then add them.
             */
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                foreach (KeyValuePair <string, List <SecurityPriceStore> > kvp in newPrices)
                {
                    HashSet <DateTime> existingDates = context.SecurityPriceData.Where(spd => spd.Security.Symbol == kvp.Key).Select(spd => spd.Date).ToHashSet();
                    foreach (SecurityPriceStore price in kvp.Value)
                    {
                        if (!existingDates.Contains(price.Date))
                        {
                            existingDates.Add(price.Date);
                            context.SecurityPriceData.Add(price);
                        }
                    }
                }

                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _host.Start();
            System.Windows.FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false; // allows me to put negatives in textbox

            PortfolioAceDbContextFactory contextFactory = _host.Services.GetRequiredService <PortfolioAceDbContextFactory>();

            using (PortfolioAceDbContext context = contextFactory.CreateDbContext())
            {
                context.Database.Migrate();
            }

            Window window = _host.Services.GetRequiredService <MainWindow>();

            window.Show();
            base.OnStartup(e);
        }
Exemplo n.º 9
0
        public async Task <Fund> CreateFund(Fund fund)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <Fund> res = await context.Funds.AddAsync(fund);

                await context.SaveChangesAsync();

                // Once the fund has been created, I then create the accounting periods

                // set the monthly or daily account periods for up to one year ahead...
                DateTime        startDate = fund.LaunchDate;
                List <DateTime> allPeriods;
                if (fund.NAVFrequency == "Daily")
                {
                    // get daily dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualWorkingDays(startDate);
                }
                else
                {
                    // get month end dates from fund launch to a year ahead
                    allPeriods = DateSettings.AnnualMonthEnds(startDate);
                }
                // add all the dates to the new periods
                List <AccountingPeriodsDIM> initialPeriods = new List <AccountingPeriodsDIM>();
                foreach (DateTime period in allPeriods)
                {
                    AccountingPeriodsDIM newPeriod;
                    newPeriod = new AccountingPeriodsDIM {
                        AccountingDate = period.Date, isLocked = false, FundId = fund.FundId
                    };
                    initialPeriods.Add(newPeriod);
                }
                context.Periods.AddRange(initialPeriods);
                await context.SaveChangesAsync();

                return(res.Entity);
            }
        }
Exemplo n.º 10
0
        public async Task <InvestorsDIM> CreateInvestor(InvestorsDIM investor)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                EntityEntry <InvestorsDIM> res = await context.Investors.AddAsync(investor);

                await context.SaveChangesAsync();

                return(res.Entity);
            }
        }
Exemplo n.º 11
0
 public List <AssetClassDIM> GetAllAssetClasses()
 {
     using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
     {
         return(context.AssetClasses.AsNoTracking().ToList());
     }
 }
Exemplo n.º 12
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);
            }
        }