Skip to content

Commit

Permalink
Merge pull request #5 from zhiyuan5986/pushMASTER
Browse files Browse the repository at this point in the history
Push master configuration
  • Loading branch information
MogicianXD authored Apr 19, 2024
2 parents 344a604 + 072efd3 commit ddfe1f2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/benchmarks/MASTER/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ paper: [MASTER: Market-Guided Stock Transformer for Stock Price Forecasting](htt

codes: [https://github.com/SJTU-Quant/MASTER](https://github.com/SJTU-Quant/MASTER)

## config
We recommend you to use conda to config the environment and run the codes:
> Note that you should install `torch` and by your self.
```
bash config.sh
```

## run
You can directly use the bash script to run the codes (you can set the `universe` and `only_backtest` flag in `run.sh`), this `main.py` will test the model with 3 random seeds:
```
conda activate MASTER
bash run.sh
```
<!-- or you can just directly use `qrun` tp run the codes (note that you should modify your `qlib`, since we add or modify some files in `qlib/contrib/data/dataset.py`, `qlib/data/dataset/__init__.py`, `qlib/data/dataset/processor.py` and `qlib/contrib/model/pytorch_master.py`):
Expand Down
19 changes: 19 additions & 0 deletions examples/benchmarks/MASTER/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# create a new conda environment named `MASTER`
conda create -n MASTER python=3.8
eval "$(conda shell.bash hook)"
conda activate MASTER

# install `qlib`
pip install pyqlib
pip install -r requirements.txt

# the following codes copy the `*.so` files in the installed `qlib` package to our customizable `qlib`
path=$(which conda)
parent_path=$(dirname $path)
parent_path=$(dirname $parent_path)
lib_path="$parent_path/envs/MASTER/lib/python3.8/site-packages/qlib/data/_libs"
echo $lib_path
find $lib_path -type f -name "*.so" -exec cp {} "../../../qlib/data/_libs" \;

# we directly use our customizable `qlib`
pip uninstall pyqlib
2 changes: 1 addition & 1 deletion examples/benchmarks/MASTER/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def parse_args():
pp.pprint(all_metrics)

for k in all_metrics.keys():
print(f"{k}: {np.mean(all_metrics[k])} +- {np.std(all_metrics[k])}")
print(f"{k}: {np.mean(all_metrics[k])} +- {np.std(all_metrics[k])}")
1 change: 1 addition & 0 deletions examples/benchmarks/MASTER/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chardet
5 changes: 4 additions & 1 deletion examples/benchmarks/MASTER/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ if [ ! -d "./backtest" ]; then
mkdir ./backtest
fi

# set the config
# set the market, you can choose `csi300` or `csi500`
universe=csi300

# set the flag: whether only backtest.
# If choose 'true', we will directly use the trained model and do backtesting; If choose 'false', the script will first train then backtest.
only_backtest=false

sed -i "s/csi.../$universe/g" workflow_config_master_Alpha158.yaml
Expand Down

0 comments on commit ddfe1f2

Please sign in to comment.