Skip to content

Commit

Permalink
added test for algo.CorporateActions
Browse files Browse the repository at this point in the history
  • Loading branch information
danilogalisteu committed Sep 22, 2024
1 parent 2af27b5 commit 8206424
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,3 +2302,42 @@ def test_hedge_risk_pseudo_over():
assert c1.position == 100
assert c2.position == -5
assert c3.position == -5


def test_corporate_actions():
dts = pd.date_range("2010-01-01", periods=3)

data = pd.DataFrame(index=dts, columns=["c1", "c2"], data=100)
divs = pd.DataFrame(index=dts, columns=["c1", "c2"], data=0.0)
divs.loc[dts[1], "c1"] = 2.0
splits = pd.DataFrame(index=dts, columns=["c1", "c2"], data=1.0)
splits.loc[dts[2], "c2"] = 10.0

algo = algos.CorporateActions(divs, splits)

s = bt.Strategy("s", children=["c1", "c2"])
s.setup(data)
s.adjust(20000)

s.update(dts[0])
s.allocate(10000, "c1", update=True)
s.allocate(10000, "c2", update=True)

assert algo(s)
assert s.capital == 0
assert s["c1"].position == 100
assert s["c2"].position == 100

s.update(dts[1])

assert algo(s)
assert s.capital == 100 * 2.0
assert s["c1"].position == 100
assert s["c2"].position == 100

s.update(dts[2])

assert algo(s)
assert s.capital == 100 * 2.0
assert s["c1"].position == 100
assert s["c2"].position == 100 * 10.0

0 comments on commit 8206424

Please sign in to comment.