Skip to content
Open
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
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ where DPS denotes dividends per share. Existing holdings are sold before purchas

## Implementation
### Environment Setup
**Recommendation:** We recommend using Python 3.12 for this project. While other versions may work, Python 3.12 has been tested and verified to work smoothly with all dependencies. Some dependencies (e.g., matplotlib) may have compatibility issues with Python 3.13.

1. Set up python virtual environment
```bash
python -m venv venv
Expand Down Expand Up @@ -101,11 +103,6 @@ python evaluation.py
[TODO: change the name of optimization folder to out-of-sample-backtesting or something like that]: #
The script will get value from `parameter/optimized_parameter.json` to execute. The results are stored in the `result/optimization` folder.

## In-sample Backtesting
Running the in-sample backtesting by execute the command:
```bash
python backtesting.py
```
### Evaluation Metrics
- Backtesting results are stored in the `result/backtest/` folder.
- Used metrics to compare with VNINDEX are:
Expand Down
13 changes: 13 additions & 0 deletions optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import logging
import json
import optuna
from optuna.samplers import TPESampler
from config.config import OPTIMIZATION_CONFIG
Expand Down Expand Up @@ -83,3 +84,15 @@ def objective(trial):
study.optimize(
objective, n_trials=OPTIMIZATION_CONFIG["no_trials"], callbacks=[optunaCallBack]
)

# Save best parameters to optimized_parameter.json
best_trial = study.best_trial
best_params = {
"pe": [0, best_trial.params["peub"]],
"dy": [best_trial.params["dylb"], 1e6],
}
with open("parameter/optimized_parameter.json", "w", encoding="utf-8") as f:
json.dump(best_params, f, indent=4)
print(f"\nBest trial: {best_trial.number}")
print(f"Best Sharpe ratio: {best_trial.value}")
print(f"Best parameters saved to parameter/optimized_parameter.json")