Skip to content

Commit

Permalink
Formated and env_setup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Charmve committed Dec 3, 2022
1 parent 0aa0a52 commit c42fdcc
Show file tree
Hide file tree
Showing 90 changed files with 4,184 additions and 2,705 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ select = B,C,E,F,P,T4,W,B9
# line length is intentionally set to 80 here because black uses Bugbear
# See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length for more details
max-line-length = 80
# NOTE (yuting zhao): may change in the future, current setting to see https://github.com/psf/black/blob/main/.flake8
max-complexity = 18
# NOTE: may change in the future, current setting to see https://github.com/psf/black/blob/main/.flake8
max-complexity = 36
# C408 ignored because we like the dict keyword argument syntax
# E501 is not flexible enough, we're using B950 instead
ignore =
Expand Down
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Style

> <b>Before you pull request, please run ``./scripts/format.sh --git``.</b>
This project is formatted with [clang-format][fmt] using the style file at the root of the repository. Please run clang-format before sending a pull request.

In general, try to follow the style of surrounding code. We mostly follow the [Google C++ style guide][cpp-style].
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/format_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
set -euo pipefail

TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
# shellcheck disable=SC1090,SC1091
source "${TOP_DIR}/scripts/check_gtest_deps.sh"

function check_code_formatted() {
readarray -t my_diffs < <(git diff \
# shellcheck disable=SC1001,SC2162
while IFS=\= read my_diff; do
my_diffs+=("$my_diff")
done < <(git diff \
--ignore-submodules --diff-filter=d --name-only -- \
"*.h" "*.cc" "*.cpp" "*.cu" \
"*.proto" \
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ jobs:
pip install pylint
- name: Analysing the code with pylint
run: |
source ./.github/scripts/format_check.sh
sudo apt install shellcheck
sudo apt install protobuf
./.github/scripts/format_check.sh
shell: bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@ dmypy.json
.vscode
.vim
.nvimrc
jqdata.json

*.DS_Store
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1> <img src="https://user-images.githubusercontent.com/29084184/204598632-23c473db-92ee-4e9b-9b57-d6d95c861fdf.png" width="42"/> Qbot </h1>
<h1> <img src="https://user-images.githubusercontent.com/29084184/204598632-23c473db-92ee-4e9b-9b57-d6d95c861fdf.png" width="42"/> 🤖 Qbot </h1>

<div align="center">
<img src="https://user-images.githubusercontent.com/29084184/204598632-23c473db-92ee-4e9b-9b57-d6d95c861fdf.png" width="224"/>
Expand Down Expand Up @@ -28,19 +28,36 @@
</p>
</div>


Qbot = 智能交易策略 + 回测系统 + 自动化交易 (+ 可视化分析工具)

```
🤖 Qbot = 智能交易策略 + 回测系统 + 自动化交易 (+ 可视化分析工具)
| | | |
| | | \_ quantstats (dashboard\online operate)
| | \______________ Qbot - vnpy, pytrader, pyfunds
| \__________________________ BackTest - backtrader, easyquant
\______________________________________ quant.ai - qlib, deep learning strategies
```

## Installation

[Install Guide](./docs/Install_guide.md)

```
____________________________________
< Run ``./env_setup.sh`` to say hello >
------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
```

## Get Started


## Benchmark and model zoo
## Benchmark and Model zoo

Results and models are available in the [model zoo](docs/en/model_zoo.md).
Results and models are available in the [model zoo](docs/model_zoo.md).

<div align="center">
<b>Components</b>
Expand Down Expand Up @@ -176,9 +193,9 @@ Results and models are available in the [model zoo](docs/en/model_zoo.md).
| FCOS3D ||||||||


<sup>**Note:** All the about **300+ models, methods of 40+ papers** in 2D detection supported by [MMDetection](https://github.com/open-mmlab/mmdetection/blob/master/docs/en/model_zoo.md) can be trained or used in this codebase.</sup>

<sup>**Note:** All the about **300+ models, methods of 40+ papers** in quant.ai supported by [Model Zoo](./docs/model_zoo.md) can be trained or used in this codebase.</sup>

## Quantstats Report
## Contributing

We appreciate all contributions to improve MMDetection3D. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline.
Expand Down
2 changes: 2 additions & 0 deletions docs/Install_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ bash Anaconda3-5.3.1-Linux-x86_64.sh
```bash
conda create -n Qbot python=3.9
conda activate Qbot

pip install -r requirements.txt
```

## Prepare
Expand Down
11 changes: 5 additions & 6 deletions docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<div align="center">
<!-- <div align="center">
<img src="https://raw.githubusercontent.com/Charmve/computer-vision-in-action/main/res/ui/maiwei.png" width="100px" alt="L0CV" title="有疑问,跑起来就会变成一朵花 ❀">
</div>
</div> -->

# Qbot 人工智能自动化量化交易 🌱
<!---## AI + 金融 <small>V1.2 </small>-->

> 人工智能、量化交易
<h1> 🤖 Qbot </h1>
<h2> 人工智能自动化量化交易机器人 </h2>

> <small>🌱 V1.2</small>
<br>
<span id="busuanzi_container_site_pv" style='display:none'>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Qbot 自动化人工智能量化交易工具 🌱</title>
<title> Qbot 自动化人工智能量化交易机器人 🌱</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
Expand Down Expand Up @@ -113,7 +113,7 @@
};

window.$docsify = {
name: '🔥 自动驾驶感知算法专题',
name: '🤖 Qbot',
// nameLink: 'https://charmve.github.io/L0CV-web/',
loadSidebar: true,
maxLevel: 4, // 默认情况下会抓取文档中所有标题渲染成目录,可配置最大支持渲染的标题层级。
Expand Down
13 changes: 13 additions & 0 deletions docs/model_zoo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Model Zoo

## Common settings

- We use distributed training.
- For fair comparison with other codebases, we report the GPU memory as the maximum value of `torch.cuda.max_memory_allocated()` for all 8 GPUs. Note that this value is usually less than what `nvidia-smi` shows.
- We report the inference time as the total time of network forwarding and post-processing, excluding the data loading time. Results are obtained with the script [benchmark.py](https://github.com/open-mmlab/mmdetection/blob/master/tools/analysis_tools/benchmark.py) which computes the average time on 2000 images.

## Baselines

### SECOND

Please refer to [SECOND](https://github.com/open-mmlab/mmdetection3d/blob/master/configs/second) for details. We provide SECOND baselines on KITTI and Waymo datasets.
44 changes: 44 additions & 0 deletions env_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -euo pipefail

wget https://repo.continuum.io/archive/Anaconda3-5.3.1-Linux-x86_64.sh
bash Anaconda3-5.3.1-Linux-x86_64.sh

echo "export PATH=/home/$USER/anaconda3/bin:$PATH" | sudo tee -a ~/.bashrc
# shellcheck disable=SC1090
source ~/.bashrc

conda info --env
conda create -n Qbot python=3.9
conda activate Qbot
conda info --env

pip install -r requirements.txt

export USER_ID="admin"
export PASSWORD="admin1234."

echo "Successful - Environment is set up!"

echo "Enjoy, Quanter!"

cat << EOF
██████╗ ██████╗ ██████╗ ████████╗
██╔═══██╗██╔══██╗██╔═══██╗╚══██╔══╝
██║ ██║██████╔╝██║ ██║ ██║
██║▄▄ ██║██╔══██╗██║ ██║ ██║
╚██████╔╝██████╔╝╚██████╔╝ ██║
╚══▀▀═╝ ╚═════╝ ╚═════╝ ╚═╝
Alpha Qbot
++++=================================++++
auth: Charmve --V.0.1
🤖 Qbot = 智能交易策略 + 回测系统 + 自动化交易 (+ 可视化分析工具)
| | | |
| | | \_ quantstats (dashboard\online operate)
| | \______________ Qbot - vnpy, pytrader, pyfunds
| \__________________________ BackTest - backtrader, easyquant
\______________________________________ quant.ai - qlib, deep learning strategies
EOF
12 changes: 5 additions & 7 deletions pytrader/analyser/alphafold158.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from qlib.config import REG_CN
from qlib.contrib.data.handler import Alpha158


if __name__ == '__main__':
qlib.init(provider_uri='data/cn_data', region=REG_CN)
if __name__ == "__main__":
qlib.init(provider_uri="data/cn_data", region=REG_CN)

data_handler_config = {
"start_time": "2018-01-01",
Expand All @@ -17,11 +16,10 @@
h = Alpha158(**data_handler_config)

# get all the columns of the data
print('columns: \n', h.get_cols())
print("columns: \n", h.get_cols())

# fetch all the labels
print('labels: \n', h.fetch(col_set="label"))
print("labels: \n", h.fetch(col_set="label"))

# fetch all the features
print('features: \n', h.fetch(col_set="feature"))

print("features: \n", h.fetch(col_set="feature"))
75 changes: 34 additions & 41 deletions pytrader/analyser/highfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@


from copy import deepcopy
import qlib

import fire
import pandas as pd
from qlib.config import REG_CN, HIGH_FREQ_CONFIG
from qlib.data import D
from qlib.utils import exists_qlib_data, init_instance_by_config, flatten_dict
from qlib.workflow import R
from qlib.workflow.record_temp import SignalRecord, PortAnaRecord
from qlib.tests.data import GetData
import qlib
from qlib.backtest import collect_data
from qlib.config import HIGH_FREQ_CONFIG, REG_CN
from qlib.tests.data import GetData
from qlib.utils import flatten_dict, init_instance_by_config
from qlib.workflow import R
from qlib.workflow.record_temp import PortAnaRecord, SignalRecord


class NestedDecisionExecutionWorkflow:
Expand Down Expand Up @@ -172,34 +172,25 @@ class NestedDecisionExecutionWorkflow:
"time_per_step": "5min",
"generate_portfolio_metrics": True,
"verbose": True,
"indicator_config": {
"show_indicator": True,
},
"indicator_config": {"show_indicator": True},
},
},
"inner_strategy": {
"class": "TWAPStrategy",
"module_path": "qlib.contrib.strategy.rule_strategy",
},
"generate_portfolio_metrics": True,
"indicator_config": {
"show_indicator": True,
},
"indicator_config": {"show_indicator": True},
},
},
"inner_strategy": {
"class": "SBBStrategyEMA",
"module_path": "qlib.contrib.strategy.rule_strategy",
"kwargs": {
"instruments": market,
"freq": "1min",
},
"kwargs": {"instruments": market, "freq": "1min"},
},
"track_data": True,
"generate_portfolio_metrics": True,
"indicator_config": {
"show_indicator": True,
},
"indicator_config": {"show_indicator": True},
},
},
"backtest": {
Expand All @@ -220,13 +211,21 @@ class NestedDecisionExecutionWorkflow:
def _init_qlib(self):
"""initialize qlib"""
provider_uri_day = "~/.qlib/qlib_data/cn_data" # target_dir
GetData().qlib_data(target_dir=provider_uri_day, region=REG_CN, version="v2", exists_skip=True)
GetData().qlib_data(
target_dir=provider_uri_day, region=REG_CN, version="v2", exists_skip=True
)
provider_uri_1min = HIGH_FREQ_CONFIG.get("provider_uri")
GetData().qlib_data(
target_dir=provider_uri_1min, interval="1min", region=REG_CN, version="v2", exists_skip=True
target_dir=provider_uri_1min,
interval="1min",
region=REG_CN,
version="v2",
exists_skip=True,
)
provider_uri_map = {"1min": provider_uri_1min, "day": provider_uri_day}
qlib.init(provider_uri=provider_uri_map, dataset_cache=None, expression_cache=None)
qlib.init(
provider_uri=provider_uri_map, dataset_cache=None, expression_cache=None
)

def _train_model(self, model, dataset):
with R.start(experiment_name="train"):
Expand All @@ -247,11 +246,7 @@ def backtest(self):
strategy_config = {
"class": "TopkDropoutStrategy",
"module_path": "qlib.contrib.strategy.signal_strategy",
"kwargs": {
"signal": (model, dataset),
"topk": 50,
"n_drop": 5,
},
"kwargs": {"signal": (model, dataset), "topk": 50, "n_drop": 5},
}
self.port_analysis_config["strategy"] = strategy_config
self.port_analysis_config["backtest"]["benchmark"] = self.benchmark
Expand Down Expand Up @@ -281,13 +276,11 @@ def collect_data(self):
strategy_config = {
"class": "TopkDropoutStrategy",
"module_path": "qlib.contrib.strategy.signal_strategy",
"kwargs": {
"signal": (model, dataset),
"topk": 50,
"n_drop": 5,
},
"kwargs": {"signal": (model, dataset), "topk": 50, "n_drop": 5},
}
data_generator = collect_data(executor=executor_config, strategy=strategy_config, **backtest_config)
data_generator = collect_data(
executor=executor_config, strategy=strategy_config, **backtest_config
)
for trade_decision in data_generator:
print(trade_decision)

Expand All @@ -303,13 +296,17 @@ def collect_data(self):
def check_diff_freq(self):
self._init_qlib()
exp = R.get_exp(experiment_name="backtest")
rec = next(iter(exp.list_recorders().values())) # assuming this will get the latest recorder
rec = next(
iter(exp.list_recorders().values())
) # assuming this will get the latest recorder
for check_key in "account", "total_turnover", "total_cost":
check_key = "total_cost"

acc_dict = {}
for freq in ["30minute", "5minute", "1day"]:
acc_dict[freq] = rec.load_object(f"portfolio_analysis/report_normal_{freq}.pkl")[check_key]
acc_dict[freq] = rec.load_object(
f"portfolio_analysis/report_normal_{freq}.pkl"
)[check_key]
acc_df = pd.DataFrame(acc_dict)
acc_resam = acc_df.resample("1d").last().dropna()
assert (acc_resam["30minute"] == acc_resam["1day"]).all()
Expand Down Expand Up @@ -362,11 +359,7 @@ def backtest_only_daily(self):
strategy_config = {
"class": "TopkDropoutStrategy",
"module_path": "qlib.contrib.strategy.signal_strategy",
"kwargs": {
"signal": (model, dataset),
"topk": 50,
"n_drop": 5,
},
"kwargs": {"signal": (model, dataset), "topk": 50, "n_drop": 5},
}
pa_conf = deepcopy(self.port_analysis_config)
pa_conf["strategy"] = strategy_config
Expand Down
Loading

0 comments on commit c42fdcc

Please sign in to comment.