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 ShouldCalculateRealizedProfitsAtInstrumentLevel() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); Stock relianceShare = new Stock(new Symbol("RIL"), new Price(10.00), "Reliance Industries"); ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), relianceShare, 10, new Price(1200), 0, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), relianceShare, 5, new Price(1300), 0, 0)); Assert.AreEqual(500, d.CalculateRealizedProfits(ts,relianceShare)); }
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 ShouldCalculateRealizedLossesDumbCaseWithoutTaxOrBrokerage() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); Stock relianceShare = new Stock(new Symbol("RIL"), new Price(10.00), "Reliance Industries"); Stock suzlonEnergyShare = new Stock(new Symbol("SUZ"), new Price(1000.00), "Suzlon Energy"); ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), relianceShare, 10, new Price(1300), 0, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), relianceShare, 5, new Price(1200), 0, 0)); Assert.AreEqual(-500, d.CalculateRealizedProfits(ts)); }
public void ShouldCalculateRealizedProfitsComplexCaseWithDateMismatch() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); Stock relianceShare = new Stock(new Symbol("RIL"), new Price(10.00), "Reliance Industries"); ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), relianceShare, 5, new Price(12), 0, 0)); ts.Add(new BuyTransaction(new DateTime(1999, 2, 20), relianceShare, 5, new Price(10), 0, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), relianceShare, 5, new Price(13), 0, 0)); ts.Add(new SellTransaction(new DateTime(1999, 7, 20), relianceShare, 3, new Price(13), 0, 0)); Assert.AreEqual(18, d.CalculateRealizedProfits(ts)); }
public void ShouldCalculateRealizedProfitsAtInstrumentLevelComplexCase() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); Stock relianceShare = new Stock(new Symbol("RIL"), new Price(10.00), "Reliance Industries"); Stock infyShare = new Stock(new Symbol("INF"), new Price(100.00), "Infosys"); ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), relianceShare, 10, new Price(1200), 0, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), relianceShare, 5, new Price(1300), 0, 0)); ts.Add(new BuyTransaction(new DateTime(1999, 8, 20), infyShare, 67, new Price(110), 0, 0)); ts.Add(new SellTransaction(new DateTime(2000, 9, 20), infyShare, 63, new Price(101), 0, 0)); Assert.AreEqual(500, d.CalculateRealizedProfits(ts, relianceShare)); Assert.AreEqual(-567, d.CalculateRealizedProfits(ts, infyShare)); }
public void ShouldCreateCashDividendTransactionForStock() { var firstOfJan2008 = new DateTime(2008, 1, 1); var selectedStock = new Stock(null, null, null); var expectedTransaction = new CashDividendTransaction(selectedStock, new Price(100), firstOfJan2008); CashDividendTransaction actualTransaction = selectedStock.CreateDividendTransaction(new Price(100), firstOfJan2008); Assert.AreEqual(expectedTransaction.Date, actualTransaction.Date); Assert.AreEqual(expectedTransaction.Instrument, actualTransaction.Instrument); Assert.AreEqual(expectedTransaction.Date, actualTransaction.Date); }
public void ShouldBeAbleToCreateSaveAStock() { Price stockUnitPrice = new Price(10.00); Instrument relianceStock = new Stock(new Symbol("REL"), stockUnitPrice, "Reliance Power Stock"); repository.Save(relianceStock); Console.WriteLine(relianceStock.Id); Assert.IsTrue(relianceStock.Id>0); var savedStock = repository.Lookup<Instrument>(relianceStock.Id); Console.WriteLine(savedStock.Id); Assert.AreEqual(relianceStock.Id,savedStock.Id); }
public void ShouldUpdateStockPrice() { var fourThousand = new Price(4000); Instrument instrument = new Stock(new Symbol("SUN"), fourThousand, "Sun MF"); repository.Save(instrument); var lookedUpObject = repository.Lookup<Instrument>(instrument.Id); Assert.AreEqual(new Price(4000), lookedUpObject.CurrentPrice); var newPrice = new Price(2500); instrument.UpdateCurrentPrice(newPrice); lookedUpObject = repository.Lookup<Instrument>(instrument.Id); Assert.AreEqual(new Price(2500), lookedUpObject.CurrentPrice); }
public void ShouldIncludeDividendInRealizedProfit() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); Stock relianceShare = new Stock(new Symbol("RIL"), new Price(10.00), "Reliance Industries"); int buyUnitPrice = 1200; int buyBrokerage = 100; int sellBrokerage = 100; int buyQuantity = 10; int sellQuantity = 5; int sellUnitPrice = 1300; ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), relianceShare, buyQuantity, new Price(buyUnitPrice), buyBrokerage, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), relianceShare, sellQuantity, new Price(sellUnitPrice), 0, sellBrokerage)); int dividend = 50; ts.Add(new CashDividendTransaction(relianceShare,new Price(dividend),new DateTime(1999, 5, 20))); Assert.AreEqual((sellUnitPrice-buyUnitPrice) * sellQuantity - sellBrokerage -buyBrokerage + dividend, d.CalculateRealizedProfits(ts)); }
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); }