Example #1
0
 def testDrawdown(self):
     dd = series_drawdown(self.TEST_SERIES)
     mx = (core.to_jdate('2014-9-18'), 361)
     mn = (core.to_jdate('2014-12-16'), 321)
     test_dd = drawdown(mx, mn)
     self.assertEqual(dd.max, test_dd.max)
     self.assertEqual(dd.min, test_dd.min)
Example #2
0
def __default_loader(id):
    normalized_id = __normalize_id(id)
    ticker,subject = normalized_id.split('::')
    fname = '{}/TIME_SERIES/{}/{}'.format(os.getenv('HOME'), ticker, subject)
    entries = []
    with open(fname) as f:
        for line in f:
            try:
                pair = line.split()
                entries.append((core.to_jdate(pair[0]),float(pair[1])))
            except:
                pass
    return obs_series.obs_to_series(entries, name=normalized_id)
Example #3
0
def obs_to_series(obs, name=None):
    '''Convert a list of (date,value) tuples to a series.'''

    valids = [(core.to_jdate(ob[0]), ob[1]) for ob in obs if ob]
    valids.sort()
    if not len(valids):
        return core.series(lambda dt: None, name)
    fd = valids[0][0]
    ld = valids[-1][0]
    vec = [None for x in range(fd, ld + 1)]
    for (dt, val) in valids:
        vec[dt - fd] = val
    return core.vector_series(vec, fd, name=name)
Example #4
0
 def __init__(self, date, holdings):
     if not is_list_of(holdings, Holding):
         raise Exception(
             "second argument to Allocation should be list of Portion")
     self.date = core.to_jdate(date)
     self.holdings = holdings
Example #5
0
 def __init__(self, date, portions):
     if not is_list_of(portions, Portion):
         raise Exception(
             "second argument to Allocation should be list of Portion")
     self.date = core.to_jdate(date)
     self.portions = portions
Example #6
0
 def testLastOb(self):
     self.assertEqual(
         last_ob(self.TEST_SERIES)[0], core.to_jdate('2014-12-31'))
Example #7
0
 def testFirstOb(self):
     self.assertEqual(
         first_ob(self.TEST_SERIES)[0], core.to_jdate('2012-1-3'))
Example #8
0
 def testMax(self):
     ob = max_ob(self.TEST_SERIES)
     self.assertEqual(ob[0], core.to_jdate('2014-9-18'))
Example #9
0
 def testMin(self):
     ob = min_ob(self.TEST_SERIES)
     self.assertEqual(ob[0], core.to_jdate('2012-1-13'))