Inheritance: Transaction
Ejemplo n.º 1
0
        public void ShouldBeAbleToCalculateTaxGivenABuyStackAndSellStackWithMultipleValues()
        {
            Instrument share = new Stock(new Symbol("REL"), new Price(10.00), "Rel*iance Power");
            Transaction buyTransaction1 = new BuyTransaction(new DateTime(2008, 06, 01), share, 20, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction1 = new SellTransaction(new DateTime(2009, 01, 01), share, 10, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction2 = new BuyTransaction(new DateTime(2008, 12, 01), share, 10, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction2 = new SellTransaction(new DateTime(2009, 08, 01), share, 10, new Price(20.00), 5.00, 3.00);

            List<Transaction> listTransaction = new List<Transaction> { buyTransaction1, sellTransaction1, buyTransaction2, sellTransaction2 };

            ShortTermTaxCalculator TaxCalculator = new ShortTermTaxCalculator(listTransaction, new FinYear(2009));

            Stack buyStack = TaxCalculator.CreateBuyTransactionStack();
            Stack sellStack = TaxCalculator.CreateSellTransactionStack();

            Assert.AreEqual(2, buyStack.Count);
            Assert.AreEqual(2, sellStack.Count);

            Price Tax;
            Tax = TaxCalculator.CalculateTaxOverTheBuyAndSellStacks(buyStack, sellStack);

            //            Assert.AreEqual(0, buyStack.Count);
            //            Assert.AreEqual(0, sellStack.Count);

            Assert.AreEqual(20, Tax.Value);
        }
Ejemplo n.º 2
0
        public void ShouldBeAbleToCalculateShortTermTaxForOneBuyAndSell()
        {
            Instrument share = new Stock(new Symbol("REL"), new Price(10.00), "Reliance Power");
            BuyTransaction buyTransaction = new BuyTransaction(new DateTime(2008, 06, 01), share, 10, new Price(10.00), 5.00, 3.00);
            SellTransaction sellTransaction = new SellTransaction(new DateTime(2008, 12, 01), share, 10, new Price(20.00), 5.00, 3.00);

            Price price = new ShortTermTaxCalculator(null, new FinYear(2009)).CalculateShortTermTaxForAPairOfTransactions(buyTransaction, sellTransaction);
            Assert.AreEqual(20, price.Value);
        }
Ejemplo n.º 3
0
        public virtual Price CalculateShortTermTax(BuyTransaction buyTransaction)
        {
            if (IsShortTerm(buyTransaction))
            {
                double profitOrLoss = CalculateTotalPrice(this.UnitPrice, this.Quantity) -
                                      CalculateTotalPrice(buyTransaction.UnitPrice, buyTransaction.Quantity);
                if(profitOrLoss>0)
                {
                    return new Price(0.20*profitOrLoss);
                }
            }

            return new Price(0);
        }
Ejemplo n.º 4
0
        public void TestListTransactionsByInstrumentId()
        {
            var hundredRuppees = new Price(100);
            var relianceMutuals = new Symbol("RELTICK");
            Instrument instrument = new MutualFund(relianceMutuals, hundredRuppees, "Test Fund", "SUNMF", "SUN Magma", "Growth");
            repository.Save(instrument);

            Transaction buyTransaction = new BuyTransaction(DateTime.Now, instrument, 10, new Price(1000), 100, 100);
            repository.Save(buyTransaction);

            IList<Transaction> translist=repository.ListTransactionsByInstrumentId<Transaction>(instrument.Id);

            Assert.AreEqual(1,repository.ListTransactionsByInstrumentId<Transaction>(instrument.Id).Count);
        }
Ejemplo n.º 5
0
        public void ShouldIncludeUnitDividendWhileGettingCurrentMarketValueOfInstrument()
        {
            Instrument instrument = new MutualFund(new Symbol("RILMF"), new Price(100.00), "Reliance Mutual Fund", "SUNMF", "SUN Magma", "Growth");

            Transaction transaction1 = new BuyTransaction(new DateTime(2009, 09, 09), instrument, 10, new Price(100.00), 10, 10);
            Transaction transaction2 = new SellTransaction(new DateTime(2009, 09, 10), instrument, 5, new Price(200.00), 10, 10);
            Transaction transaction3 = new UnitDividendTransaction(instrument, 5, new DateTime(2009, 09, 10));

            List<Transaction> listTransaction = new List<Transaction>();
            listTransaction.Add(transaction1);
            listTransaction.Add(transaction2);
            Assert.AreEqual(500.00, instrument.CurrentMarketValue(listTransaction).Value);
            listTransaction.Add(transaction3);

            Assert.AreEqual(1000.00, instrument.CurrentMarketValue(listTransaction).Value);
        }
Ejemplo n.º 6
0
        public Price CalculateTaxOverTheBuyAndSellStacks(Stack buyStack, Stack sellStack)
        {
            BuyTransaction buy;
            SellTransaction sell;

            Price shortTermTax = new Price(0);

            while (buyStack.Count > 0 && sellStack.Count > 0)
            {
                buy = (BuyTransaction)buyStack.Pop();
                sell = (SellTransaction)sellStack.Pop();

                if (buy.Quantity.Equals(sell.Quantity))
                {
                    shortTermTax += sell.CalculateShortTermTax(buy);
                }
                else
                    if (buy.Quantity > sell.Quantity)
                    {
                        BuyTransaction buyTransactionIntoStack = new BuyTransaction(buy.Date, buy.Instrument, buy.Quantity - sell.Quantity, buy.UnitPrice, buy.Tax, buy.Brokerage);

                        buyStack.Push(buyTransactionIntoStack);

                        shortTermTax += sell.CalculateShortTermTax(new BuyTransaction(buy.Date, buy.Instrument, sell.Quantity, buy.UnitPrice, buy.Tax, buy.Brokerage));

                    }
                    else
                    {
                        SellTransaction sellTransactionIntoStack = new SellTransaction(buy.Date, buy.Instrument, sell.Quantity - buy.Quantity, buy.UnitPrice, buy.Tax, buy.Brokerage);

                        sellStack.Push(sellTransactionIntoStack);

                        sell.Quantity = buy.Quantity;

                        shortTermTax += sell.CalculateShortTermTax(new BuyTransaction(buy.Date, buy.Instrument, sell.Quantity, buy.UnitPrice, buy.Tax, buy.Brokerage));

                    }
            }

            return shortTermTax;
        }
Ejemplo n.º 7
0
        public void ShouldGetSTCGForTheListOfValidTransactions()
        {
            Instrument share = new Stock(new Symbol("REL"), new Price(10.00), "Rel*iance Power");

            Transaction buyTransaction1 = new BuyTransaction(new DateTime(2005, 06, 01), share, 20, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction1 = new SellTransaction(new DateTime(2006, 01, 01), share, 10, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction2 = new BuyTransaction(new DateTime(2006, 12, 01), share, 10, new Price(30.00), 5.00, 3.00);
            Transaction sellTransaction2 = new SellTransaction(new DateTime(2007, 08, 01), share, 10, new Price(50.00), 5.00, 3.00);

            // The balance at end of this should be a Buy with 10 shares left.
            // These transactions below will not be considered.
            //            Transaction buyTransaction8 = new BuyTransaction(new DateTime(2008, 06, 01), share, 10, new Price(10.00), 5.00, 3.00);
            Transaction buyTransaction3 = new BuyTransaction(new DateTime(2008, 06, 01), share, 20, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction3 = new SellTransaction(new DateTime(2009, 01, 01), share, 10, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction4 = new BuyTransaction(new DateTime(2008, 12, 01), share, 10, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction4 = new SellTransaction(new DateTime(2009, 08, 01), share, 10, new Price(20.00), 5.00, 3.00);

            List<Transaction> listTransaction = new List<Transaction> { buyTransaction1, sellTransaction1, buyTransaction2, sellTransaction2,buyTransaction3, sellTransaction3, buyTransaction4, sellTransaction4 };

            ShortTermTaxCalculator TaxCalculator = new ShortTermTaxCalculator(listTransaction, new FinYear(2009));

            Price Tax = TaxCalculator.CalculateShortTermTax();

            Assert.AreEqual(20, Tax.Value);
        }
Ejemplo n.º 8
0
        public void ShouldCreateStackOfSellTransactionsGivenAListOfTransactions()
        {
            Instrument share = new Stock(new Symbol("REL"), new Price(10.00), "Reliance Power");
            Transaction buyTransaction1 = new BuyTransaction(new DateTime(2008, 06, 01), share, 10, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction1 = new SellTransaction(new DateTime(2008, 12, 01), share, 2, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction2 = new BuyTransaction(new DateTime(2009, 06, 01), share, 12, new Price(50.00), 5.00, 3.00);
            Transaction sellTransaction2 = new SellTransaction(new DateTime(2009, 12, 01), share, 20, new Price(100.00), 5.00, 3.00);

            List<Transaction> listTransaction = new List<Transaction> { buyTransaction1, sellTransaction1, buyTransaction2, sellTransaction2 };

            Stack sellStack = new ShortTermTaxCalculator(listTransaction, new FinYear(2009)).CreateSellTransactionStack();
            Assert.AreEqual(2, sellStack.Count);
            Assert.AreEqual(sellTransaction1, sellStack.Pop());
            Assert.AreEqual(sellTransaction2, sellStack.Pop());
        }
Ejemplo n.º 9
0
        public void ShouldBeAbleToCreateATransactionShowingRemainingQuantityOfInstrumentForAllBuyAndSellBeforeOneYearPriorToTaxCalculationYear()
        {
            Instrument share = new Stock(new Symbol("REL"), new Price(10.00), "Rel*iance Power");

            Transaction buyTransaction1 = new BuyTransaction(new DateTime(2005, 06, 01), share, 20, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction1 = new SellTransaction(new DateTime(2006, 01, 01), share, 10, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction2 = new BuyTransaction(new DateTime(2006, 12, 01), share, 10, new Price(30.00), 5.00, 3.00);
            Transaction sellTransaction2 = new SellTransaction(new DateTime(2007, 08, 01), share, 10, new Price(50.00), 5.00, 3.00);

            // The balance at end of this should be a Buy with 10 shares left.
            // These transactions below will not be considered.

            Transaction buyTransaction3 = new BuyTransaction(new DateTime(2008, 06, 01), share, 20, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction3 = new SellTransaction(new DateTime(2009, 01, 01), share, 10, new Price(20.00), 5.00, 3.00);
            Transaction buyTransaction4 = new BuyTransaction(new DateTime(2008, 12, 01), share, 10, new Price(10.00), 5.00, 3.00);
            Transaction sellTransaction4 = new SellTransaction(new DateTime(2009, 08, 01), share, 10, new Price(20.00), 5.00, 3.00);

            List<Transaction> listTransaction = new List<Transaction> { buyTransaction1, sellTransaction1, buyTransaction2, sellTransaction2, buyTransaction3, sellTransaction3, buyTransaction4, sellTransaction4 };

            ShortTermTaxCalculator TaxCalculator = new ShortTermTaxCalculator(listTransaction, new FinYear(2009));

            List<Transaction> listOfValidTransactionsForSTCG = TaxCalculator.GetTransactionBalance();

            Assert.AreEqual(10,listOfValidTransactionsForSTCG[0].Quantity);
        }
Ejemplo n.º 10
0
 public virtual Price CalculateShortTermTaxForAPairOfTransactions(BuyTransaction buyTransaction, SellTransaction sellTransaction)
 {
     return sellTransaction.CalculateShortTermTax(buyTransaction);
 }
Ejemplo n.º 11
0
        public List<Transaction> GetTransactionBalance()
        {
            int leftOverBuys = 0;
            FinYear theYearBefore = new FinYear(YearForStcg.StartYear-1);
            Instrument theBuyInstrument = Transactions[0].Instrument;

            for (int i = 0; i < Transactions.Count;)
            {
                if (Transactions[i].Date.CompareTo(theYearBefore.GetTaxationPeriod().Value.StartDate) > 0)
                {
                    break;
                }
                if (Transactions[i].GetType() == typeof(BuyTransaction))
                 {
                     leftOverBuys += Transactions[i].Quantity;
                     Transactions.Remove(Transactions[i]);

                 }
                else if (Transactions[i].GetType() == typeof(SellTransaction))
                {
                    leftOverBuys -= Transactions[i].Quantity;
                    Transactions.Remove(Transactions[i]);

                }

            }
            BuyTransaction theBuyToAppendToList = new BuyTransaction(new DateTime(2008, 06, 01), theBuyInstrument, leftOverBuys, new Price(0),0, 0);

            if (theBuyToAppendToList.Quantity > 0)
            {
                //             Transactions.Insert(0, theBuyToAppendToList);

                for (int i = 0; i < Transactions.Count;i++)
                {
                    if (Transactions[i].GetType() == typeof (SellTransaction))
                    {
                       leftOverBuys -= Transactions[i].Quantity;
                       if(leftOverBuys<0)
                       {
                           Transactions[i].Quantity = -leftOverBuys;
                           break;
                       }
                       else if(leftOverBuys>0)
                       {
                           Transactions.Remove(Transactions[i]);
                           i--;
                       }
                    }
                }
            }
            return Transactions;
        }