public Add ( |
||
transaction | ||
Résultat | bool |
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 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 ShouldUpdateQuantityOnAdditionOfUnitDividend() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); var selectedMutualFund = new MutualFund(null, null, null, "SUNMF", "SUN Magma", "Growth"); ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), selectedMutualFund, 10, new Price(1200), 1000, 0)); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), selectedMutualFund, 5, new Price(1300), 0, 1000)); ts.Add(new UnitDividendTransaction(selectedMutualFund, 2, new DateTime(1999, 5, 20))); int actualQty = 0; foreach (Transaction transaction in ts.TransactionList) { actualQty += transaction.EffectiveTransactionQuantity(); } Assert.AreEqual(7, actualQty); }
public double CalculateRealizedProfits(ITransactionCollection statement, Instrument instrument) { ITransactionCollection instrumentSpecificTransaction = new TransactionCollection(); foreach (Transaction transaction in statement.TransactionList) { if (transaction.Instrument == instrument) { instrumentSpecificTransaction.Add(transaction); } } return instrumentSpecificTransaction.RealizedProfit().Profit.Value; }
public void ShouldIncludeUnitDividendSoldInRealizedProfit() { Portfolio d = new Portfolio(); TransactionCollection ts = new TransactionCollection(); var selectedMutualFund = new MutualFund(null, null, null, "SUNMF", "SUN Magma", "Growth"); int buyUnitPrice = 1200; int buyBrokerage = 100; int sellBrokerage = 100; int buyQuantity = 10; int sellQuantity = 10; ts.Add(new BuyTransaction(new DateTime(1999, 3, 20), selectedMutualFund, buyQuantity, new Price(buyUnitPrice), buyBrokerage, 0)); int sellUnitPrice = 1300; ts.Add(new SellTransaction(new DateTime(1999, 5, 20), selectedMutualFund, 5, new Price(sellUnitPrice), 0, sellBrokerage)); int unitReceived = 2; ts.Add(new UnitDividendTransaction(selectedMutualFund, unitReceived, new DateTime(1999, 5, 20))); ts.Add(new SellTransaction(new DateTime(1999, 5, 20), selectedMutualFund, 7, new Price(sellUnitPrice), 0, sellBrokerage)); Assert.AreEqual((sellUnitPrice - buyUnitPrice) * sellQuantity - buyBrokerage - sellBrokerage + sellUnitPrice * unitReceived - sellBrokerage, d.CalculateRealizedProfits(ts)); }
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 ShouldBeAbleToGiveRealizedProfitForSinglePayoutTermDeposit() { Price depositPrice = new Price(10000); Price withdrawalPrice = new Price(2100); TermDeposit termDeposit = new TermDeposit(new Term(4), new Price(10000), new Symbol("CITI"), "Term Deposit", new InterestRate(10), -1); Transaction termDepositTransaction = new TermDepositTransaction(new DateTime(2006, 11, 6), termDeposit, new Price(10000.00)); ITransactionCollection transactionCollection = new TransactionCollection(); transactionCollection.Add(termDepositTransaction); Assert.AreEqual(0, termDeposit.CalculateRealizedProfits(transactionCollection)); }
public void ShouldBeAbleToGiveRealizedProfitForMaturedSinglePayoutTermDeposit() { Price depositPrice = new Price(10000); Price withdrawalPrice = new Price(2100); TermDeposit termDeposit = new TermDeposit(new Term(2), new Price(10000), new Symbol("CITI"), "Term Deposit", new InterestRate(10), 24); Transaction termDepositTransaction = new TermDepositTransaction(new DateTime(2006, 11, 6), termDeposit, null); Transaction termDepositWithdrawalTransaction = new TermDepositWithdrawalTransaction(new DateTime(2008, 11, 6), termDeposit, new Price(2310)); ITransactionCollection transactionCollection = new TransactionCollection(); transactionCollection.Add(termDepositTransaction); transactionCollection.Add(termDepositWithdrawalTransaction); int noOfYears = DateTime.Now.Subtract(new DateTime(2008, 11, 6)).Days / 365; double withDrawAmountWithInterest = Math.Round((withdrawalPrice.GetEffectiveReturn(noOfYears, 0.1).Value), 2); Assert.AreEqual(withDrawAmountWithInterest, termDeposit.CalculateRealizedProfits(transactionCollection)); }