Skip to content

Commit

Permalink
added a test for multi assets backtest
Browse files Browse the repository at this point in the history
  • Loading branch information
AxelGard committed Jun 15, 2024
1 parent 7cf6461 commit 23f36b9
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from . import util
import os
import numpy as np
import pandas as pd


def test_iterate():
Expand Down Expand Up @@ -59,4 +60,36 @@ def test_backtest_fees():
resutlt = cira.strategy.back_test(strat, feature_data, prices, 100, use_fees=True)

res = resutlt[strat.name].values.astype(int).tolist()
assert res == [99, 98, 97, 96, 95]
assert res == [99, 98, 97, 96, 95]


def test_backtest_multi_asset_uniform_prices():
feature_data = util.stock_data
strat = cira.strategy.DollarCostAveraging(amount=1)

prices = pd.DataFrame()
prices["ast_1"] = [10, 10, 5, 20, 10]
prices["ast_2"] = [10, 10, 5, 20, 10]
prices["ast_3"] = [10, 10, 5, 20, 10]
prices["ast_4"] = [10, 10, 5, 20, 10]

resutlt = cira.strategy.back_test(strat, feature_data, prices, 40, use_fees=False)

res = resutlt[strat.name].values.astype(int).tolist()
assert res == [40, 40, 20, 80, 40]


def test_backtest_multi_asset():
feature_data = util.stock_data
strat = cira.strategy.DollarCostAveraging(amount=1)

prices = pd.DataFrame()
prices["ast_1"] = [10, 10, 1, 0, 0]
prices["ast_2"] = [10, 11, 5, 0, 0]
prices["ast_3"] = [10, 10, 1, 0, 0]
prices["ast_4"] = [10, 14, 7, 99, 0]

resutlt = cira.strategy.back_test(strat, feature_data, prices, 40, use_fees=False)

res = resutlt[strat.name].values.astype(int).tolist()
assert res == [40, 45, 14, 99, 0]

0 comments on commit 23f36b9

Please sign in to comment.