Ejemplo n.º 1
0
        public void CanRebalanceWithPositiveOriginalPositionValue()
        {
            double newValue = 123456.78;
            Portfolio orig = new Portfolio
            {
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "gumballs",
                        Amount = 0.0
                    }
                }
            };
            Portfolio recommended = new Portfolio
            {
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "cherries",
                        Amount = 0.0
                    }
                }
            };
            Customer target = new Customer
            {
                OriginalPortfolio = orig,
                RecommendedPortfolio = recommended
            };

            orig.Positions[0].Amount = newValue;

            Assert.IsTrue(target.CanRebalance(), "checking CanRebalance");
        }
Ejemplo n.º 2
0
        public void TotalValueZeroForEmptyPortfolio()
        {
            double expectedAmount = 0.0;
            Portfolio target = new Portfolio();

            Assert.AreEqual(expectedAmount, target.TotalValue);
        }
Ejemplo n.º 3
0
        public void CannotRebalanceWithZeroOriginalPositionValue()
        {
            Portfolio orig = new Portfolio{
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "gumballs",
                        Amount = 0.0
                    }
                }
            };
            Portfolio recommended = new Portfolio
            {
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "cherries",
                        Amount = 0.0
                    }
                }
            };
            Customer target = new Customer
            {
                OriginalPortfolio = orig,
                RecommendedPortfolio = recommended
            };

            Assert.IsFalse(target.CanRebalance(), "checking CanRebalance");
        }
Ejemplo n.º 4
0
        public void OnePosition_TotalValue()
        {
            double expectedAmount = 12345.67;
            Position pos = new Position { SecurityIdentifier = "foo", Amount = expectedAmount };
            Portfolio target = new Portfolio();

            target.Positions.Add(pos);

            Assert.AreEqual(expectedAmount, target.TotalValue);
        }
Ejemplo n.º 5
0
        public void TwoPositions_TotalValue()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            double expectedAmount = posOne.Amount + posTwo.Amount;
            Portfolio target = new Portfolio();

            target.Positions.Add(posOne);
            target.Positions.Add(posTwo);

            Assert.AreEqual(expectedAmount, target.TotalValue);
        }
Ejemplo n.º 6
0
        public void AddingPositionFiresPropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Portfolio target = new Portfolio();
            target.Positions.Add(posOne);

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            target.Positions.Add(posTwo);

            Assert.AreEqual(1, propertyNames.Count(), "checking propertyNames Count");
            Assert.IsTrue(propertyNames.Contains(String.Empty), "checking that propertyNames contains empty string");
        }
Ejemplo n.º 7
0
 public Customer()
 {
     FirstName = "Joe";
     LastName = "Schmoe";
     OriginalPortfolio = new Portfolio
     {
         Positions = new ObservableCollection<Position>
         {
             new Position 
             {
                 SecurityIdentifier = "CASH",
                 Amount = 100000.00
             }
         }
     };
     RecommendedPortfolio = new Portfolio
     {
         Positions = new ObservableCollection<Position>
         {
             new Position 
             {
                 SecurityIdentifier = "247109BR", 
                 Issuer = "DELMARVA POWER AND LIGHT",
                 Coupon="4.00",
                 Maturity="06/01/2042",
                 Amount=20000.00
             },
             new Position 
             {
                 SecurityIdentifier = "369550AT", 
                 Issuer = "GENERAL DYNAMICS CORP",
                 Coupon="3.60",
                 Maturity="11/15/2042",
                 Amount=20000.00
             },
             new Position 
             {
                 SecurityIdentifier = "61746BCY", 
                 Issuer = "MORGAN STANLEY DEAN WITTER",
                 Coupon="5.75",
                 Maturity="11/15/2038",
                 Amount=20000.00
             },
             new Position 
             {
                 SecurityIdentifier = "927804FG", 
                 Issuer = "VIRGINIA ELECTRIC POWER",
                 Coupon="8.875",
                 Maturity="11/15/2038",
                 Amount=20000.00
             },
             new Position 
             {
                 SecurityIdentifier = "931142CM", 
                 Issuer = "WAL-MART STORES",
                 Coupon="6.20",
                 Maturity="04/30/2038",
                 Amount=20000.00
             }
         }
     };
 }
Ejemplo n.º 8
0
        public void RebalancingWithOneRecommendedPosition()
        {
            double newValue = 123456.78;
            Portfolio orig = new Portfolio
            {
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "gumballs",
                        Amount = 0.0
                    }
                }
            };
            Portfolio recommended = new Portfolio
            {
                Positions = new ObservableCollection<Position>{
                    new Position {
                        SecurityIdentifier = "cherries",
                        Amount = 0.0
                    }
                }
            };
            Customer target = new Customer
            {
                OriginalPortfolio = orig,
                RecommendedPortfolio = recommended
            };

            orig.Positions[0].Amount = newValue;
            Assert.IsTrue(target.CanRebalance(), "checking CanRebalance");

            target.DoRebalance();

            Assert.AreEqual(newValue, target.RecommendedPortfolio.TotalValue, "checking recommended total value");
            Assert.AreEqual(newValue, target.RecommendedPortfolio.Positions[0].Amount, "checking recommended position 0 amount");
        }
Ejemplo n.º 9
0
        public void ChangingPositionAmountInOldCollectionDoesNotFirePropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Position posThree = new Position { SecurityIdentifier = "bletch", Amount = 34567.89 };
            ObservableCollection<Position> origPositions = new ObservableCollection<Position>{
                posOne,
                posTwo
            };
            ObservableCollection<Position> newPositions = new ObservableCollection<Position> { posThree };
            Portfolio target = new Portfolio { Positions = origPositions };
            target.Positions = newPositions;

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            posOne.Amount = 45678.90;

            Assert.AreEqual(0, propertyNames.Count(), "checking propertyNames Count");
        }
Ejemplo n.º 10
0
        public void ChangingRemovedPositionDoesNotFirePropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Portfolio target = new Portfolio();
            target.Positions.Add(posOne);
            target.Positions.Add(posTwo);

            target.Positions.Remove(posTwo);

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            posTwo.Amount = 34567.89;

            Assert.AreEqual(0, propertyNames.Count(), "checking propertyNames Count");
        }
Ejemplo n.º 11
0
        public void ReplacingPositionsCollectionFiresPropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Position posThree = new Position { SecurityIdentifier = "bletch", Amount = 34567.89 };
            ObservableCollection<Position> origPositions = new ObservableCollection<Position>{
                posOne,
                posTwo
            };
            ObservableCollection<Position> newPositions = new ObservableCollection<Position> { posThree };
            Portfolio target = new Portfolio { Positions = origPositions };

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            target.Positions = newPositions;

            Assert.AreEqual(1, propertyNames.Count(), "checking propertyNames Count");
            Assert.IsTrue(propertyNames.Contains(String.Empty), "checking that propertyNames contains String.Empty");
        }
Ejemplo n.º 12
0
 public Customer()
 {
     FirstName         = "Joe";
     LastName          = "Schmoe";
     OriginalPortfolio = new Portfolio
     {
         Positions = new ObservableCollection <Position>
         {
             new Position
             {
                 SecurityIdentifier = "CASH",
                 Amount             = 100000.00
             }
         }
     };
     RecommendedPortfolio = new Portfolio
     {
         Positions = new ObservableCollection <Position>
         {
             new Position
             {
                 SecurityIdentifier = "247109BR",
                 Issuer             = "DELMARVA POWER AND LIGHT",
                 Coupon             = "4.00",
                 Maturity           = "06/01/2042",
                 Amount             = 20000.00
             },
             new Position
             {
                 SecurityIdentifier = "369550AT",
                 Issuer             = "GENERAL DYNAMICS CORP",
                 Coupon             = "3.60",
                 Maturity           = "11/15/2042",
                 Amount             = 20000.00
             },
             new Position
             {
                 SecurityIdentifier = "61746BCY",
                 Issuer             = "MORGAN STANLEY DEAN WITTER",
                 Coupon             = "5.75",
                 Maturity           = "11/15/2038",
                 Amount             = 20000.00
             },
             new Position
             {
                 SecurityIdentifier = "927804FG",
                 Issuer             = "VIRGINIA ELECTRIC POWER",
                 Coupon             = "8.875",
                 Maturity           = "11/15/2038",
                 Amount             = 20000.00
             },
             new Position
             {
                 SecurityIdentifier = "931142CM",
                 Issuer             = "WAL-MART STORES",
                 Coupon             = "6.20",
                 Maturity           = "04/30/2038",
                 Amount             = 20000.00
             }
         }
     };
 }