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); }
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); }
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); }
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; }
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); }
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()); }
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); }
public virtual Price CalculateShortTermTaxForAPairOfTransactions(BuyTransaction buyTransaction, SellTransaction sellTransaction) { return sellTransaction.CalculateShortTermTax(buyTransaction); }