public void GetValueWeekly() { var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 01, 17)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioValueService(portfolio, PortfolioTestCreator.TradingCalendar); var result = service.GetValue(dateRange, ValueFrequency.Week); result.Result.Should().BeEquivalentTo(new { Values = new[] { new ClosingPrice() { Date = new Date(2000, 01, 02), Price = 9960.10m }, new ClosingPrice() { Date = new Date(2000, 01, 09), Price = 9963.10m }, new ClosingPrice() { Date = new Date(2000, 01, 16), Price = 9975.10m }, new ClosingPrice() { Date = new Date(2000, 01, 17), Price = 9982.10m } } }); }
public void GetHoldingsInDateRange() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioHoldingService(portfolio); var result = service.GetHoldings(new DateRange(new Date(2000, 01, 01), new Date(2003, 01, 01))); result.Result.Should().BeEquivalentTo(new[] { new RestApi.Portfolios.Holding() { Stock = PortfolioTestCreator.Stock_ARG, Units = 200, Value = 198.00m, Cost = 239.90m, CostBase = 239.90m, }, new RestApi.Portfolios.Holding() { Stock = PortfolioTestCreator.Stock_WAM, Units = 200, Value = 254.00m, Cost = 259.95m, CostBase = 259.95m, } }); }
public void GetValueForStockWeekly() { var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 01, 17)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioValueService(portfolio, PortfolioTestCreator.TradingCalendar); var result = service.GetValue(PortfolioTestCreator.Stock_ARG.Id, dateRange, ValueFrequency.Week); result.Result.Should().BeEquivalentTo(new { Values = new[] { new ClosingPrice() { Date = new Date(2000, 01, 02), Price = 100.00m }, new ClosingPrice() { Date = new Date(2000, 01, 09), Price = 101.00m }, new ClosingPrice() { Date = new Date(2000, 01, 16), Price = 107.00m }, new ClosingPrice() { Date = new Date(2000, 01, 17), Price = 108.00m } } }); }
public void ApplyCostBaseAdjustment() { var mockRepository = new MockRepository(MockBehavior.Strict); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var events = new List <Event>(); var repository = mockRepository.Create <IRepository <Portfolio> >(); repository.Setup(x => x.Update(It.IsAny <Portfolio>())).Callback <Portfolio>(x => events.AddRange(x.FetchEvents())); var service = new PortfolioTransactionService(portfolio, repository.Object); var transaction = new CostBaseAdjustment() { Id = Guid.NewGuid(), Stock = PortfolioTestCreator.Stock_ARG.Id, TransactionDate = new Date(2007, 01, 01), Comment = "", Percentage = 0.50m }; var result = service.ApplyTransaction(transaction); result.Should().HaveOkStatus(); events.Should().BeEquivalentTo(new[] { new CostBaseAdjustmentOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "") { Percentage = 0.50m } }); mockRepository.Verify(); }
public void GetIncome() { var dateRange = new DateRange(new Date(2001, 01, 01), new Date(2010, 01, 01)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioIncomeService(portfolio); var result = service.GetIncome(dateRange); result.Result.Should().BeEquivalentTo(new { Income = new[] { new IncomeResponse.IncomeItem() { Stock = PortfolioTestCreator.Stock_ARG, UnfrankedAmount = 20.00m, FrankedAmount = 120.00m, FrankingCredits = 4.00m, NetIncome = 140.00m, GrossIncome = 144.00m }, new IncomeResponse.IncomeItem() { Stock = PortfolioTestCreator.Stock_WAM, UnfrankedAmount = 3.00m, FrankedAmount = 30.00m, FrankingCredits = 2.00m, NetIncome = 33.00m, GrossIncome = 35.00m } } }); }
public void GetProperties() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); portfolio.ChangeDrpParticipation(PortfolioTestCreator.Stock_WAM.Id, true); var service = new PortfolioPropertiesService(portfolio); var result = service.GetProperties(); result.Result.Should().BeEquivalentTo(new { Id = portfolio.Id, Name = "Test", StartDate = new Date(2000, 01, 01), EndDate = Date.MaxValue, Holdings = new[] { new RestApi.Portfolios.HoldingProperties() { Stock = PortfolioTestCreator.Stock_ARG, StartDate = new Date(2000, 01, 01), EndDate = Date.MaxValue, ParticipatingInDrp = false }, new RestApi.Portfolios.HoldingProperties() { Stock = PortfolioTestCreator.Stock_WAM, StartDate = new Date(2000, 01, 01), EndDate = Date.MaxValue, ParticipatingInDrp = true } } }); }
public void GetHoldingAtDateStockNotFound() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioHoldingService(portfolio); var result = service.GetHolding(Guid.NewGuid(), new Date(2000, 01, 01)); result.Should().HaveNotFoundStatus(); }
public void GetCorporateActionsStockNotOwned() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCorporateActionsService(portfolio, PortfolioTestCreator.StockResolver); var result = service.GetCorporateActions(Guid.NewGuid()); result.Should().HaveNotFoundStatus(); }
public void ChangeDrpParticipation() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioService(portfolio); var result = service.ChangeDrpParticipation(PortfolioTestCreator.Stock_ARG.Id, true); result.Should().HaveOkStatus(); }
public void GetTransactionNotFound() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioTransactionService(portfolio, null); var result = service.GetTransaction(Guid.NewGuid()); result.Should().HaveNotFoundStatus(); }
public void ChangeDrpParticipationStockNotFound() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioService(portfolio); var result = service.ChangeDrpParticipation(Guid.NewGuid(), true); result.Should().HaveNotFoundStatus(); }
public void GetGetDetailedCapitalGainsCapitalGainsStockNotOwnedAtDate() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCapitalGainsService(portfolio); var result = service.GetDetailedCapitalGains(PortfolioTestCreator.Stock_ARG.Id, new Date(1999, 01, 01)); result.Result.UnrealisedGains.Should().BeEmpty(); }
public void GetCapitalGainsStockNotFound() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCapitalGainsService(portfolio); var result = service.GetCapitalGains(Guid.NewGuid(), new Date(2010, 01, 01)); result.Should().HaveNotFoundStatus(); }
public void GetTransactionsForStockNotOwned() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioTransactionService(portfolio, null); var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 12, 31)); var result = service.GetTransactions(Guid.NewGuid(), dateRange); result.Result.Transactions.Should().BeEmpty(); }
public void GetValueForStockNotOwned() { var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 12, 31)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioValueService(portfolio, PortfolioTestCreator.TradingCalendar); var result = service.GetValue(Guid.NewGuid(), dateRange, ValueFrequency.Day); result.Should().HaveNotFoundStatus(); }
public void GetPerformance() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioPerformanceService(portfolio); var result = service.GetPerformance(new DateRange(new Date(2001, 01, 01), new Date(2010, 01, 01))); result.Result.Should().BeEquivalentTo(new { OpeningBalance = 335.00m, Dividends = 173.00m, ChangeInMarketValue = 291.00m, OutstandingDRPAmount = -0.50m, ClosingBalance = 807.50m, OpeningCashBalance = 9620.10m, Deposits = 500.00m, Withdrawls = -5000.00m, Interest = 100.00m, Fees = -59.85m, ClosingCashBalance = 5151.25m, HoldingPerformance = new[] { new RestApi.Portfolios.PortfolioPerformanceResponse.HoldingPerformanceItem() { Stock = PortfolioTestCreator.Stock_ARG, OpeningBalance = 105.00m, Purchases = 200.00m, Sales = 51.00m, ClosingBalance = 500.00m, Dividends = 140.00m, CapitalGain = 246.00m, DrpCashBalance = 0.00m, TotalReturn = 386.00m, Irr = 0.15518m }, new RestApi.Portfolios.PortfolioPerformanceResponse.HoldingPerformanceItem() { Stock = PortfolioTestCreator.Stock_WAM, OpeningBalance = 230.00m, Purchases = 32.50m, Sales = 0.00m, ClosingBalance = 307.50m, Dividends = 33.00m, CapitalGain = 45.00m, DrpCashBalance = 0.50m, TotalReturn = 78.00m, Irr = 0.03299m } } }); }
public void GetCapitalGainsStockOwnedAtDate() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCapitalGainsService(portfolio); var result = service.GetCapitalGains(PortfolioTestCreator.Stock_ARG.Id, new Date(2010, 01, 01)); result.Result.Should().BeEquivalentTo(new { UnrealisedGains = new[] { new RestApi.Portfolios.SimpleUnrealisedGainsItem() { Stock = PortfolioTestCreator.Stock_ARG, AquisitionDate = new Date(2000, 01, 01), Units = 50, CostBase = 59.97m, MarketValue = 100m, CapitalGain = 40.03m, DiscoutedGain = 20.02m, DiscountMethod = RestApi.Portfolios.CgtMethod.Discount }, new RestApi.Portfolios.SimpleUnrealisedGainsItem() { Stock = PortfolioTestCreator.Stock_ARG, AquisitionDate = new Date(2003, 01, 01), Units = 100, CostBase = 119.95m, MarketValue = 200m, CapitalGain = 80.05m, DiscoutedGain = 40.03m, DiscountMethod = RestApi.Portfolios.CgtMethod.Discount }, new RestApi.Portfolios.SimpleUnrealisedGainsItem() { Stock = PortfolioTestCreator.Stock_ARG, AquisitionDate = new Date(2005, 01, 01), Units = 100, CostBase = 119.95m, MarketValue = 200m, CapitalGain = 80.05m, DiscoutedGain = 40.03m, DiscountMethod = RestApi.Portfolios.CgtMethod.Discount } } }); }
public void ApplyIncomeReceived() { var mockRepository = new MockRepository(MockBehavior.Strict); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var events = new List <Event>(); var repository = mockRepository.Create <IRepository <Portfolio> >(); repository.Setup(x => x.Update(It.IsAny <Portfolio>())).Callback <Portfolio>(x => events.AddRange(x.FetchEvents())); var service = new PortfolioTransactionService(portfolio, repository.Object); var transaction = new IncomeReceived() { Id = Guid.NewGuid(), Stock = PortfolioTestCreator.Stock_ARG.Id, TransactionDate = new Date(2007, 01, 01), Comment = "", RecordDate = new Date(2006, 12, 27), FrankedAmount = 1.00m, UnfrankedAmount = 2.00m, FrankingCredits = 3.00m, Interest = 4.00m, TaxDeferred = 5.00m, CreateCashTransaction = true, DrpCashBalance = 2.50m }; var result = service.ApplyTransaction(transaction); result.Should().HaveOkStatus(); events.Should().BeEquivalentTo(new[] { new IncomeOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "") { RecordDate = new Date(2006, 12, 27), FrankedAmount = 1.00m, UnfrankedAmount = 2.00m, FrankingCredits = 3.00m, Interest = 4.00m, TaxDeferred = 5.00m, CreateCashTransaction = true, DrpCashBalance = 2.50m } }); mockRepository.Verify(); }
public void GetHoldingAtDate() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioHoldingService(portfolio); var result = service.GetHolding(PortfolioTestCreator.Stock_ARG.Id, new Date(2000, 01, 01)); result.Result.Should().BeEquivalentTo(new RestApi.Portfolios.Holding() { Stock = PortfolioTestCreator.Stock_ARG, Units = 100, Value = 100.00m, Cost = 119.95m, CostBase = 119.95m, }); }
public void GetTransaction() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioTransactionService(portfolio, null); var id = portfolio.Transactions[1].Id; var result = service.GetTransaction(id); result.Result.Should().BeEquivalentTo(new { Stock = PortfolioTestCreator.Stock_ARG.Id, Id = id, Type = TransactionType.Aquisition, TransactionDate = new Date(2000, 01, 01), Description = "Aquired 100 shares @ $1.00" }); }
public void GetCorporateActionsForStock() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCorporateActionsService(portfolio, PortfolioTestCreator.StockResolver); var result = service.GetCorporateActions(PortfolioTestCreator.Stock_WAM.Id); result.Result.Should().BeEquivalentTo(new { CorporateActions = new[] { new CorporateActionsResponse.CorporateActionItem() { Id = PortfolioTestCreator.WAM_Split, ActionDate = new Date(2002, 01, 01), Stock = PortfolioTestCreator.Stock_WAM, Description = "WAM Split" }, } }); }
public void ApplyDisposal() { var mockRepository = new MockRepository(MockBehavior.Strict); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var events = new List <Event>(); var repository = mockRepository.Create <IRepository <Portfolio> >(); repository.Setup(x => x.Update(It.IsAny <Portfolio>())).Callback <Portfolio>(x => events.AddRange(x.FetchEvents())); var service = new PortfolioTransactionService(portfolio, repository.Object); var transaction = new Disposal() { Id = Guid.NewGuid(), Stock = PortfolioTestCreator.Stock_ARG.Id, TransactionDate = new Date(2007, 01, 01), Comment = "", Units = 50, AveragePrice = 0.98m, TransactionCosts = 1.00m, CgtMethod = CgtCalculationMethod.LastInFirstOut, CreateCashTransaction = true }; var result = service.ApplyTransaction(transaction); result.Should().HaveOkStatus(); events.Should().BeEquivalentTo(new[] { new DisposalOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "") { Units = 50, AveragePrice = 0.98m, TransactionCosts = 1.00m, CgtMethod = Domain.Utils.CgtCalculationMethod.LastInFirstOut, CreateCashTransaction = true } }); mockRepository.Verify(); }
public void GetValueForStockMonthly() { var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 05, 25)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioValueService(portfolio, PortfolioTestCreator.TradingCalendar); var result = service.GetValue(PortfolioTestCreator.Stock_ARG.Id, dateRange, ValueFrequency.Month); result.Result.Should().BeEquivalentTo(new { Values = new[] { new ClosingPrice() { Date = new Date(2000, 01, 03), Price = 101.00m }, new ClosingPrice() { Date = new Date(2000, 01, 31), Price = 109.00m }, new ClosingPrice() { Date = new Date(2000, 02, 29), Price = 110.00m }, new ClosingPrice() { Date = new Date(2000, 03, 31), Price = 107.00m }, new ClosingPrice() { Date = new Date(2000, 04, 30), Price = 107.00m }, new ClosingPrice() { Date = new Date(2000, 05, 25), Price = 103.00m } } }); }
public void HoldingAquiredAndDisposedInPeriod() { var portfolio = PortfolioTestCreator.CreateEmptyPortfolio(); portfolio.AquireShares(PortfolioTestCreator.Stock_ARG.Id, new Date(2002, 01, 01), 100, 1.00m, 19.95m, false, "", Guid.NewGuid()); portfolio.DisposeOfShares(PortfolioTestCreator.Stock_ARG.Id, new Date(2009, 01, 01), 100, 1.20m, 19.95m, Domain.Utils.CgtCalculationMethod.FirstInFirstOut, false, "", Guid.NewGuid()); var service = new PortfolioPerformanceService(portfolio); var result = service.GetPerformance(new DateRange(new Date(2001, 01, 01), new Date(2010, 01, 01))); result.Result.Should().BeEquivalentTo(new { OpeningBalance = 0.00m, Dividends = 0.00m, ChangeInMarketValue = 20.00m, OutstandingDRPAmount = 0.00m, ClosingBalance = 000.00m, OpeningCashBalance = 0.00m, Deposits = 0.00m, Withdrawls = 0.00m, Interest = 0.00m, Fees = 0.00m, ClosingCashBalance = 0.00m, HoldingPerformance = new[] { new RestApi.Portfolios.PortfolioPerformanceResponse.HoldingPerformanceItem() { Stock = PortfolioTestCreator.Stock_ARG, OpeningBalance = 0.00m, Purchases = 100.00m, Sales = 120.00m, ClosingBalance = 0.00m, Dividends = 0.00m, CapitalGain = 20.00m, DrpCashBalance = 0.00m, TotalReturn = 20.00m, Irr = 0.02637m } } }); }
public void GetValueMonthly() { var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 05, 25)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioValueService(portfolio, PortfolioTestCreator.TradingCalendar); var result = service.GetValue(dateRange, ValueFrequency.Month); result.Result.Should().BeEquivalentTo(new { Values = new[] { new ClosingPrice() { Date = new Date(2000, 01, 03), Price = 9963.10m }, new ClosingPrice() { Date = new Date(2000, 01, 31), Price = 9985.10m }, new ClosingPrice() { Date = new Date(2000, 02, 29), Price = 9988.10m }, new ClosingPrice() { Date = new Date(2000, 03, 31), Price = 9981.10m }, new ClosingPrice() { Date = new Date(2000, 04, 30), Price = 9981.10m }, new ClosingPrice() { Date = new Date(2000, 05, 25), Price = 9969.10m } } }); }
public void GetTransactionsForStock() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioTransactionService(portfolio, null); var dateRange = new DateRange(new Date(2000, 01, 01), new Date(2000, 12, 31)); var result = service.GetTransactions(PortfolioTestCreator.Stock_WAM.Id, dateRange); result.Result.Transactions.Should().BeEquivalentTo(new[] { new RestApi.Portfolios.TransactionsResponse.TransactionItem() { Id = portfolio.Transactions[2].Id, Stock = PortfolioTestCreator.Stock_WAM, TransactionDate = new Date(2000, 01, 01), Description = "Aquired 200 shares @ $1.20", Comment = "" } }); }
public void GetTransactionsForCorporateAction() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCorporateActionsService(portfolio, PortfolioTestCreator.StockResolver); var result = service.GetTransactionsForCorporateAction(PortfolioTestCreator.Stock_WAM.Id, PortfolioTestCreator.WAM_Split); result.Result.Should().BeEquivalentTo(new [] { new RestApi.Transactions.UnitCountAdjustment() { Stock = PortfolioTestCreator.Stock_WAM.Id, TransactionDate = new Date(2002, 01, 01), Description = "Adjust unit count using ratio 1:2", Comment = "WAM Split", OriginalUnits = 1, NewUnits = 2 } }, options => options.Excluding(x => x.Id)); }
public void GetCGTLiability() { var dateRange = new DateRange(new Date(2003, 07, 01), new Date(2004, 06, 30)); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioCgtLiabilityService(portfolio); var result = service.GetCGTLiability(dateRange); result.Result.Should().BeEquivalentTo(new { CurrentYearCapitalGainsOther = 0.00m, CurrentYearCapitalGainsDiscounted = 0.00m, CurrentYearCapitalGainsTotal = -0.00m, CurrentYearCapitalLossesOther = 0.00m, CurrentYearCapitalLossesDiscounted = 28.93m, CurrentYearCapitalLossesTotal = 28.93m, GrossCapitalGainOther = 0.00m, GrossCapitalGainDiscounted = -28.93m, GrossCapitalGainTotal = -28.93m, Discount = 0.00m, NetCapitalGainOther = 0.00m, NetCapitalGainDiscounted = -28.93m, NetCapitalGainTotal = -28.93m, Events = new [] { new CgtLiabilityResponse.CgtLiabilityEvent() { Stock = PortfolioTestCreator.Stock_ARG, EventDate = new Date(2004, 01, 01), CostBase = 59.98m, AmountReceived = 31.05m, CapitalGain = -28.93m, Method = CgtMethod.Discount } } }); }
public void ApplyReturnOfCapital() { var mockRepository = new MockRepository(MockBehavior.Strict); var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var events = new List <Event>(); var repository = mockRepository.Create <IRepository <Portfolio> >(); repository.Setup(x => x.Update(It.IsAny <Portfolio>())).Callback <Portfolio>(x => events.AddRange(x.FetchEvents())); var service = new PortfolioTransactionService(portfolio, repository.Object); var transaction = new ReturnOfCapital() { Id = Guid.NewGuid(), Stock = PortfolioTestCreator.Stock_ARG.Id, TransactionDate = new Date(2007, 01, 01), Comment = "", Amount = 5.00m, RecordDate = new Date(2006, 12, 01), CreateCashTransaction = true }; var result = service.ApplyTransaction(transaction); result.Should().HaveOkStatus(); events.Should().BeEquivalentTo(new[] { new ReturnOfCapitalOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "") { Amount = 5.00m, RecordDate = new Date(2006, 12, 01), CreateCashTransaction = true } }); mockRepository.Verify(); }
public void GetSummary() { var portfolio = PortfolioTestCreator.CreateDefaultPortfolio(); var service = new PortfolioSummaryService(portfolio); var result = service.GetSummary(new Date(2010, 01, 01)); result.Result.Should().BeEquivalentTo(new { PortfolioValue = 5958.75m, PortfolioCost = 5743.57m, Return1Year = 0.01991m, Return3Year = 0.01882m, Return5Year = 0.00837m, ReturnAll = 0.00539m, CashBalance = 5151.25m, Holdings = new[] { new RestApi.Portfolios.Holding() { Stock = PortfolioTestCreator.Stock_ARG, Units = 250, Value = 500m, Cost = 299.87m, CostBase = 299.87m }, new RestApi.Portfolios.Holding() { Stock = PortfolioTestCreator.Stock_WAM, Units = 205, Value = 307.50m, Cost = 292.45m, CostBase = 292.45m } } }); }