Exemple #1
0
 def test_sell(self):
     """ Test sales """
     stock_data = StockData()
     t1 = Transaction(5, 2.5)
     cost = stock_data.apply_transaction(t1)
     self.assertEqual(cost, 12.5)
     t2 = Transaction(-2, 3.2)
     cost = stock_data.apply_transaction(t2)
     self.assertEqual(cost, -6.4)
     self.assertEqual(stock_data.holding, 3)
     self.assertEqual(stock_data.transactions, [t1, t2])
Exemple #2
0
 def test_sorted_holdings_value(self):
     """ Test get_sorted_holdings_value """
     stock_data = StockData()
     ts = [Transaction(4, 2.5, date=self.get_today(-4)),  # 2.5, 2.5, 2.5, 2.5
           Transaction(-2, 3.2, date=self.get_today(-3)), # 2.5, 2.5 
           Transaction(1, 3.0, date=self.get_today(-2)),  # 2.5, 2.5, 3.0
           Transaction(2, 2.6, date=self.get_today(-1)),  # 2.5, 2.5, 2.6, 2.6, 3.0
           Transaction(-3, 2.9, date=self.get_today(0))]  # 2.6, 3.0
     for t in ts:
         stock_data.apply_transaction(t)
         
     # Total holding should be 5.6
     self.assertEqual(stock_data.holding, 2)
     self.assertEqual(stock_data.transactions, ts)
     self.assertEqual(stock_data.sorted_holdings_value(), 5.6)
Exemple #3
0
 def test_buy(self):
     """ Test purchases """
     stock_data = StockData()
     t1 = Transaction(2, 3.0)
     cost = stock_data.apply_transaction(t1)
     self.assertEqual(cost, 6.0)
     self.assertEqual(stock_data.holding, 2)
     self.assertEqual(stock_data.transactions, [t1])