Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/tqdm-4.66.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MDUYN committed Jul 2, 2024
2 parents e7565ba + d4927f7 commit 1e6bcd8
Show file tree
Hide file tree
Showing 70 changed files with 6,689 additions and 1,031 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude =
investing_algorithm_framework/domain/utils/backtesting.py
examples
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
#----------------------------------------------
- run: python -m pip install black flake8 isort
- run: |
flake8 ./investing_algorithm_framework --exclude="investing_algorithm_framework/domain/utils/backtesting.py"
flake8 ./investing_algorithm_framework
test:
needs: linting
strategy:
Expand Down
101 changes: 60 additions & 41 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__='v3.6.0'
__version__ = 'v3.6.0'
10 changes: 6 additions & 4 deletions examples/backtest_example/algorithm/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from investing_algorithm_framework import TimeUnit, TradingStrategy, \
Algorithm, OrderSide
from .data_sources import bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker, \
bitvavo_dot_eur_ticker, bitvavo_dot_eur_ohlcv_2h

"""
This strategy is based on the golden cross strategy. It will buy when the
Expand Down Expand Up @@ -47,10 +49,10 @@ class CrossOverStrategy(TradingStrategy):
time_unit = TimeUnit.HOUR
interval = 2
market_data_sources = [
"BTC/EUR-ohlcv",
"DOT/EUR-ohlcv",
"BTC/EUR-ticker",
"DOT/EUR-ticker"
bitvavo_dot_eur_ticker,
bitvavo_btc_eur_ticker,
bitvavo_dot_eur_ohlcv_2h,
bitvavo_btc_eur_ohlcv_2h
]
symbols = ["BTC/EUR", "DOT/EUR"]
fast = 21
Expand Down
9 changes: 6 additions & 3 deletions examples/backtest_example/run_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
bitvavo_dot_eur_ohlcv_2h, bitvavo_dot_eur_ticker, bitvavo_btc_eur_ticker
from app import app
from investing_algorithm_framework import PortfolioConfiguration, \
pretty_print_backtest
pretty_print_backtest, BacktestDateRange

app.add_algorithm(algorithm)
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)
Expand All @@ -26,9 +26,12 @@
if __name__ == "__main__":
end_date = datetime(2023, 12, 2)
start_date = end_date - timedelta(days=100)
date_range = BacktestDateRange(
start_date=start_date,
end_date=end_date
)
backtest_report = app.run_backtest(
algorithm=algorithm,
start_date=start_date,
end_date=end_date,
backtest_date_range=date_range,
)
pretty_print_backtest(backtest_report)
16 changes: 6 additions & 10 deletions examples/bitvavo_trading_bot/bitvavo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
create_app, PortfolioConfiguration, Algorithm, SYMBOLS, RESOURCE_DIRECTORY

"""
Bitvavo trading bot example with market data sources of bitvavo.
Bitvavo trading bot example with market data sources of bitvavo.
Bitvavo does not requires you to have an API key and secret key to access
their market data
If you just want to backtest your strategy, you don't need to
add a market credential. If your running your strategy live,
their market data. If you just want to backtest your strategy,
you don't need to add a market credential. If your running your strategy live,
you need to add a market credential to the app, that accesses your
account on bitvavo.
"""


# Define your market credential for bitvavo
bitvavo_market_credential = MarketCredential(
api_key="<your_api_key>",
Expand All @@ -38,10 +38,7 @@
class BitvavoTradingStrategy(TradingStrategy):
time_unit = TimeUnit.HOUR
interval = 2
market_data_sources = [
"BTC/EUR-ohlcv",
"BTC/EUR-ticker"
]
market_data_sources = [bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker]

def apply_strategy(self, algorithm, market_data):
print(market_data["BTC/EUR-ohlcv"])
Expand Down Expand Up @@ -75,4 +72,3 @@ def apply_strategy(self, algorithm, market_data):

if __name__ == "__main__":
app.run()

14 changes: 5 additions & 9 deletions examples/coinbase_trading_bot/coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
and secret key to access their market data. You can create them here:
https://www.coinbase.com/settings/api
You need to add a market credential to the app, and then add market data sources
to the app. You can then use the market data sources in your trading strategy.
You need to add a market credential to the app, and then add market
data sources to the app. You can then use the market data
sources in your trading strategy.
"""
# Define your market credential for coinbase
coinbase_market_credential = MarketCredential(
Expand All @@ -36,22 +37,18 @@
class CoinBaseTradingStrategy(TradingStrategy):
time_unit = TimeUnit.SECOND
interval = 5
market_data_sources = [
"BTC/EUR-ohlcv",
"BTC/EUR-ticker"
]
market_data_sources = [coinbase_btc_eur_ticker, coinbase_btc_eur_ohlcv_2h]

def apply_strategy(self, algorithm, market_data):
pass


config = {
SYMBOLS: ["BTC/EUR"],
RESOURCE_DIRECTORY: os.path.join(os.path.dirname(__file__), "resources")
}

algorithm = Algorithm()
algorithm.add_strategy(CoinBaseTradingStrategy)

app = create_app(config=config)
app.add_algorithm(algorithm)
app.add_market_credential(coinbase_market_credential)
Expand All @@ -65,4 +62,3 @@ def apply_strategy(self, algorithm, market_data):

if __name__ == "__main__":
app.run()

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from investing_algorithm_framework import TimeUnit, TradingStrategy, \
Algorithm, OrderSide
from .data_sources import bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker, \
bitvavo_dot_eur_ticker, bitvavo_dot_eur_ohlcv_2h


"""
This strategy is based on the golden cross strategy. It will buy when the
Expand Down Expand Up @@ -49,10 +52,10 @@ class CrossOverStrategy(TradingStrategy):
time_unit = TimeUnit.HOUR
interval = 2
market_data_sources = [
"BTC/EUR-ohlcv",
"DOT/EUR-ohlcv",
"BTC/EUR-ticker",
"DOT/EUR-ticker"
bitvavo_dot_eur_ticker,
bitvavo_dot_eur_ohlcv_2h,
bitvavo_btc_eur_ticker,
bitvavo_btc_eur_ohlcv_2h
]
symbols = ["BTC/EUR", "DOT/EUR"]

Expand Down
9 changes: 6 additions & 3 deletions examples/crossover_moving_average_trading_bot/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
bitvavo_dot_eur_ohlcv_2h, bitvavo_dot_eur_ticker, bitvavo_btc_eur_ticker
from app import app
from investing_algorithm_framework import PortfolioConfiguration, \
pretty_print_backtest
pretty_print_backtest, BacktestDateRange

app.add_algorithm(algorithm)
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)
Expand All @@ -26,10 +26,13 @@
if __name__ == "__main__":
end_date = datetime(2023, 12, 2)
start_date = end_date - timedelta(days=100)
date_range = BacktestDateRange(
start_date=start_date,
end_date=end_date
)
backtest_report = app.run_backtest(
algorithm=algorithm,
start_date=start_date,
end_date=end_date,
backtest_date_range=date_range,
pending_order_check_interval="2h",
)
pretty_print_backtest(backtest_report)
9 changes: 7 additions & 2 deletions investing_algorithm_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
TickerMarketDataSource, MarketService, BacktestReportsEvaluation, \
pretty_print_backtest_reports_evaluation, load_backtest_reports, \
RESERVED_BALANCES, APP_MODE, AppMode, DATETIME_FORMAT, \
load_backtest_report, BacktestDateRange
load_backtest_report, BacktestDateRange, create_ema_graph, \
create_prices_graph, create_rsi_graph, get_price_efficiency_ratio
from investing_algorithm_framework.infrastructure import \
CCXTOrderBookMarketDataSource, CCXTOHLCVMarketDataSource, \
CCXTTickerMarketDataSource, CSVOHLCVMarketDataSource, \
Expand Down Expand Up @@ -67,5 +68,9 @@
"load_backtest_report",
"BacktestDateRange",
"create_trade_exit_markers_chart",
"create_trade_entry_markers_chart"
"create_trade_entry_markers_chart",
"create_ema_graph",
"create_prices_graph",
"create_rsi_graph",
"get_price_efficiency_ratio"
]
3 changes: 2 additions & 1 deletion investing_algorithm_framework/app/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class is responsible for managing the strategies and executing
:param (optional) name: The name of the algorithm
:param (optional) description: The description of the algorithm
:param (optional) context: The context of the algorithm, for backtest references
:param (optional) context: The context of the algorithm,
for backtest references
:param (optional) strategy: A single strategy to add to the algorithm
:param (optional) data_sources: The list of data sources to
add to the algorithm
Expand Down
Loading

0 comments on commit 1e6bcd8

Please sign in to comment.