def setUp(self): self.random_portfolio = tools.random_portfolio(n=1000, k=3, mu=0., sd=0.01)
def S(): """ Random portfolio for testing. """ return tools.random_portfolio(n=1000, k=3, mu=0., sd=0.01)
"""Fees for BAH should be equal to 1 * fee.""" FEE = 0.01 result = algos.BAH().run(S) wealth_no_fees = result.total_wealth result.fee = FEE wealth_with_fees = result.total_wealth assert abs(wealth_no_fees * (1 - FEE) - wealth_with_fees) < EPS # CRP def test_crp(S): """Make sure that equity of a portfolio [1,0,...,0] with NaN values is the same as asset itself.""" b = [1.0] + [0.0] * (len(S.columns) - 1) result = algos.CRP(b).run(S) assert abs(result.total_wealth - S[S.columns[0]].iloc[-1]) < EPS def test_tco1(S): """Zero turnover with extremely high fees.""" result = algos.TCO1(eta=1, trx_fee_pct=1e6).run(S) assert abs(result.turnover) < 1e-8 data = tools.random_portfolio(n=1000, k=3, mu=0.0, sd=0.01) result = ONS().run(data) print(result.summary()) result.plot()