Ejemplo n.º 1
0
    def calc_real_equity_increment(self, equity_increment, equity_held, equity_target, date_joined):
      quarter_joined = round_to_quarter(date_joined)  
      current_quarter = round_to_quarter(datetime.datetime.today())
      quarters = quarter_diff(current_quarter, quarter_joined)
      on_track_equity = min(equity_increment * quarters, equity_target)

      if (equity_held >= on_track_equity):
        return Decimal(0)
      elif (on_track_equity - equity_held) < equity_increment:
        return on_track_equity - equity_held
      else:
        return equity_increment
Ejemplo n.º 2
0
 def test_round_to_quarter(self):
   self.assertEqual(round_to_quarter(datetime(2012,1,1)), datetime(2012,1,1))
   self.assertEqual(round_to_quarter(datetime(2012,2,1)), datetime(2012,1,1))
   self.assertEqual(round_to_quarter(datetime(2012,3,1)), datetime(2012,4,1))
   self.assertEqual(round_to_quarter(datetime(2012,4,1)), datetime(2012,4,1))
   self.assertEqual(round_to_quarter(datetime(2012,5,1)), datetime(2012,4,1))
   self.assertEqual(round_to_quarter(datetime(2012,6,1)), datetime(2012,7,1))
   self.assertEqual(round_to_quarter(datetime(2012,7,1)), datetime(2012,7,1))
   self.assertEqual(round_to_quarter(datetime(2012,8,1)), datetime(2012,7,1))
   self.assertEqual(round_to_quarter(datetime(2012,9,1)), datetime(2012,10,1))
   self.assertEqual(round_to_quarter(datetime(2012,10,1)), datetime(2012,10,1))
   self.assertEqual(round_to_quarter(datetime(2012,11,1)), datetime(2012,10,1))
   self.assertEqual(round_to_quarter(datetime(2012,12,1)), datetime(2013,1,1))
   self.assertRaises(ValueError, round_to_quarter, False)