コード例 #1
0
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var returnOfCapital = transaction as ReturnOfCapital;

            if (returnOfCapital == null)
            {
                throw new ArgumentException("Expected transaction to be an ReturnOfCapital");
            }

            if (!holding.IsEffectiveAt(returnOfCapital.RecordDate))
            {
                throw new NoSharesOwnedException("No holdings");
            }

            // Reduce cost base of parcels
            decimal totalAmount = 0;

            foreach (var parcel in holding.Parcels(returnOfCapital.RecordDate))
            {
                var costBaseReduction = parcel.Properties[returnOfCapital.RecordDate].Units * returnOfCapital.Amount;
                parcel.Change(returnOfCapital.RecordDate, 0, 0.00m, costBaseReduction, transaction);

                totalAmount += costBaseReduction;
            }

            if (returnOfCapital.CreateCashTransaction)
            {
                var asxCode = returnOfCapital.Stock.Properties[returnOfCapital.RecordDate].AsxCode;
                cashAccount.Transfer(returnOfCapital.Date, totalAmount, String.Format("Return of capital for {0}", asxCode));
            }
        }
コード例 #2
0
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var incomeReceived = transaction as IncomeReceived;

            if (incomeReceived == null)
            {
                throw new ArgumentException("Expected transaction to be an IncomeReceived");
            }

            if (!holding.IsEffectiveAt(incomeReceived.RecordDate))
            {
                throw new NoSharesOwnedException("No holdings");
            }

            // Handle any tax deferred amount recieved
            if (incomeReceived.TaxDeferred > 0)
            {
                var parcels = holding.Parcels(incomeReceived.RecordDate);

                // Apportion amount between parcels
                var apportionedAmounts = parcels.Select(x => new ApportionedCurrencyValue()
                {
                    Units = x.Properties[incomeReceived.RecordDate].Units
                }).ToArray();
                MathUtils.ApportionAmount(incomeReceived.TaxDeferred, apportionedAmounts);

                // Reduce cost base of parcels
                var i = 0;
                foreach (var parcel in parcels)
                {
                    parcel.Change(incomeReceived.RecordDate, 0, 0.00m, apportionedAmounts[i++].Amount, transaction);
                }
            }

            if (incomeReceived.CreateCashTransaction)
            {
                var asxCode = incomeReceived.Stock.Properties[incomeReceived.RecordDate].AsxCode;
                cashAccount.Transfer(incomeReceived.Date, incomeReceived.CashIncome, String.Format("Distribution for {0}", asxCode));
            }

            var drpCashBalance = holding.DrpAccount.Balance(incomeReceived.Date);

            var drpAccountCredit = incomeReceived.DrpCashBalance - drpCashBalance;

            if (drpAccountCredit != 0.00m)
            {
                holding.AddDrpAccountAmount(incomeReceived.Date, drpAccountCredit);
            }
        }
コード例 #3
0
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var costBaseAdjustment = transaction as CostBaseAdjustment;

            if (costBaseAdjustment == null)
            {
                throw new ArgumentException("Expected transaction to be an CostBaseAdjustment");
            }

            if (!holding.IsEffectiveAt(costBaseAdjustment.Date))
            {
                throw new NoSharesOwnedException("No holdings");
            }

            // Adjust cost base of parcels
            foreach (var parcel in holding.Parcels(costBaseAdjustment.Date))
            {
                var costBaseReduction = (parcel.Properties[costBaseAdjustment.Date].CostBase * (1 - costBaseAdjustment.Percentage)).ToCurrency(RoundingRule.Round);
                parcel.Change(costBaseAdjustment.Date, 0, 0.00m, -costBaseReduction, transaction);
            }
        }
コード例 #4
0
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var unitCountAdjustment = transaction as UnitCountAdjustment;

            if (unitCountAdjustment == null)
            {
                throw new ArgumentException("Expected transaction to be an UnitCountAdjustment");
            }

            if (!holding.IsEffectiveAt(unitCountAdjustment.Date))
            {
                throw new NoSharesOwnedException("No holdings");
            }

            // Adjust unit count of parcels
            var ratio = (decimal)unitCountAdjustment.NewUnits / (decimal)unitCountAdjustment.OriginalUnits;

            foreach (var parcel in holding.Parcels(unitCountAdjustment.Date))
            {
                var units = (int)Math.Ceiling(parcel.Properties[unitCountAdjustment.Date].Units * ratio);
                parcel.Change(unitCountAdjustment.Date, units, 0.00m, 0.00m, transaction);
            }
        }
コード例 #5
0
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var disposal = transaction as Disposal;

            if (disposal == null)
            {
                throw new ArgumentException("Expected transaction to be a Disposal");
            }

            if (!holding.IsEffectiveAt(disposal.Date))
            {
                throw new NoSharesOwnedException("No holdings");
            }

            if (holding.Properties[disposal.Date].Units < disposal.Units)
            {
                throw new NotEnoughSharesForDisposal("Not enough shares for disposal");
            }

            // Determine which parcels to sell based on CGT method
            decimal amountReceived = (disposal.Units * disposal.AveragePrice) - disposal.TransactionCosts;

            var cgtCalculator = new CgtCalculator();
            var parcelsSold   = cgtCalculator.Calculate(holding.Parcels(disposal.Date), disposal.Date, disposal.Units, amountReceived, CgtCalculator.GetCgtComparer(disposal.Date, disposal.CgtMethod));

            // Dispose of select parcels
            if (disposal.Stock is StapledSecurity)
            {
                /*     foreach (ParcelSold parcelSold in cgtCalculation.ParcelsSold)
                 *   {
                 *       var childStocks = _StockQuery.GetChildStocks(stock.Id, disposal.TransactionDate);
                 *
                 *       // Apportion amount based on NTA of child stocks
                 *       var amountsReceived = PortfolioUtils.ApportionAmountOverChildStocks(childStocks, disposal.TransactionDate, parcelSold.AmountReceived, _StockQuery);
                 *
                 *       int i = 0;
                 *       foreach (var childStock in childStocks)
                 *       {
                 *           var childParcels = _PortfolioQuery.GetParcelsForStock(childStock.Id, disposal.TransactionDate, disposal.TransactionDate);
                 *
                 *           var childParcel = childParcels.First(x => x.PurchaseId == parcelSold.Parcel.PurchaseId);
                 *           DisposeOfParcel(unitOfWork, childParcel, disposal.TransactionDate, parcelSold.UnitsSold, amountsReceived[i].Amount, transaction.Id);
                 *
                 *           i++;
                 *       }
                 *
                 *   };  */
            }
            else
            {
                foreach (var parcelSold in parcelsSold)
                {
                    holding.DisposeOfParcel(parcelSold.Parcel.Id, disposal.Date, parcelSold.UnitsSold, parcelSold.AmountReceived, parcelSold.CapitalGain, parcelSold.CgtMethod, transaction);
                }
            }

            if (disposal.CreateCashTransaction)
            {
                var cost = disposal.Units * disposal.AveragePrice;

                var asxCode = disposal.Stock.Properties[disposal.Date].AsxCode;
                cashAccount.Transfer(disposal.Date, cost, String.Format("Sale of {0}", asxCode));

                if (disposal.TransactionCosts > 0.00m)
                {
                    cashAccount.FeeDeducted(disposal.Date, disposal.TransactionCosts, String.Format("Brokerage for sale of {0}", asxCode));
                }
            }
        }