Exemple #1
0
 public Transaction(DateTime date, Instrument instrument, int quantity, Price unitPrice)
 {
     this.Quantity = quantity;
     this.Instrument = instrument;
     this.Date = date;
     this.UnitPrice = unitPrice;
 }
Exemple #2
0
 public void ShouldBeAbleToUpdateInstrumentCurrentPrice()
 {
     Instrument instrument = new MutualFund(new Symbol("SUN"), new Price(1000), "Sun MF", "SUNMF", "SUN Magma", "Growth");
     var four = new Price(4);
     instrument.UpdateCurrentPrice(four);
     Assert.AreEqual(four, instrument.CurrentPrice);
 }
Exemple #3
0
 public SellTransaction(DateTime date, Instrument instrument, int quantity, Price amount, double tax,
                        double brokerage)
     : base(date, instrument, quantity, amount)
 {
     this.Tax = tax;
     this.Brokerage = brokerage;
 }
Exemple #4
0
        public void ShouldPersistMutualFund()
        {
            var fourThousand = new Price(4000);

            Instrument instrument = new MutualFund(new Symbol("SUN"), fourThousand, "Sun MF", "SUNMF", "SUN Magma", "Growth");
            repository.Save(instrument);
            var lookedUpObject = repository.Lookup<Instrument>(instrument.Id);
            Assert.AreEqual(new Price(4000), lookedUpObject.CurrentPrice);
        }
Exemple #5
0
        public void ShouldDeleteMutualFund()
        {
            var fourThousand = new Price(4000);

            Instrument instrument = new MutualFund(new Symbol("SUN"), fourThousand, "Sun MF", "SUNMF", "SUN Magma", "Growth");
            repository.Delete(instrument);
            var lookedUpObject = repository.Lookup<Instrument>(instrument.Id);
            Assert.IsNull(lookedUpObject);
        }
Exemple #6
0
        public void ShouldBeAbleToGiveCompoundInterestForDepositTransaction()
        {
            Price deposit = new Price(10000);
            TermDeposit termDeposit = new TermDeposit(new Term(4), deposit, new Symbol("CITI"), "Term Deposit", new InterestRate(10), 24);
            Transaction termDepositTransaction = new TermDepositTransaction(new DateTime(2006, 11, 6), termDeposit, new Price(10000.00));

            double noOfYears = ((double)DateTime.Now.Subtract(new DateTime(2006, 11, 6)).Days) / 365;
            double expectedAmount = Math.Round((deposit.GetEffectiveReturn(noOfYears, 0.1).Value), 2);

            Assert.AreEqual(Math.Round(expectedAmount), termDepositTransaction.Amount().Value);
        }
Exemple #7
0
        public Price CurrentMarketValue()
        {
            IList<Symbol> symbolList = Repository.ListAllSymbols<Symbol>();

            Price portfolioPrice = new Price(0.0);

            foreach (Symbol symbol in symbolList)
            {
                portfolioPrice.Value += CurrentMarketValue(symbol).Value;
            }

            return portfolioPrice;
        }
Exemple #8
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);
        }
Exemple #9
0
        public virtual Price CurrentMarketValue(IList<Transaction> transactions)
        {
            Price CurrentPrice = this.CurrentPrice;
            Price value = new Price(0.0);
            int count = 0;

            foreach (Transaction trans in transactions)
            {
                count += trans.EffectiveTransactionQuantity();
            }

            value.Value = count * CurrentPrice.Value;
            return value;
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        public void TestListAllSymbols()
        {
            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);

            IList<Symbol> list = repository.ListAllSymbols<Symbol>();

            Assert.AreEqual(1,list.Count);
            Assert.AreEqual("RELTICK",list[0].Value);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        public void TestLookupAfterSave()
        {
            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);

            var actual = repository.Lookup<Instrument>(instrument.Id);

            Assert.AreEqual(typeof(MutualFund), actual.GetType());

            Instrument expectedMutualFund = new MutualFund(relianceMutuals, hundredRuppees, "Test Fund", "SUNMF", "SUN Magma", "Growth")
                                                {Id = actual.Id};
            Assert.AreEqual(expectedMutualFund, actual);
            Assert.AreNotEqual(0, instrument.Id);
            Assert.True(instrument.Id > 0);
        }
Exemple #14
0
        public void ShouldBeAbleToGiveCurrentMarketValueForPeriodicPayoutTermDeposit()
        {
            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), 24);
            Transaction termDepositTransaction = new TermDepositTransaction(new DateTime(2006, 11, 6), termDeposit, new Price(10000.00));
            Transaction termDepositWithdrawalTransaction = new TermDepositWithdrawalTransaction(new DateTime(2008, 11, 6), termDeposit, new Price(2100.0));

            IList<Transaction> transactionCollection = new List<Transaction>() { termDepositTransaction, termDepositWithdrawalTransaction };

            double noOfYears = ((double)DateTime.Now.Subtract(new DateTime(2006, 11, 6)).Days) / 365;
            double depositAmountWithInterest = Math.Round((depositPrice.GetEffectiveReturn(noOfYears, 0.1).Value), 2);

            noOfYears = ((double)DateTime.Now.Subtract(new DateTime(2008, 11, 6)).Days) / 365;
            double withDrawAmountWithInterest = Math.Round((withdrawalPrice.GetEffectiveReturn(noOfYears, 0.1).Value), 2);

            Assert.AreEqual(Math.Round(depositAmountWithInterest - withDrawAmountWithInterest), termDeposit.CurrentMarketValue(transactionCollection).Value);
        }
Exemple #15
0
        public void ShouldBeAbleToGiveCurrentMarketValueForMaturedSinglePayoutTermDeposit()
        {
            Price depositPrice = new Price(10000);
            TermDeposit termDeposit = new TermDeposit(new Term(2), 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));
            Transaction termDepositWithdrawalTransaction =
                new TermDepositWithdrawalTransaction(new DateTime(2008, 11, 6), termDeposit, new Price(12100));

            IList<Transaction> transactionCollection = new List<Transaction>() { termDepositTransaction, termDepositWithdrawalTransaction };
            transactionCollection.Add(termDepositTransaction);
            transactionCollection.Add(termDepositWithdrawalTransaction);

            Console.WriteLine(termDepositTransaction.Amount().Value);
            Console.WriteLine(termDepositWithdrawalTransaction.EffectiveTransactionAmount().Value);

            Assert.AreEqual(0, termDeposit.CurrentMarketValue(transactionCollection).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;
        }
Exemple #17
0
 public void ShouldBeMaturedSinglePayoutTermDeposit()
 {
     Price depositPrice = new Price(10000);
     TermDeposit termDeposit = new TermDeposit(new Term(1), new Price(10000), new Symbol("CITI"),
                                                  "Term Deposit", new InterestRate(10), -1);
     Transaction termDepositTransaction = new TermDepositTransaction(new DateTime(2007, 11, 6), termDeposit,
                                                                    new Price(10000));
     Assert.AreEqual(true, termDeposit.IsMatured());
 }
Exemple #18
0
 public virtual CashDividendTransaction CreateDividendTransaction(Price price,DateTime transactionDate)
 {
     return new CashDividendTransaction(this, price, transactionDate);
 }
 public DividendTransaction(Instrument instrument, Price dividendAmount, DateTime transactionDate)
     : base(transactionDate, instrument, 0,dividendAmount)
 {
 }
Exemple #20
0
 private double CalculateTotalPrice(Price unitPrice, int quantity)
 {
     return unitPrice.Value*quantity;
 }
Exemple #21
0
 public TermDeposit(Term term, Price investedAmount,
                     Symbol symbol, string description,
                     InterestRate interestRate, int interestPayoutFrequency)
     : base(symbol, investedAmount, description)
 {
     Term = term;
     InterestRate = interestRate;
     InvestedAmount = investedAmount;
     InterestPayoutFrequency = interestPayoutFrequency;
     Validate();
 }
 public TermDepositWithdrawalTransaction(DateTime dateTime, TermDeposit instrument, Price price)
     : base(dateTime, instrument, 0, price)
 {
 }
Exemple #23
0
 public Net(Price profit, int quantity)
 {
     Profit = profit;
     Quantity = quantity;
 }
Exemple #24
0
        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));
        }
Exemple #25
0
 public Stock(Symbol symbol, Price currentPrice, string description)
     : base(symbol, currentPrice, description)
 {
 }
Exemple #26
0
        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));
        }
Exemple #27
0
        public override double CalculateRealizedProfits(ITransactionCollection listOfTransactions)
        {
            Price realizedProfit = new Price(0);
            foreach (Transaction transaction in listOfTransactions.TransactionList)
            {
                realizedProfit += transaction.EffectiveTransactionAmount();
            }

            return realizedProfit.Value;
        }
 public CashDividendTransaction(Instrument instrument, Price dividendAmount, DateTime transactionDate)
     : base(instrument, dividendAmount, transactionDate)
 {
 }
 public TermDepositTransaction(DateTime dateTime, TermDeposit instrument, Price price)
     : base(dateTime, instrument, 0, price)
 {
     instrument.DepositDate = new DepositDate(dateTime);
 }
Exemple #30
0
        public override Price CurrentMarketValue(IList<Transaction> transactions)
        {
            Price price = new Price(0);

            foreach (Transaction transaction in transactions)
            {
                price += transaction.Amount();
            }

            return price;
        }