Пример #1
0
    def setUpClass(cls):
        cls.writer = writer("tmp_J32JFASDK", host="mongo")
        cls.reader = reader("tmp_J32JFASDK", host="mongo")

        # write assets into test database. Writing is slow!
        cls.writer.update_assets(frame=read_frame("price.csv", parse_dates=True))
        cls.writer.update_symbols(frame=read_frame("symbols.csv"))
        cls.writer.update_portfolio("test", test_portfolio(), group="test")
Пример #2
0
    def setUpClass(cls):
        cls.writer = writer("tmp_JKJFDAFJJKFD", host="mongo")
        cls.reader = reader("tmp_JKJFDAFJJKFD", host="mongo")

        # write assets into test database. Writing is slow!
        assets = read_frame("price.csv", parse_dates=True)

        for asset in assets:
            cls.writer.update_asset(asset, assets[asset])

        frame = read_frame("symbols.csv")
        cls.writer.update_symbols(frame)

        p = test_portfolio()
        cls.writer.update_portfolio("test", p, group="test", comment="test")
Пример #3
0
 def test_transaction_report(self):
     x = test_portfolio()
     p1 = x.iron_threshold(threshold=0.05)
     y = p1.transaction_report()
     yy = read_frame("report.csv", index_col=[0, 1])
     yy.index.names = [None, None]
     pdt.assert_frame_equal(y, yy)
Пример #4
0
    def test_build(self):
        prices = read_frame("price.csv")
        weights = pd.DataFrame(index=prices.index, data=0.1, columns=prices.keys())
        portfolio = Portfolio(prices, weights)

        # self.assertEqual(portfolio.index[0], pd.Timestamp('2013-01-01'))
        self.assertAlmostEqual(portfolio.weights["B"][pd.Timestamp('2013-01-08')], 0.1, places=5)
Пример #5
0
    def test_dcc(self):
        frame = read_frame(name="price_data.csv")
        vola = volatility(prices=frame)
        volaAdj = volatility_adj_returns(prices=frame, volatility=vola)

        dcc = DCC(volAdjReturns=volaAdj)
        mat = dcc[pd.Timestamp("2013-10-09")]
        self.assertAlmostEqual(mat["G"]["A"], 0.094022481720826195, places=10)
Пример #6
0
    def test_portfolio(self):
        portfolio = test_portfolio()
        self.writer.update_symbols(frame=read_frame("symbols.csv", parse_dates=False))
        self.writer.update_portfolio("test", portfolio, "test-group")
        # self.archive.update_portfolio("test", portfolio, "test-group", n=10)
        g = self.reader.portfolios["test"]

        pdt.assert_frame_equal(portfolio.prices, g.prices)
        pdt.assert_frame_equal(portfolio.weights, g.weights)
Пример #7
0
    def test_master(self):

        con = Configuration(self.writer, t0=pd.Timestamp("2013-01-01"))
        self.assertEqual(con.name, "test")
        self.assertEquals(con.group, "testgroup")
        p = con.prices(assets=["A","B"])
        pdt.assert_frame_equal(p[["A","B"]], read_frame("price.csv")[["A","B"]].truncate(before=pd.Timestamp("2013-01-01")), check_less_precise=True)

        portfolio=con.portfolio()
        self.assertAlmostEquals(portfolio.nav.statistics.sharpe, -0.017204147680543617, places=5)
Пример #8
0
 def test_table(self):
     s = read_series("ts.csv", parse_dates=True)
     pdt.assert_almost_equal(
         monthlytable(s), read_frame("monthtable.csv", parse_dates=False))
Пример #9
0
 def test_monthlytable(self):
     f = 100 * monthlytable(ts)
     f = f[f.index >= 2008]
     pdt.assert_frame_equal(f, read_frame("month.csv", parse_dates=False))
Пример #10
0
 def setUpClass(cls):
     cls.assets = read_frame("price.csv")
Пример #11
0
 def test_csv(self):
     reader = CsvArchive()
     reader.put(name="price", frame=read_frame("price.csv", parse_dates=True))
     a=reader.history(["A","B","C"], name="price", before=pd.Timestamp("2014-01-01"))
     self.assertAlmostEqual(a["A"][pd.Timestamp("2014-01-01")], 1200.90, places=6)
Пример #12
0
 def test_portfolio(self):
     prices = read_frame("price_data.csv")
     cashpos = pd.DataFrame(index=prices.index, columns=prices.columns, data=50000)
     portfolio = Portfolio(prices=prices, cashPos=cashpos, size=1e6)
     self.assertAlmostEqual(portfolio.nav.sharpe_ratio(), 0.286338249832, places=10)
Пример #13
0
 def test_frame2html(self):
     x = frame2html(read_frame("price.csv"), name="maffay")
     self.assertTrue(x)
Пример #14
0
    def test_sector_weights(self):
        x = portfolio.sector_weights(pd.Series({"A": "A", "B": "A", "C": "B", "D": "B",
                                                "E": "C", "F": "C", "G": "C"}))

        pdt.assert_frame_equal(x.head(10), read_frame("sector_weights.csv", parse_dates=True))
Пример #15
0
 def setUpClass(cls):
     cls.writer = writer("tmp_ZHJKJFA8", host="mongo")
     cls.writer.update_assets(read_frame("price.csv", parse_dates=True))