Skip to content

Commit be8d930

Browse files
authored
Add experiment multiple algorithms support (#252)
* Add experiment multiple algorithms support * Add experimentation functionality * Fix ohlcv data sources tests * Fix ohlcv data sources tests
1 parent ca22899 commit be8d930

File tree

145 files changed

+10901
-11943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+10901
-11943
lines changed

README.md

Lines changed: 64 additions & 96 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from investing_algorithm_framework import Algorithm
2+
from .strategy import CrossOverStrategy
3+
4+
algorithm = Algorithm()
5+
algorithm.add_strategy(CrossOverStrategy)

examples/expirement/strategy.py renamed to examples/backtest/algorithm/strategy.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
https://tulipindicators.org/ or go directly to the pypi page:
1818
https://pypi.org/project/tulipy/
1919
"""
20-
# Define market data sources
21-
2220
def is_below_trend(fast_series, slow_series):
2321
return fast_series[-1] < slow_series[-1]
2422

@@ -55,6 +53,9 @@ class CrossOverStrategy(TradingStrategy):
5553
"DOT/EUR-ticker"
5654
]
5755
symbols = ["BTC/EUR", "DOT/EUR"]
56+
fast = 9
57+
slow = 50
58+
trend = 100
5859

5960
def apply_strategy(self, algorithm: Algorithm, market_data):
6061

@@ -72,8 +73,8 @@ def apply_strategy(self, algorithm: Algorithm, market_data):
7273
price = ticker_data['bid']
7374

7475
if not algorithm.has_position(target_symbol) \
75-
and is_crossover(fast, slow)\
76-
and not is_above_trend(fast, trend):
76+
and is_crossover(fast, slow) \
77+
and is_above_trend(fast, trend):
7778
algorithm.create_limit_order(
7879
target_symbol=target_symbol,
7980
order_side=OrderSide.BUY,
@@ -84,6 +85,7 @@ def apply_strategy(self, algorithm: Algorithm, market_data):
8485

8586
if algorithm.has_position(target_symbol) \
8687
and is_below_trend(fast, slow):
88+
8789
open_trades = algorithm.get_open_trades(
8890
target_symbol=target_symbol
8991
)

examples/backtest/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pathlib
2+
3+
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY
4+
5+
app = create_app(
6+
config={RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()}
7+
)

examples/expirement/experiment.py renamed to examples/backtest/backtest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
pretty_print_backtest
55

66
from app import app
7+
from algorithm.algorithm import algorithm
8+
from algorithm.data_sources import bitvavo_btc_eur_ohlcv_2h, \
9+
bitvavo_dot_eur_ohlcv_2h, bitvavo_dot_eur_ticker, bitvavo_btc_eur_ticker
10+
11+
12+
app.add_algorithm(algorithm)
13+
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)
14+
app.add_market_data_source(bitvavo_dot_eur_ohlcv_2h)
15+
app.add_market_data_source(bitvavo_btc_eur_ticker)
16+
app.add_market_data_source(bitvavo_dot_eur_ticker)
717

818

919
# Add a portfolio configuration of 400 euro initial balance
@@ -18,10 +28,10 @@
1828
if __name__ == "__main__":
1929
end_date = datetime(2023, 12, 2)
2030
start_date = end_date - timedelta(days=100)
21-
experiment_report, backtest_reports = app.experiment(
31+
backtest_report = app.run_backtest(
32+
algorithm=algorithm,
2233
start_date=start_date,
2334
end_date=end_date,
2435
pending_order_check_interval="2h",
25-
strategies=[]
2636
)
27-
pretty_print_expirement(expirement_report)
37+
pretty_print_backtest(backtest_report)

examples/backtest_expirement/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .algorithm import create_algorithm
2+
3+
4+
__all__ = ["create_algorithm"]

0 commit comments

Comments
 (0)