Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
9d1605b
feat: allow cors origin all
dev-abuke Jun 25, 2024
bcac714
fix: backtesting import errors
dev-abuke Jun 25, 2024
0f066e7
fix: space in the files of backtest
dev-abuke Jun 25, 2024
4474aec
feat: add logging to backend
dev-abuke Jun 26, 2024
7a60f98
feat: update kafka config to accept large files
dev-abuke Jun 26, 2024
ff05cf6
fix: backtesting features updated to resemble backend
dev-abuke Jun 26, 2024
6367ac0
move: move frontend folder from updated to frontend
dev-abuke Jun 26, 2024
91ac90b
feat:update consumer in backtest implementation
dev-abuke Jun 26, 2024
adb0092
fix: update backtest results for backtest
dev-abuke Jun 26, 2024
2d6cdb0
fix: update backtest results schema
dev-abuke Jun 26, 2024
f3505ee
test: playground updates
dev-abuke Jun 26, 2024
571f235
feat: add return dictionary to backtest results
dev-abuke Jun 26, 2024
1e98fb4
chore: update main for logger
dev-abuke Jun 26, 2024
08bf473
fix: fix sharpee ratio for none value
dev-abuke Jun 26, 2024
47653b7
feat: integrationof backend
dev-abuke Jun 26, 2024
5cf9522
feat: add lstm strategy
dev-abuke Jun 27, 2024
48dc5e1
fix: update sharpee from int to float
dev-abuke Jun 27, 2024
e5fee37
chore: update readme
dev-abuke Jun 27, 2024
1cd03f8
feat: inegrate mlflow to backtest runs
dev-abuke Jun 27, 2024
2625c9d
feat: add sharpee and max draws
dev-abuke Jun 27, 2024
5eb9917
test: experiment
dev-abuke Jun 27, 2024
4d58ea8
mlflow: datas of mlflow
dev-abuke Jun 27, 2024
c73674e
chore: add mlruns to gitifnore
dev-abuke Jun 27, 2024
6e95e4a
feat: add max draw down to model column
dev-abuke Jun 27, 2024
24914a6
feat: add max drawdown to schema
dev-abuke Jun 27, 2024
53d969c
feat: add error handling and features
dev-abuke Jun 27, 2024
8c7e4ac
test: experimentation
dev-abuke Jun 27, 2024
777b362
chore: add screenshots
dev-abuke Jun 27, 2024
4756d37
lstm: experimentation
dev-abuke Jun 27, 2024
295a46a
feat: update frontend
dev-abuke Jun 27, 2024
a6096e0
chore: add logging
dev-abuke Jun 27, 2024
987f9dc
feat: add profile
dev-abuke Jun 27, 2024
a40a68a
feat: add title
dev-abuke Jun 27, 2024
d1b1858
chore: add logging
dev-abuke Jun 27, 2024
42bb207
feat: add full name to top bar
dev-abuke Jun 27, 2024
b02c940
feat: add profile feat
dev-abuke Jun 27, 2024
66a3b60
ltsm: add calculate return method
dev-abuke Jun 27, 2024
1243711
feat: docker fie backend
dev-abuke Jun 27, 2024
f9a0b8e
feat: docker file frontend
dev-abuke Jun 27, 2024
d898d8b
feat: airflow docker
dev-abuke Jun 27, 2024
f7829fe
fix: error in sharpee ratio
dev-abuke Jun 27, 2024
8edd97e
Merge pull request #6 from dev-abuke/frontend
dev-abuke Jun 27, 2024
6ab8806
Merge pull request #7 from dev-abuke/airflow
dev-abuke Jun 27, 2024
ed9c33b
airflow: compose file finilized
dev-abuke Jun 27, 2024
e8944e2
feat: dockerfile for installation of requirements to airflow dags
dev-abuke Jun 27, 2024
ffd220b
chore: add requirements to airflow
dev-abuke Jun 27, 2024
96691e7
chore: init code for implementing backtest dags
dev-abuke Jun 27, 2024
e2d4f45
dag: implement fetch everyday for airflow
dev-abuke Jun 27, 2024
ec4992a
notebook: ecperimentations
dev-abuke Jun 27, 2024
dcbe377
others: necessary files
dev-abuke Jun 27, 2024
650dbf3
feat: add data quality checks
dev-abuke Jun 27, 2024
0af4cab
fix: add backend and script files to airflow docker
dev-abuke Jun 27, 2024
b52e3d4
fix: pandas to resemble the model
dev-abuke Jun 27, 2024
97cc4e8
feat: add stock data api getway
dev-abuke Jun 27, 2024
c603892
feat: add stock data model
dev-abuke Jun 27, 2024
a22eaea
feat: add stock data schema
dev-abuke Jun 27, 2024
3a36860
chore: notebook experimenation
dev-abuke Jun 27, 2024
6f8c71a
feat: add scene list route and fix login
dev-abuke Jun 27, 2024
8b624b5
fix: port change
dev-abuke Jun 27, 2024
517b6ab
feat: add scene list ui
dev-abuke Jun 27, 2024
8fcdaef
install: add react icon package
dev-abuke Jun 27, 2024
8dc7d88
mig: alembic migration
dev-abuke Jun 28, 2024
8e97082
chore: files for mlflow and db
dev-abuke Jun 28, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ celerybeat.pid

# SageMath parsed files
*.sage.py

mlruns/
# Environments
.env
.venv
Expand Down
35 changes: 35 additions & 0 deletions 0.5.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Collecting nixtla
Downloading nixtla-0.5.1-py3-none-any.whl.metadata (4.8 kB)
Requirement already satisfied: httpx in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from nixtla) (0.27.0)
Requirement already satisfied: pandas in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from nixtla) (2.2.2)
Requirement already satisfied: pydantic in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from nixtla) (2.7.4)
Requirement already satisfied: requests in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from nixtla) (2.32.3)
Collecting tenacity (from nixtla)
Downloading tenacity-8.4.1-py3-none-any.whl.metadata (1.2 kB)
Collecting utilsforecast>=0.1.7 (from nixtla)
Downloading utilsforecast-0.1.11-py3-none-any.whl.metadata (7.4 kB)
Requirement already satisfied: numpy in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from utilsforecast>=0.1.7->nixtla) (1.26.4)
Requirement already satisfied: packaging in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from utilsforecast>=0.1.7->nixtla) (24.1)
Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pandas->nixtla) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pandas->nixtla) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pandas->nixtla) (2024.1)
Requirement already satisfied: anyio in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpx->nixtla) (4.4.0)
Requirement already satisfied: certifi in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpx->nixtla) (2024.6.2)
Requirement already satisfied: httpcore==1.* in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpx->nixtla) (1.0.5)
Requirement already satisfied: idna in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpx->nixtla) (3.7)
Requirement already satisfied: sniffio in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpx->nixtla) (1.3.1)
Requirement already satisfied: h11<0.15,>=0.13 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from httpcore==1.*->httpx->nixtla) (0.14.0)
Requirement already satisfied: annotated-types>=0.4.0 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pydantic->nixtla) (0.7.0)
Requirement already satisfied: pydantic-core==2.18.4 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pydantic->nixtla) (2.18.4)
Requirement already satisfied: typing-extensions>=4.6.1 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from pydantic->nixtla) (4.12.2)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from requests->nixtla) (3.3.2)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from requests->nixtla) (2.2.2)
Requirement already satisfied: six>=1.5 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from python-dateutil>=2.8.2->pandas->nixtla) (1.16.0)
Requirement already satisfied: exceptiongroup>=1.0.2 in c:\users\user\downloads\ten_academy\week9\scalable_backtesting_infrastructure_for_crypto_trading\backtest\lib\site-packages (from anyio->httpx->nixtla) (1.2.1)
Downloading nixtla-0.5.1-py3-none-any.whl (71 kB)
---------------------------------------- 71.4/71.4 kB 561.5 kB/s eta 0:00:00
Downloading utilsforecast-0.1.11-py3-none-any.whl (40 kB)
---------------------------------------- 40.6/40.6 kB 978.0 kB/s eta 0:00:00
Downloading tenacity-8.4.1-py3-none-any.whl (27 kB)
Installing collected packages: tenacity, utilsforecast, nixtla
Successfully installed nixtla-0.5.1 tenacity-8.4.1 utilsforecast-0.1.11
33 changes: 33 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Use the official Python base image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the required Python packages
RUN pip install --no-cache-dir -r requirements.txt

# Copy the entire backend project into the container
COPY ./backend .

# Expose the port that FastAPI runs on
EXPOSE 8000

# Set environment variables for the FastAPI app
ENV PYTHONUNBUFFERED=1

ENV BINANCE_API_KEY="FN6iy8IhLMbDR3kVEYp1ZqsN6lj0fZXFRQaRZeJsWuLz6Is7DkVvyb70fwPGDY3B"
ENV DATABASE_URL="postgresql://trading_db_av2v_user:210M6MA9QKEEgVdiasnUdMQDBNN417oy@dpg-cpqojbqj1k6c73bkqq3g-a.oregon-postgres.render.com/trading_db_av2v"
ENV PYCOPG_DATABASE_URL = "postgresql+psycopg2://trading_db_av2v_user:210M6MA9QKEEgVdiasnUdMQDBNN417oy@dpg-cpqojbqj1k6c73bkqq3g-a.oregon-postgres.render.com/trading_db_av2v"
ENV DB_USERNAME='group3'
ENV DB_PASSWORD='group3@week9'
ENV DB_HOST='g3.10academy.org'
ENV DB_PORT=5432
ENV DB_DATABASE='backtest'
ENV AWS_DATABASE_URL="postgresql+psycopg2://group3:group3%[email protected]/backtest"

# Run the FastAPI app with Uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
29 changes: 29 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use the official Node.js image as the base image
FROM node:16-alpine

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY ./frontend/package*.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application code to the working directory
COPY ./frontend .

# Build the React application
RUN npm run build

# Use the official Nginx image to serve the React application
FROM nginx:alpine

# Copy the built React application from the previous stage
COPY --from=0 /app/build /usr/share/nginx/html

# Expose port 80
EXPOSE 80

# Start Nginx when the container starts
CMD ["nginx", "-g", "daemon off;"]
132 changes: 125 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Scalable Crypto Backtesting Infrastructure
# Scalable Stock and Crypto Backtesting Infrastructure

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Project Structure](#project-structure)
- [Endpoints](#endpoints)
- [Kafka Integration](#kafka-integration)
- [LSTM Integration](#lstm-integration)
- [License](#license)

## Overview

Expand Down Expand Up @@ -56,7 +66,20 @@ pip install -r requirements.txt
```
## Project Structure
```bash
├── data/
├── backend/
│ ├── main.py
│ ├── models.py
│ ├── schemas.py
│ ├── database.py
│ ├── auth.py
│ ├── requirements.txt
│ ├── README.md
│ └── scripts
│ ├── backtesting
│ ├── init_data.py
│ ├── kafka_config.py
│ │ ├── main.py
│ └── init_db.py
├── scripts/
│ └── download_data.py
├── tests/
Expand All @@ -66,13 +89,108 @@ pip install -r requirements.txt
├── requirements.txt
└── README.md
```

### Set Up Kafka

If you do not have Kafka installed, you can run it using Docker:

docker run -d --name zookeeper -p 2181:2181 zookeeper:3.4.9
docker run -d --name kafka -p 9092:9092 --link zookeeper wurstmeister/kafka:latest

Alternatively, follow the [Kafka Quickstart](https://kafka.apache.org/quickstart) guide to set up Kafka.

### Configure Environment Variables

Create a `.env` file in the root directory and add the following configurations:

- KAFKA_BROKER_URL=localhost:9092
- SCENE_TOPIC=scene_parameters
- RESULT_TOPIC=backtest_results

### Initialize the Database

python -m scripts.init_db

## Backend Usage

### Run the FastAPI Application

uvicorn main:app --reload

### Sending Requests

Use a tool like Postman, Thunder Client, or Curl to interact with the API.

### Endpoints

### Health Check

**GET /health**

### Create Indicator

**POST /indicators/**

```sh
Body
{
"name": "Simple Moving Average",
"symbol": "SMA",
"description": "A simple moving average indicator"
}
```

### Read Indicators

**GET /indicators/**

### Create Stock

**POST /stocks/**

```sh
Body
{
"name": "Apple Inc.",
"symbol": "AAPL",
"description": "Apple Inc. stock"
}
```

### Read Stocks

**GET /stocks/**

### Create Scene

**POST /scenes/**

```sh
Body
{
"period": 20,
"indicator_id": 1,
"stock_id": 1,
"start_date": "2023-01-01",
"end_date": "2023-12-31"
}
```

### Read Scenes

**GET /scenes/**

### Perform Backtest

**POST /backtests/{scene_id}**

### Read Backtest Results

**GET /backtest_results/**

## Contributors
- Abubeker Shamil
- Addisu Alemu
- Michael George
- Sheila Murugi



## License
This project is licensed under the MIT License - see the LICENSE file for details.
Expand All @@ -85,4 +203,4 @@ This project is licensed under the MIT License - see the LICENSE file for detail
- Rehmet

**References:**
backtrader, Freqtrade, Vectorbt, Kafka, Airflow, MLflow, CML
backtrader, Freqtrade, Vectorbt, Kafka, Airflow, MLflow, CML
26 changes: 26 additions & 0 deletions airflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM apache/airflow:2.9.1

# Switch to root to install system dependencies
USER root

# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
pkg-config \
libhdf5-dev \
gcc \
python3-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Switch to airflow user to install Python packages
USER airflow

# Copy requirements and install Python packages
COPY requirements.txt .

COPY ../backend ./backend

COPY ../scripts/backtesting ./scripts/backtesting

RUN pip install --no-cache-dir -r requirements.txt
Loading