mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
refine optimizer executor config structure
This commit is contained in:
parent
16682596df
commit
9b82de596b
|
@ -3,12 +3,16 @@
|
||||||
# go run ./cmd/bbgo optimize --config bollmaker_ethusdt.yaml --optimizer-config optimizer.yaml --debug
|
# go run ./cmd/bbgo optimize --config bollmaker_ethusdt.yaml --optimizer-config optimizer.yaml --debug
|
||||||
#
|
#
|
||||||
---
|
---
|
||||||
maxThread: 10
|
executor:
|
||||||
|
type: local
|
||||||
|
local:
|
||||||
|
maxNumberOfProcesses: 10
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
- type: iterate
|
- type: iterate
|
||||||
label: interval
|
label: interval
|
||||||
path: '/exchangeStrategies/0/bollmaker/interval'
|
path: '/exchangeStrategies/0/bollmaker/interval'
|
||||||
values: ["1m", "5m", "15m", "30m"]
|
values: [ "1m", "5m", "15m", "30m" ]
|
||||||
|
|
||||||
- type: range
|
- type: range
|
||||||
path: '/exchangeStrategies/0/bollmaker/amount'
|
path: '/exchangeStrategies/0/bollmaker/amount'
|
||||||
|
|
|
@ -80,6 +80,7 @@ var optimizeCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
executor := &optimizer.LocalProcessExecutor{
|
executor := &optimizer.LocalProcessExecutor{
|
||||||
|
Config: optConfig.Executor.LocalExecutorConfig,
|
||||||
Bin: os.Args[0],
|
Bin: os.Args[0],
|
||||||
WorkDir: ".",
|
WorkDir: ".",
|
||||||
ConfigDir: configDir,
|
ConfigDir: configDir,
|
||||||
|
|
|
@ -18,11 +18,30 @@ type SelectorConfig struct {
|
||||||
Step fixedpoint.Value `json:"step,omitempty" yaml:"step,omitempty"`
|
Step fixedpoint.Value `json:"step,omitempty" yaml:"step,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LocalExecutorConfig struct {
|
||||||
|
MaxNumberOfProcesses int `json:"maxNumberOfProcesses" yaml:"maxNumberOfProcesses"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExecutorConfig struct {
|
||||||
|
Type string `json:"type" yaml:"type"`
|
||||||
|
LocalExecutorConfig *LocalExecutorConfig `json:"local" yaml:"local"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Executor *ExecutorConfig `json:"executor" yaml:"executor"`
|
||||||
MaxThread int `yaml:"maxThread,omitempty"`
|
MaxThread int `yaml:"maxThread,omitempty"`
|
||||||
Matrix []SelectorConfig `yaml:"matrix"`
|
Matrix []SelectorConfig `yaml:"matrix"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultExecutorConfig = &ExecutorConfig{
|
||||||
|
Type: "local",
|
||||||
|
LocalExecutorConfig: defaultLocalExecutorConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultLocalExecutorConfig = &LocalExecutorConfig{
|
||||||
|
MaxNumberOfProcesses: 10,
|
||||||
|
}
|
||||||
|
|
||||||
func LoadConfig(yamlConfigFileName string) (*Config, error) {
|
func LoadConfig(yamlConfigFileName string) (*Config, error) {
|
||||||
configYaml, err := ioutil.ReadFile(yamlConfigFileName)
|
configYaml, err := ioutil.ReadFile(yamlConfigFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,9 +53,16 @@ func LoadConfig(yamlConfigFileName string) (*Config, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default of MaxThread is 5
|
if optConfig.Executor == nil {
|
||||||
if optConfig.MaxThread <= 0 {
|
optConfig.Executor = defaultExecutorConfig
|
||||||
optConfig.MaxThread = 5
|
}
|
||||||
|
|
||||||
|
if optConfig.Executor.Type == "" {
|
||||||
|
optConfig.Executor.Type = "local"
|
||||||
|
}
|
||||||
|
|
||||||
|
if optConfig.Executor.Type == "local" && optConfig.Executor.LocalExecutorConfig == nil {
|
||||||
|
optConfig.Executor.LocalExecutorConfig = defaultLocalExecutorConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
return &optConfig, nil
|
return &optConfig, nil
|
||||||
|
|
|
@ -199,7 +199,7 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "MaxThread", o.Config.MaxThread)
|
ctx := context.Background()
|
||||||
resultsC, err := executor.Run(ctx, taskC)
|
resultsC, err := executor.Run(ctx, taskC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -36,6 +36,7 @@ type AsyncHandle struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalProcessExecutor struct {
|
type LocalProcessExecutor struct {
|
||||||
|
Config *LocalExecutorConfig
|
||||||
Bin string
|
Bin string
|
||||||
WorkDir string
|
WorkDir string
|
||||||
ConfigDir string
|
ConfigDir string
|
||||||
|
@ -73,7 +74,7 @@ func (e *LocalProcessExecutor) readReport(output []byte) (*backtest.SummaryRepor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask) (chan BacktestTask, error) {
|
func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask) (chan BacktestTask, error) {
|
||||||
var maxNumOfProcess = ctx.Value("MaxThread").(int)
|
var maxNumOfProcess = e.Config.MaxNumberOfProcesses
|
||||||
var resultsC = make(chan BacktestTask, maxNumOfProcess*2)
|
var resultsC = make(chan BacktestTask, maxNumOfProcess*2)
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user