public ServiceResult <PortfolioValueResponse> GetValue(Guid stockId, DateRange dateRange, ValueFrequency frequency)
        {
            if (_Portfolio == null)
            {
                return(ServiceResult <PortfolioValueResponse> .NotFound());
            }

            var holding = _Portfolio.Holdings[stockId];

            if (holding == null)
            {
                return(ServiceResult <PortfolioValueResponse> .NotFound());
            }

            var response = new PortfolioValueResponse();

            var dates = GetDates(dateRange, frequency);

            foreach (var date in dates)
            {
                var value = new ClosingPrice()
                {
                    Date  = date,
                    Price = holding.Value(date)
                };

                response.Values.Add(value);
            }

            return(ServiceResult <PortfolioValueResponse> .Ok(response));
        }
        public ServiceResult <PortfolioValueResponse> GetValue(DateRange dateRange, ValueFrequency frequency)
        {
            if (_Portfolio == null)
            {
                return(ServiceResult <PortfolioValueResponse> .NotFound());
            }

            var response = new PortfolioValueResponse();

            var dates = GetDates(dateRange, frequency);

            var holdings = _Portfolio.Holdings.All(dateRange);

            var closingBalances          = _Portfolio.CashAccount.EffectiveBalances(dateRange);
            var closingBalanceEnumerator = closingBalances.GetEnumerator();

            closingBalanceEnumerator.MoveNext();

            foreach (var date in dates)
            {
                var amount = 0.00m;

                // Add holding values
                foreach (var holding in holdings)
                {
                    amount += holding.Value(date);
                }

                // Add cash account balances
                if (date > closingBalanceEnumerator.Current.EffectivePeriod.ToDate)
                {
                    closingBalanceEnumerator.MoveNext();
                }
                amount += closingBalanceEnumerator.Current.Balance;

                var value = new ClosingPrice()
                {
                    Date  = date,
                    Price = amount
                };

                response.Values.Add(value);
            }

            return(ServiceResult <PortfolioValueResponse> .Ok(response));
        }
Ejemplo n.º 3
0
        public void GetValueMonthly()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var response = new PortfolioValueResponse();

            var service = mockRepository.Create <IPortfolioValueService>();

            service.Setup(x => x.GetValue(It.IsAny <DateRange>(), ValueFrequency.Month)).Returns(ServiceResult <PortfolioValueResponse> .Ok(response)).Verifiable();

            var controller = new PortfolioController();
            var result     = controller.GetValue(service.Object, null, null, ValueFrequency.Month);

            result.Result.Should().BeOkObjectResult().Value.Should().Be(response);

            mockRepository.VerifyAll();
        }
Ejemplo n.º 4
0
        public void GetValueBothDates()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var response = new PortfolioValueResponse();

            var service = mockRepository.Create <IPortfolioValueService>();

            service.Setup(x => x.GetValue(new DateRange(new Date(2000, 01, 01), new Date(2000, 12, 31)), It.IsAny <ValueFrequency>())).Returns(ServiceResult <PortfolioValueResponse> .Ok(response)).Verifiable();

            var controller = new PortfolioController();
            var result     = controller.GetValue(service.Object, new DateTime(2000, 01, 01), new DateTime(2000, 12, 31), null);

            result.Result.Should().BeOkObjectResult().Value.Should().Be(response);

            mockRepository.VerifyAll();
        }
        public void GetValueNoDates()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stockId  = Guid.NewGuid();
            var response = new PortfolioValueResponse();

            var service = mockRepository.Create <IPortfolioValueService>();

            service.Setup(x => x.GetValue(stockId, new DateRange(Date.Today.AddYears(-1).AddDays(1), Date.Today), It.IsAny <ValueFrequency>())).Returns(ServiceResult <PortfolioValueResponse> .Ok(response)).Verifiable();

            var controller = new HoldingController();
            var result     = controller.GetValue(service.Object, stockId, null, null, null);

            result.Result.Should().BeOkObjectResult().Value.Should().Be(response);

            mockRepository.VerifyAll();
        }
Ejemplo n.º 6
0
        public async Task GetValue(ValueFrequency frequency, string queryString)
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var portfolioId = Guid.NewGuid();
            var dateRange   = new DateRange(new Date(2001, 02, 03), new Date(2008, 06, 30));
            var response    = new PortfolioValueResponse();

            var messageHandler = mockRepository.Create <IRestClientMessageHandler>();

            messageHandler.SetupProperty(x => x.Portfolio, portfolioId);
            messageHandler.Setup(x => x.GetAsync <PortfolioValueResponse>(It.Is <string>(x => x == "portfolio/" + portfolioId + "/value?fromdate=2001-02-03&todate=2008-06-30&frequency=" + queryString)))
            .Returns(Task <PortfolioValueResponse> .FromResult(response))
            .Verifiable();

            var resource = new PortfolioResource(messageHandler.Object);

            var result = await resource.GetValue(dateRange, frequency);

            result.Should().Be(response);

            mockRepository.Verify();
        }