ShareKhan.domain.Portfolio.CalculateRealizedProfits C# (CSharp) Method

CalculateRealizedProfits() public method

public CalculateRealizedProfits ( ITransactionCollection listOfTransactions ) : double
listOfTransactions ITransactionCollection
return double
        public double CalculateRealizedProfits(ITransactionCollection listOfTransactions)
        {
            ISet<Instrument> instruments = listOfTransactions.GetAllUniqueInstruments();
            double realizedProfits = 0;
            foreach (Instrument instrument in instruments)
            {
                realizedProfits += CalculateRealizedProfits(listOfTransactions, instrument);
            }

            return realizedProfits;
        }

Same methods

Portfolio::CalculateRealizedProfits ( ITransactionCollection statement, Instrument instrument ) : double

Usage Example

Example #1
0
 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));
 }
All Usage Examples Of ShareKhan.domain.Portfolio::CalculateRealizedProfits