public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var aquisition = transaction as Aquisition;

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

            if (!aquisition.Stock.IsEffectiveAt(aquisition.Date))
            {
                throw new StockNotActiveException("Stock is not active");
            }

            decimal cost       = aquisition.Units * aquisition.AveragePrice;
            decimal amountPaid = cost + aquisition.TransactionCosts;
            decimal costBase   = amountPaid;

            holding.AddParcel(aquisition.Date, aquisition.Date, aquisition.Units, amountPaid, costBase, transaction);

            if (aquisition.CreateCashTransaction)
            {
                var asxCode = aquisition.Stock.Properties[aquisition.Date].AsxCode;
                cashAccount.Transfer(aquisition.Date, -cost, String.Format("Purchase of {0}", asxCode));

                if (aquisition.TransactionCosts > 0.00m)
                {
                    cashAccount.FeeDeducted(aquisition.Date, aquisition.TransactionCosts, String.Format("Brokerage for purchase of {0}", asxCode));
                }
            }
        }
Пример #2
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));
            }
        }
Пример #3
0
        private static IRebalancingTradeData GetRebalancingTradeData(IHolding holding, Func <uint, decimal, bool> validation, decimal targetCapital)
        {
            decimal contribution         = holding.CurrentPrice * holding.Quantity;
            decimal differenceFromTarget = contribution - targetCapital;
            uint    quantity             = (uint)(Math.Abs(differenceFromTarget) / holding.CurrentPrice);

            return(validation(quantity, differenceFromTarget) ? new RebalancingTradeData(quantity, holding.Symbol, holding.CurrentPrice) : null);
        }
Пример #4
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);
            }
        }
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var openingBalance = transaction as OpeningBalance;

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

            if (!openingBalance.Stock.IsEffectiveAt(openingBalance.Date))
            {
                throw new StockNotActiveException("Stock is not active");
            }

            holding.AddParcel(openingBalance.Date, openingBalance.AquisitionDate, openingBalance.Units, openingBalance.CostBase, openingBalance.CostBase, transaction);
        }
Пример #6
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);
            }
        }
        public void Apply(IPortfolioTransaction transaction, IHolding holding, ICashAccount cashAccount)
        {
            var cashTransaction = transaction as CashTransaction;

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

            var description = "";

            if (cashTransaction.Comment != "")
            {
                description = cashTransaction.Comment;
            }
            else if (cashTransaction.CashTransactionType == BankAccountTransactionType.Deposit)
            {
                description = "Deposit";
            }
            else if (cashTransaction.CashTransactionType == BankAccountTransactionType.Fee)
            {
                description = "Fee";
            }
            else if (cashTransaction.CashTransactionType == BankAccountTransactionType.Interest)
            {
                description = "Interest";
            }
            else if (cashTransaction.CashTransactionType == BankAccountTransactionType.Transfer)
            {
                description = "Transfer";
            }
            else if (cashTransaction.CashTransactionType == BankAccountTransactionType.Withdrawl)
            {
                description = "Withdrawl";
            }

            cashAccount.AddTransaction(cashTransaction.Date, cashTransaction.Amount, description, cashTransaction.CashTransactionType);
        }
        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);
            }
        }
Пример #9
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));
                }
            }
        }