Exemplo n.º 1
0
        public List <CalculatedCashPosition> GetAllCashPositions(Fund fund, DateTime asOfDate)
        {
            List <TransactionsBO> allTrades = fund.Transactions
                                              .Where(t => t.TradeDate <= asOfDate && t.isActive)
                                              .OrderBy(t => t.TradeDate)
                                              .ToList();
            Dictionary <(string, string), List <TransactionsBO> > cashTradesByCurrencyAndCustodian = new Dictionary <(string, string), List <TransactionsBO> >();

            foreach (TransactionsBO trade in allTrades)
            {
                ValueTuple <string, string> groupKey = (trade.Currency.Symbol, trade.Custodian.Name); // this allows me to group transactions by security AND custodian
                if (!cashTradesByCurrencyAndCustodian.ContainsKey(groupKey))
                {
                    cashTradesByCurrencyAndCustodian[groupKey] = new List <TransactionsBO> {
                        trade
                    };
                }
                else
                {
                    cashTradesByCurrencyAndCustodian[groupKey].Add(trade);
                }
            }

            List <CalculatedCashPosition> allCashPositions = new List <CalculatedCashPosition>();

            foreach (KeyValuePair <(string, string), List <TransactionsBO> > Kvp in cashTradesByCurrencyAndCustodian)
            {
                CurrenciesDIM          currency  = Kvp.Value[0].Currency;
                CustodiansDIM          custodian = Kvp.Value[0].Custodian;
                CalculatedCashPosition balance   = _positionFactory.CreateCashPosition(currency, custodian);
                balance.AddTransactionRange(Kvp.Value);
                allCashPositions.Add(balance);
            }
            return(allCashPositions);
        }
 public LiquidCashPosition(CurrenciesDIM currency, CustodiansDIM custodian)
 {
     this.Currency  = currency;
     this.Custodian = custodian;
     this._balance  = decimal.Zero;
     _asOfDate      = DateTime.MinValue;
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 public CalculatedCashPosition CreateCashPosition(CurrenciesDIM currency, CustodiansDIM custodian)
 {
     return(new LiquidCashPosition(currency, custodian));
 }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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();
        }