Example #1
0
        private SimpleUnrealisedGainsResponse GetCapitalGains(IEnumerable <IReadOnlyHolding> holdings, Date date)
        {
            var response = new SimpleUnrealisedGainsResponse();

            foreach (var holding in holdings)
            {
                foreach (var parcel in holding.Parcels(date))
                {
                    var properties = parcel.Properties[date];

                    var value          = properties.Units * holding.Stock.GetPrice(date);
                    var capitalGain    = value - properties.CostBase;
                    var discountMethod = CgtUtils.CgtMethodForParcel(parcel.AquisitionDate, date);
                    var discoutedGain  = (discountMethod == Domain.Portfolios.CgtMethod.Discount) ? CgtUtils.DiscountedCgt(capitalGain, Domain.Portfolios.CgtMethod.Discount) : capitalGain;

                    var unrealisedGain = new SimpleUnrealisedGainsItem()
                    {
                        Stock          = holding.Stock.ToSummaryResponse(date),
                        AquisitionDate = parcel.AquisitionDate,
                        Units          = properties.Units,
                        CostBase       = properties.CostBase,
                        MarketValue    = value,
                        CapitalGain    = capitalGain,
                        DiscoutedGain  = discoutedGain,
                        DiscountMethod = discountMethod.ToResponse()
                    };

                    response.UnrealisedGains.Add(unrealisedGain);
                }
            }

            return(response);
        }
        public void CgtMethodCalculation(Date aquisitionDate, CgtMethod method, string reason)
        {
            var saleDate = new Date(2020, 01, 01);

            var cgtMethod = CgtUtils.CgtMethodForParcel(aquisitionDate, saleDate);

            cgtMethod.Should().Be(method, reason);
        }
Example #3
0
        private DetailedUnrealisedGainsResponse GetDetailedCapitalGains(IEnumerable <IReadOnlyHolding> holdings, Date date)
        {
            var response = new DetailedUnrealisedGainsResponse();

            foreach (var holding in holdings)
            {
                foreach (var parcel in holding.Parcels(date))
                {
                    var properties = parcel.Properties[date];

                    var value          = properties.Units * holding.Stock.GetPrice(date);
                    var capitalGain    = value - properties.CostBase;
                    var discountMethod = CgtUtils.CgtMethodForParcel(parcel.AquisitionDate, date);
                    var discoutedGain  = (discountMethod == Domain.Portfolios.CgtMethod.Discount) ? CgtUtils.DiscountedCgt(capitalGain, Domain.Portfolios.CgtMethod.Discount) : capitalGain;

                    var unrealisedGain = new DetailedUnrealisedGainsItem()
                    {
                        Stock          = holding.Stock.ToSummaryResponse(date),
                        AquisitionDate = parcel.AquisitionDate,
                        Units          = properties.Units,
                        CostBase       = properties.CostBase,
                        MarketValue    = value,
                        CapitalGain    = capitalGain,
                        DiscoutedGain  = discoutedGain,
                        DiscountMethod = discountMethod.ToResponse()
                    };

                    int     units    = 0;
                    decimal costBase = 0.00m;
                    foreach (var auditRecord in parcel.Audit.TakeWhile(x => x.Date <= date))
                    {
                        units    += auditRecord.UnitCountChange;
                        costBase += auditRecord.CostBaseChange;

                        var cgtEvent = new DetailedUnrealisedGainsItem.CGTEventItem()
                        {
                            Date           = auditRecord.Date,
                            Description    = auditRecord.Transaction.Description,
                            UnitChange     = auditRecord.UnitCountChange,
                            Units          = units,
                            CostBaseChange = auditRecord.CostBaseChange,
                            CostBase       = costBase,
                        };

                        unrealisedGain.CGTEvents.Add(cgtEvent);
                    }

                    response.UnrealisedGains.Add(unrealisedGain);
                }
            }

            return(response);
        }