Skip to content
Closed
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
50 changes: 50 additions & 0 deletions .github/workflows/strategy-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Strategy Test

on:
pull_request:
paths:
- 'src/strategies/**'
- '.github/workflows/strategy-test.yml'

jobs:
test-strategy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
uv sync

- name: Find changed strategy files
id: find-strategies
run: |
STRATEGIES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep 'src/strategies/.*\.py$' || true)
echo "strategies<<EOF" >> $GITHUB_OUTPUT
echo "$STRATEGIES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Test strategies
if: steps.find-strategies.outputs.strategies != ''
run: |
for strategy in ${{ steps.find-strategies.outputs.strategies }}; do
echo "Testing $strategy..."
python scripts/test_strategy.py "$strategy"
done

- name: Update leaderboard
if: steps.find-strategies.outputs.strategies != ''
run: |
# TODO: Implement leaderboard update
echo "Leaderboard update not yet implemented"
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
.DS_store
.venv
.ipynb_checkpoints
.ipynb_checkpoints
__pycache__/
**/__pycache__/
*/*.pyc
*/*.pyo
*/*.pyd
*/*.pyw
*/*.pyz
*/*.pywz
132 changes: 109 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,122 @@
# nstrade

NS Learnathon - Trading for Bitcoin

# install brew
Go to `brew.sh`
## Setup

### Prerequisites

1. **Install Homebrew**
- Visit [brew.sh](https://brew.sh)

2. **Install uv**
```bash
# On macOS
brew install uv
```
> Note: `uv` is like `poetry` but better in every way. [Learn more](https://docs.astral.sh/uv/getting-started/installation/)

3. **Fork and Clone**
```bash
# Fork the repo at https://github.com/athon-millane/nstrade.git
git clone https://github.com/your-username/nstrade.git
```

4. **Python Setup**
```bash
# Optional: Install Python 3.12 if needed
uv python install 3.12

# Initialize venv and install dependencies
uv sync
```

### Syncing with Upstream

```bash
# Add upstream remote
git remote add upstream https://github.com/athon-millane/nstrade.git

# Pull from upstream (either method)
git pull upstream main

# OR
git fetch upstream
git merge upstream main
```

## Creating a New Strategy

1. **Copy the Template**
```bash
cp strategies/template.py strategies/my_strategy.py
```

2. **Edit Your Strategy**
- Set your name, strategy name, and description
- Implement your strategy logic in `process_bar()` and `get_signal()`
- Optionally implement a vectorized version in `get_signals()`

3. **Quick Test**
```bash
python scripts/test_strategy.py strategies/my_strategy.py
```
This will:
- Validate your strategy implementation
- Test on development period (2011-2024)
- Test on holdout period (2025)

4. **Detailed Evaluation**
- Open `notebooks/evaluate.ipynb` in Jupyter
- Change the `strategy_path` to point to your strategy file
- Run all cells to see:
- Detailed performance metrics
- Interactive plots of price, volume, equity curve, drawdowns, and Sharpe ratio
- Buy/sell points overlaid on the price chart
- Trade-by-trade analysis

# install uv
If on mac
`brew install uv`
5. **Submit Your Strategy**
- Create a pull request
- Our CI will validate and backtest your strategy
- If successful, it will be added to the leaderboard

Apparently `uv` is `poetry` but better in every way. To be seen.
## Project Status

[website here](https://docs.astral.sh/uv/getting-started/installation/)
### Completed
- [x] Speed up backtest (maybe vectorise, maybe parallelise)
- [x] Set up a standardised flow for creating, contributing and backtesting new `Strategy`
- [x] Capture user metadata in Strategy for leaderboard display

# fork the repo
Go to [https://github.com/athon-millane/nstrade.git](https://github.com/athon-millane/nstrade.git) and fork the repo
### To Do
- [ ] Set up CI/CD YAML file:
- Validate strategy backtestability
- Run backtests on our dataset
- Store results in leaderboard file
- Handle unique submissions (User + Strategy name)
- Define development/holdout sets:
- `development.csv`: Data up to end of 2024
- `holdout.csv`: All of 2025
- Strategies should only use `development.csv`

# clone the repo
`git clone https://github.com/your-username/nstrade.git`
## Metrics

# Optional: install python if you don't have version 3.12
`uv python install 3.12`
### Current Focus
- Sharpe ratio as primary metric
- Drawdown
- Win rate
- Number of trades

# initialize venv and sync packages
`uv sync`
### Future Metrics
- Sortino ratio
- R² of equity curve (suggested by Barnabas)

# Sync with changes to the upstream repo (the one at `athon-millane` repo)
Add upstream
`git remote add upstream https://github.com/athon-millane/nstrade.git`
## Notes

Pull from upstream
`git pull upstream main`
### Security
- Current focus: Ensure test data isn't used in strategy development
- More comprehensive security measures to be addressed later

Pull via fetch / merge (if you know what that means)
`git fetch upstream`
`git merge upstream main`
### Observations
- SMA Crossover performance appears suspiciously good
- Most bootstrapped strategies perform poorly without fees and slippage
- Recommended: Include 0.3% fee+slippage per trade
Original file line number Diff line number Diff line change
Expand Up @@ -118057,4 +118057,4 @@ time,high,low,open,volumefrom,volumeto,close,conversionType,conversionSymbol
2025-05-16 23:00:00+00:00,103718.44,103465.47,103551.32,312.4,32355068.37,103499.6,direct,
2025-05-17 00:00:00+00:00,103569.6,103141.31,103499.6,488.11,50440671.96,103388.02,direct,
2025-05-17 01:00:00+00:00,103388.09,102642.39,103388.02,669.72,68915256.62,102859.21,direct,
2025-05-17 02:00:00+00:00,102872.81,102850.93,102859.21,1.836,188867.39,102850.93,direct,
2025-05-17 02:00:00+00:00,103316.88,102779.28,102859.21,263.48,27152537.22,103307.02,direct,
64 changes: 64 additions & 0 deletions data/leaderboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"strategies": [
{
"author_name": "Lucien",
"strategy_name": "SMA Crossover 1",
"description": "Goes long when the 32-period SMA crosses above the 140-period SMA, and exits when it crosses below.",
"last_updated": "2025-05-17T09:58:22.770193Z",
"development_metrics": {
"sharpe": 1.3255701716105417,
"total_return": 37176.1940346568,
"max_drawdown": 0.8976062164340162,
"n_trades": 505,
"win_rate": 0.39603960396039606
},
"holdout_metrics": {
"sharpe": -0.692657754272795,
"total_return": -0.11414418233992363,
"max_drawdown": 0.2941198645359705,
"n_trades": 19,
"win_rate": 0.21052631578947367
}
},
{
"author_name": "Example Author",
"strategy_name": "Example Strategy",
"description": "An example strategy",
"development_metrics": {
"sharpe": 0.0,
"total_return": 0.0,
"max_drawdown": 0.0,
"n_trades": 0,
"win_rate": 0.0
},
"holdout_metrics": {
"sharpe": 0.0,
"total_return": 0.0,
"max_drawdown": 0.0,
"n_trades": 0,
"win_rate": 0.0
},
"last_updated": "2024-01-01T00:00:00Z"
},
{
"author_name": "YOUR_NAME",
"strategy_name": "YOUR_STRATEGY_NAME",
"description": "DESCRIBE YOUR STRATEGY HERE",
"last_updated": "2025-05-17T08:23:59.481326Z",
"development_metrics": {
"sharpe": 0.0,
"total_return": 0.0,
"max_drawdown": 0.0,
"n_trades": 0,
"win_rate": 0.0
},
"holdout_metrics": {
"sharpe": 0.0,
"total_return": 0.0,
"max_drawdown": 0.0,
"n_trades": 0,
"win_rate": 0.0
}
}
]
}
207 changes: 0 additions & 207 deletions notebooks/1.ipynb

This file was deleted.

Loading