示例#1
0
文件: models.py 项目: suminb/finance
 def daily_net_worth(self, date_from, date_to, granularity=Granularity.day):
     """NOTE: This probably shouldn't be here, but we'll leave it here for
     demonstration purposes.
     """
     # FIXME: Calculate the daily net worth incrementally
     for date in date_range(date_from, date_to):
         yield date, self.net_worth(date)
示例#2
0
 def daily_net_worth(self, date_from, date_to, granularity=Granularity.day):
     """NOTE: This probably shouldn't be here, but we'll leave it here for
     demonstration purposes.
     """
     # FIXME: Calculate the daily net worth incrementally
     for date in date_range(date_from, date_to):
         yield date, self.net_worth(date)
示例#3
0
def test_date_range():
    start, end = parse_date("2016-01-01"), parse_date("2016-01-15")
    r = date_range(start, end)
    assert isinstance(r, types.GeneratorType)

    r = list(r)
    assert 14 == len(r)
    assert r[0] == parse_date("2016-01-01")
    assert r[13] == parse_date("2016-01-14")
示例#4
0
def test_date_range():
    start, end = make_date('2016-01-01'), make_date('2016-01-15')
    r = date_range(start, end)
    assert isinstance(r, types.GeneratorType)

    r = list(r)
    assert 14 == len(r)
    assert r[0] == make_date('2016-01-01')
    assert r[13] == make_date('2016-01-14')
示例#5
0
def test_date_range_relative(start, end, count):
    r = date_range(start, end)

    try:
        prev_date = next(r)
    except StopIteration:
        n = 0
    else:
        n = 1

    for date in r:
        assert prev_date < date
        n += 1

    assert n == count
示例#6
0
 def gen(start, end):
     for date in date_range(start, end):
         log.info('Calculating net worth on {}', date)
         nw = portfolio.net_worth(date)
         v = float(nw)
         yield date.strftime('%Y%m%d'), v, v, v, v, 0
示例#7
0
def test_date_range_exceptions(start, end):
    with pytest.raises(ValueError):
        list(date_range(start, end))

    with pytest.raises(NotImplementedError):
        list(date_range(start, end, 2))
示例#8
0
 def gen(start, end):
     for date in date_range(start, end):
         log.info('Calculating net worth on {}', date)
         nw = portfolio.net_worth(date)
         v = float(nw)
         yield date.strftime('%Y%m%d'), v, v, v, v, 0