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)
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)
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)
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
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
def testLastOb(self): self.assertEqual( last_ob(self.TEST_SERIES)[0], core.to_jdate('2014-12-31'))
def testFirstOb(self): self.assertEqual( first_ob(self.TEST_SERIES)[0], core.to_jdate('2012-1-3'))
def testMax(self): ob = max_ob(self.TEST_SERIES) self.assertEqual(ob[0], core.to_jdate('2014-9-18'))
def testMin(self): ob = min_ob(self.TEST_SERIES) self.assertEqual(ob[0], core.to_jdate('2012-1-13'))