Skip to content

289 include unrealized gains in backtesting result #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ jobs:
fail-fast: true
matrix:
os: [ "ubuntu-latest", "macos-latest" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.9", "3.10", "3.11" ]
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
#----------------------------------------------
Expand Down Expand Up @@ -99,7 +102,7 @@ jobs:
#----------------------------------------------
- name: Run tests
run: |
source .venv/bin/activate
source $VENV
coverage run -m unittest discover -s tests
# #----------------------------------------------
# # upload coverage stats
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Features:
The following algorithm connects to binance and buys BTC every 5 seconds. It also exposes an REST API that allows you to interact with the algorithm.

```python
import logging
import logging.config

from investing_algorithm_framework import create_app, PortfolioConfiguration, \
Expand All @@ -61,7 +60,6 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
symbol="BTC/EUR",
)
app = create_app()
algorithm = Algorithm()
# Bitvavo market credentials are read from .env file
app.add_market_credential(MarketCredential(market="bitvavo"))
app.add_portfolio_configuration(
Expand All @@ -71,18 +69,16 @@ app.add_portfolio_configuration(
initial_balance=400
)
)
app.add_algorithm(algorithm)

# Run every two hours and register the data sources
@algorithm.strategy(
@app.strategy(
time_unit=TimeUnit.HOUR,
interval=2,
market_data_sources=[bitvavo_btc_eur_ticker, bitvavo_btc_eur_ohlcv_2h]
)
def perform_strategy(algorithm: Algorithm, market_data: dict):
# Access the data sources with the indentifier
polars_df = market_data["BTC-ohlcv"]

# Convert the polars dataframe to a pandas dataframe
pandas_df = polars_df.to_pandas()
ticker_data = market_data["BTC-ticker"]
Expand All @@ -93,18 +89,21 @@ def perform_strategy(algorithm: Algorithm, market_data: dict):
closed_trades = algorithm.get_closed_trades()

# Create a buy oder
algorithm.create_limit_order(
order = algorithm.create_limit_order(
target_symbol="BTC/EUR",
order_side="buy",
amount=0.01,
price=ticker_data["ask"],
)
trade = algorithm.get_trade(order_id=order.id)
algorithm.add_trailing_stop_loss(trade=trade, percentage=5)

# Close a trade
algorithm.close_trade(trades[0].id)
algorithm.close_trade(trade=trade)

# Close a position
algorithm.close_position(positions[0].get_symbol())
position = algorithm.get_position(symbol="BTC/EUR")
algorithm.close_position(position)

if __name__ == "__main__":
app.run()
Expand All @@ -116,7 +115,14 @@ if __name__ == "__main__":

The framework also supports backtesting and performing backtest experiments. After a backtest, you can print a report that shows the performance of your trading bot.

To run a single backtest you can use the example code that can be found [here](./examples/backtest).
To run a single backtest you can use the example code that can be found [here](./examples/backtest_example). Simply run:

> Its assumed here that you have cloned the repository, installed the framework and
> are in the root of the project.

```bash
python examples/backtest_example/run_backtest.py
```

### Backtesting report

Expand Down
49 changes: 0 additions & 49 deletions examples/app.py

This file was deleted.

Empty file.
Empty file.
5 changes: 0 additions & 5 deletions examples/backtest_example/algorithm/algorithm.py

This file was deleted.

30 changes: 0 additions & 30 deletions examples/backtest_example/algorithm/data_sources.py

This file was deleted.

108 changes: 0 additions & 108 deletions examples/backtest_example/algorithm/strategy.py

This file was deleted.

11 changes: 0 additions & 11 deletions examples/backtest_example/app.py

This file was deleted.

Loading
Loading