def test_total3(): port = Portfolio() h0 = Holding(hold0) h1 = Holding(hold1) h2 = Holding(hold2) port.append(h0) port.append(h1) port.append(h2) assert 18099 == port.total(lambda k: k[1] == 'g')
def test_total4(): port = Portfolio() h0 = Holding(hold0) h1 = Holding(hold1) h2 = Holding(hold2) port.append(h0) port.append(h1) port.append(h2) # 0.110908286 0.111018918 0.111240181 for mv mb mg expect = {'mv': .110908286, 'mb': .111018918, 'mg': .111240181} ratio = port.ratio(lambda k: k[0] == 'm') assert len(ratio) == 3 assert pytest.approx(expect['mv']) == ratio['mv'] assert pytest.approx(expect['mb']) == ratio['mb'] assert pytest.approx(expect['mg']) == ratio['mg']
def test_total2(): port = Portfolio() h0 = Holding(hold0) h1 = Holding(hold1) h2 = Holding(hold2) port.append(h0) port.append(h1) port.append(h2) subp = port.sub_port(lambda h: h['ticker'] == 'DFEOX' or h['ticker'] == 'DFEVX') assert h0.total() + h1.total() == subp.total()
def test_total1(): port = Portfolio() h0 = Holding(hold0) h1 = Holding(hold1) port.append(h0) port.append(h1) assert h0.total() + h1.total() == port.total()
def csv_to_port(filename): # ignore the first row, and all rows after the # appears row_type = Enum('row_type', 'init, port, ignore') this_row = row_type.init port = Portfolio() with open(filename) as fil: csv_reader = csv.DictReader(fil, all_titles) titles = csv_reader.fieldnames # print(titles) for row in csv_reader: if this_row == row_type.init: this_row = row_type.port elif row['ticker'] == "#": this_row = row_type.ignore # print(row) elif this_row == row_type.port: holding = Holding(row) port.append(holding) return port
def make_a_holding(row): return Holding(row)
def test_total0(): holding = Holding(hold0) assert 9078 == holding.total()
def test_total3(): holding = Holding(hold0) assert 3033 == holding.total(lambda k: k[1] == 'g')
def test_total2(): holding = Holding(hold2) assert 9049 == holding.total(lambda k: k[0] == 'l')
def test_total1(): holding = Holding(hold1) assert 2007 == holding.total(lambda k: k == 'mb')
def test_total0(): port = Portfolio() h0 = Holding(hold0) port.append(h0) assert h0.total() == port.total()