Skip to content

Commit

Permalink
Merge pull request #472 from enarjord/v7.1.0
Browse files Browse the repository at this point in the history
V7.1.0 optimize coin filter params
  • Loading branch information
enarjord authored Oct 2, 2024
2 parents cd4f1cf + bba6429 commit feb6554
Show file tree
Hide file tree
Showing 21 changed files with 698 additions and 1,762 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

:warning: **Used at one's own risk** :warning:

v7.0.9
v7.1.0


## Overview
Expand Down
10 changes: 8 additions & 2 deletions configs/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"entry_trailing_grid_ratio": -0.28,
"entry_trailing_retracement_pct": 0.0024735,
"entry_trailing_threshold_pct": -0.062799,
"filter_relative_volume_clip_pct": 0.5,
"filter_rolling_window": 60.0,
"n_positions": 10.776,
"total_wallet_exposure_limit": 0.97499,
"unstuck_close_pct": 0.049666,
Expand All @@ -43,6 +45,8 @@
"entry_trailing_grid_ratio": -0.3633,
"entry_trailing_retracement_pct": 0.06044,
"entry_trailing_threshold_pct": -0.084207,
"filter_relative_volume_clip_pct": 0.5,
"filter_rolling_window": 60.0,
"n_positions": 7.6679,
"total_wallet_exposure_limit": 0.0,
"unstuck_close_pct": 0.052781,
Expand All @@ -61,10 +65,8 @@
"max_n_cancellations_per_batch": 5,
"max_n_creations_per_batch": 3,
"minimum_coin_age_days": 30.0,
"ohlcv_rolling_window": 60,
"pnls_max_lookback_days": 30.0,
"price_distance_threshold": 0.002,
"relative_volume_filter_clip_pct": 0.5,
"time_in_force": "good_till_cancelled",
"user": "bybit_01"},
"optimize": {"bounds": {"long_close_grid_markup_range": [0.0, 0.03],
Expand All @@ -84,6 +86,8 @@
"long_entry_trailing_grid_ratio": [-1.0, 1.0],
"long_entry_trailing_retracement_pct": [0.0, 0.1],
"long_entry_trailing_threshold_pct": [-0.1, 0.1],
"long_filter_relative_volume_clip_pct": [0.0, 1.0],
"long_filter_rolling_window": [10.0, 1440.0],
"long_n_positions": [1.0, 20.0],
"long_total_wallet_exposure_limit": [0.0, 5.0],
"long_unstuck_close_pct": [0.001, 0.1],
Expand All @@ -107,6 +111,8 @@
"short_entry_trailing_grid_ratio": [-1.0, 1.0],
"short_entry_trailing_retracement_pct": [0.0, 0.1],
"short_entry_trailing_threshold_pct": [-0.1, 0.1],
"short_filter_relative_volume_clip_pct": [0.0, 1.0],
"short_filter_rolling_window": [10.0, 1440.0],
"short_n_positions": [1.0, 20.0],
"short_total_wallet_exposure_limit": [0.0, 5.0],
"short_unstuck_close_pct": [0.001, 0.1],
Expand Down
15 changes: 10 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ If a position is stuck, bot will use profits made on other positions to realize
- `unstuck_threshold`:
- if a position is bigger than a threshold, consider it stuck and activate unstucking.
- `if wallet_exposure / wallet_exposure_limit > unstuck_threshold: unstucking enabled`
- e.g. if a position size is $500 and max allowed position size is $1000, then position is 50% full. If unstuck_threshold==0.45, then unstuck the position until its size is $450.
- e.g. if a position size is $500 and max allowed position size is $1000, then position is 50% full. If unstuck_threshold==0.45, then unstuck the position until its size is $450.

### Filter Parameters

Coins selected for trading are filtered by volume and noisiness. First, filter coins by volume, dropping x% of the lowest volume coins, then sort the eligible coins by noisiness and select the top noisiest coins for trading.

- `filter_relative_volume_clip_pct`: Volume filter: disapprove the lowest relative volume coins. E.g. `filter_relative_volume_clip_pct=0.1`: drop 10% lowest volume coins. Set to zero to allow all.
- `filter_rolling_window`: number of minutes to look into the past to compute volume and noisiness, used for dynamic coin selection in forager mode.
- noisiness is normalized relative range of 1m ohlcvs: `mean((high - low) / close)`
- in forager mode, bot will select coins with highest noisiness for opening positions

## Live Trading Settings
- `approved_coins`: list of coins approved for trading. If empty, all coins are approved.
Expand Down Expand Up @@ -136,12 +145,8 @@ If a position is stuck, bot will use profits made on other positions to realize
- `max_n_cancellations_per_batch`: will cancel n open orders per execution
- `max_n_creations_per_batch`: will create n new orders per execution
- `minimum_coin_age_days`: disallow coins younger than a given number of days
- `ohlcv_rolling_window`: number of minutes to look into the past to compute volume and noisiness, used for dynamic coin selection in forager mode.
- noisiness is normalized relative range of 1m ohlcvs: `mean((high - low) / close)`
- in forager mode, bot will select coins with highest noisiness for opening positions
- `pnls_max_lookback_days`: how far into the past to fetch pnl history
- `price_distance_threshold`: minimum distance to current price action required for EMA based limit orders
- `relative_volume_filter_clip_pct`: Volume filter: disapprove the lowest relative volume coins. Default 0.1 == 10%. Set to zero to allow all.
- `time_in_force`: default is good-till-cancelled
- `user`: fetch API key/secret from api-keys.json

Expand Down
38 changes: 30 additions & 8 deletions notebooks/notes_backtest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@
"cell_type": "code",
"execution_count": null,
"id": "97f846a3-874c-48f4-93d8-829edc0b4bce",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"config = load_config('configs/template.json')\n",
"{k: config[k] for k in ['backtest', 'bot', 'live']}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60155aa0-a1d3-4763-b314-5e015643b527",
"metadata": {},
"outputs": [],
"source": [
"#config['backtest']['symbols'] = config['backtest']['symbols'][::10]\n",
"config['backtest']['start_date'] = '2024-03-01'\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -43,18 +56,19 @@
"outputs": [],
"source": [
"symbols = config['backtest']['symbols']\n",
"symbols, hlcvs, mss, results_path = await prepare_hlcvs_mss(config)\n",
"hlcs = hlcvs[:,:,:3]"
"symbols, hlcvs, mss, results_path = await prepare_hlcvs_mss(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "896e5b9f-e71f-4abb-b33d-085065fbd3eb",
"id": "2f473002-2ba5-41e3-9f06-ff56aaea2318",
"metadata": {},
"outputs": [],
"source": [
"preferred_coins = calc_preferred_coins(hlcvs, config)"
"#config['bot']['long']['n_positions'] = 3\n",
"#config['bot']['long']['filter_rolling_window'] = 1440\n",
"#config['bot']['long']['filter_relative_volume_clip_pct'] = 0.5"
]
},
{
Expand All @@ -64,13 +78,13 @@
"metadata": {},
"outputs": [],
"source": [
"fills, equities, analysis = run_backtest(hlcs, preferred_coins, mss, config)"
"fills, equities, analysis = run_backtest(hlcvs, mss, config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3ce4490-63ad-4e1f-8477-d188cc058fa4",
"id": "b0a86c90-e834-4016-abfa-8158e2d227cb",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -79,7 +93,7 @@
"print(f'elapsed {utc_ms() - sts}')\n",
"sts = utc_ms()\n",
"equities = pd.Series(equities)\n",
"analysis_py, balance_and_equity = analyze_fills_forager(config['backtest']['symbols'], hlcs, fdf, equities)\n",
"analysis_py, balance_and_equity = analyze_fills_forager(config['backtest']['symbols'], hlcvs, fdf, equities)\n",
"for k in analysis_py:\n",
" if k not in analysis:\n",
" analysis[k] = analysis_py[k]\n",
Expand All @@ -88,6 +102,14 @@
"balance_and_equity.plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e4be85e1-6a27-4864-8e5f-cd78d23abf52",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
33 changes: 33 additions & 0 deletions passivbot-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions passivbot-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ crate-type = ["cdylib"]
pyo3 = { version = "0.21.2", features = ["extension-module"] }
ndarray = "0.15.6"
numpy = "0.21.0"
memmap = "0.7.0"
Loading

0 comments on commit feb6554

Please sign in to comment.