Ejemplo n.º 1
0
 def test_two_similar_lots(self):
     # There are two lots that have the same values, but were bought
     # separately.
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lots = lots_lib.Lots([lot1, lot2])
     self.assertSameLot(lot2, wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 2
0
 def test_replacement_is_first_bought(self):
     lots = lots_lib.Lots([
         self.first_gain, self.first_gain_earlier_sale,
         self.first_gain_later_sale
     ])
     self.assertSameLot(self.first_gain_earlier_sale,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 3
0
 def test_two_similar_lots(self):
     # There are two lots that have the same values, but were bought
     # separately.
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lots = lots_lib.Lots([lot1, lot2])
     self.assertSameLot(lot2, wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 4
0
 def test_two_lots_from_same_buy_lot(self):
     # There are two lots that have the same values, and were bought
     # together.
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot1.buy_lot = '1'
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2.buy_lot = '1'
     lots = lots_lib.Lots([lot1, lot2])
     self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 5
0
 def test_two_lots_from_same_buy_lot(self):
     # There are two lots that have the same values, and were bought
     # together.
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot1.buy_lot = '1'
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2.buy_lot = '1'
     lots = lots_lib.Lots([lot1, lot2])
     self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 6
0
    def test_replacement_for_large_loss(self):
        lots = lots_lib.Lots([self.unsold, self.first_gain, self.large_loss])
        final_lots = copy.deepcopy(lots)
        wash_lot = wash.best_replacement_lot(self.large_loss, lots)
        self.assertSameLot(self.first_gain, wash_lot)
        self.assertEqual(10, wash_lot.num_shares)
        self.assertEqual(3, lots.size())

        lots.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_original_buy_date))
        final_lots.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_original_buy_date))
        self.assertSameLots(lots, final_lots)
Ejemplo n.º 7
0
    def test_replacement_for_large_loss(self):
        lots = lots_lib.Lots([self.unsold, self.first_gain, self.large_loss])
        final_lots = copy.deepcopy(lots)
        wash_lot = wash.best_replacement_lot(self.large_loss, lots)
        self.assertSameLot(self.first_gain, wash_lot)
        self.assertEqual(10, wash_lot.num_shares)
        self.assertEqual(3, lots.size())

        lots.sort(cmp=lots_lib.Lot.cmp_by_original_buy_date)
        final_lots.sort(cmp=lots_lib.Lot.cmp_by_original_buy_date)
        self.assertSameLots(lots, final_lots)
Ejemplo n.º 8
0
 def test_replacement_30_days_after(self):
     lots = lots_lib.Lots([self.days_after_30])
     self.assertSameLot(self.days_after_30,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 9
0
 def test_replacement_30_days_before(self):
     lots = lots_lib.Lots([self.days_early_30])
     self.assertSameLot(self.days_early_30,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 10
0
 def test_no_replacement_31_days_after(self):
     lots = lots_lib.Lots([self.days_after_31])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 11
0
 def test_no_replacement_too_late(self):
     lots = lots_lib.Lots([self.second_gain, self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 12
0
 def test_replacement_for_loss_multiple_options(self):
     lots = lots_lib.Lots([self.loss, self.small_first_gain,
                           self.large_first_gain])
     wash_lot = wash.best_replacement_lot(self.loss, lots)
     self.assertSameLot(self.small_first_gain, wash_lot)
Ejemplo n.º 13
0
 def test_replacement_for_loss_multiple_options(self):
     lots = lots_lib.Lots(
         [self.loss, self.small_first_gain, self.large_first_gain])
     wash_lot = wash.best_replacement_lot(self.loss, lots)
     self.assertSameLot(self.small_first_gain, wash_lot)
Ejemplo n.º 14
0
 def test_replacement_checks_sell_date(self):
     # If there are multiple possible replacements that were bought on the
     # same day, the one with the earlier sell date is chosen.
     lots = lots_lib.Lots([self.unsold, self.first_gain, self.loss])
     self.assertSameLot(self.first_gain,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 15
0
 def test_loss_not_in_lots(self):
     lots = lots_lib.Lots([self.unsold, self.first_gain])
     self.assertSameLot(self.first_gain,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 16
0
 def test_lot_sold_before_loss_is_not_replacement(self):
     lots = lots_lib.Lots([self.loss, self.gain_just_before_loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 17
0
 def test_already_used_replacement_is_not_used_again(self):
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2.is_replacement = True
     lots = lots_lib.Lots([lot1, lot2])
     self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 18
0
 def test_replacement_is_first_bought(self):
     lots = lots_lib.Lots([self.first_gain, self.first_gain_earlier_sale,
                           self.first_gain_later_sale])
     self.assertSameLot(self.first_gain_earlier_sale,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 19
0
 def test_replacement_checks_sell_date(self):
     # If there are multiple possible replacements that were bought on the
     # same day, the one with the earlier sell date is chosen.
     lots = lots_lib.Lots([self.unsold, self.first_gain, self.loss])
     self.assertSameLot(self.first_gain,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 20
0
 def test_loss_not_in_lots(self):
     lots = lots_lib.Lots([self.unsold, self.first_gain])
     self.assertSameLot(self.first_gain,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 21
0
 def test_replacement_is_unsold(self):
     lots = lots_lib.Lots([self.unsold, self.loss])
     self.assertSameLot(self.unsold,
                        wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 22
0
 def test_replacement_is_unsold(self):
     lots = lots_lib.Lots([self.unsold, self.loss])
     self.assertSameLot(self.unsold,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 23
0
 def test_replacement_30_days_after(self):
     lots = lots_lib.Lots([self.days_after_30])
     self.assertSameLot(self.days_after_30,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 24
0
 def test_lot_sold_before_loss_is_not_replacement(self):
     lots = lots_lib.Lots([self.loss, self.gain_just_before_loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 25
0
 def test_replacement_for_small_loss(self):
     lots = lots_lib.Lots([self.unsold, self.first_gain, self.small_loss])
     wash_lot = wash.best_replacement_lot(self.small_loss, lots)
     self.assertSameLot(self.first_gain, wash_lot)
Ejemplo n.º 26
0
 def test_replacement_30_days_before(self):
     lots = lots_lib.Lots([self.days_early_30])
     self.assertSameLot(self.days_early_30,
                         wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 27
0
 def test_only_loss_lot_exists(self):
     lots = lots_lib.Lots([self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 28
0
 def test_replacement_for_small_loss(self):
     lots = lots_lib.Lots([self.unsold, self.first_gain, self.small_loss])
     wash_lot = wash.best_replacement_lot(self.small_loss, lots)
     self.assertSameLot(self.first_gain, wash_lot)
Ejemplo n.º 29
0
 def test_no_replacement_too_early(self):
     lots = lots_lib.Lots([self.very_early_gain, self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 30
0
 def test_no_replacement_too_late(self):
     lots = lots_lib.Lots([self.second_gain, self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 31
0
 def test_already_used_replacement_is_not_used_again(self):
     lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110)
     lot2.is_replacement = True
     lots = lots_lib.Lots([lot1, lot2])
     self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
Ejemplo n.º 32
0
 def test_no_replacement_too_early(self):
     lots = lots_lib.Lots([self.very_early_gain, self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 33
0
 def test_only_loss_lot_exists(self):
     lots = lots_lib.Lots([self.loss])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
Ejemplo n.º 34
0
 def test_no_replacement_31_days_after(self):
     lots = lots_lib.Lots([self.days_after_31])
     self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))