示例#1
0
文件: runtests.py 项目: tmmagee/tmess
 def test_quarter_diff(self):
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2012,1,1)), 0)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2012,4,1)), 1)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2012,7,1)), 2)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2012,10,1)), 3)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2013,1,1)), 4)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2013,4,1)), 5)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2013,7,1)), 6)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2013,10,1)), 7)
   self.assertEqual(quarter_diff(datetime(2012,1,1), datetime(2014,1,1)), 8)
   self.assertRaises(ValueError, quarter_diff, datetime(2012,1,1), datetime(2013,10,2))
   self.assertRaises(ValueError, quarter_diff, datetime(2012,1,1), datetime(2013,9,1))
   self.assertRaises(ValueError, quarter_diff, datetime(2012,1,1), False)
   self.assertRaises(ValueError, quarter_diff, False, datetime(2012,1,1))
示例#2
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