Documentation ¶
Index ¶
- Constants
- Variables
- func FormatMetricsTsv(writer io.WriteCloser, metrics map[string][]Metric) error
- func FormatResultsTsv(writer io.WriteCloser, labelPaths map[string]string, ...) error
- type AsyncHandle
- type BacktestTask
- type Config
- type Executor
- type ExecutorConfig
- type GridOptimizer
- type HyperparameterOptimizeReport
- type HyperparameterOptimizeTrialResult
- type HyperparameterOptimizer
- type LocalExecutorConfig
- type LocalProcessExecutor
- func (e *LocalProcessExecutor) Execute(configJson []byte) (*backtest.SummaryReport, error)
- func (e *LocalProcessExecutor) ExecuteAsync(configJson []byte) *AsyncHandle
- func (e *LocalProcessExecutor) Prepare(configJson []byte) error
- func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask, bar *pb.ProgressBar) (chan BacktestTask, error)
- type Metric
- type MetricValueFunc
- type OpFunc
- type SelectorConfig
Constants ¶
View Source
const ( // HpOptimizerObjectiveEquity optimize the parameters to maximize equity gain HpOptimizerObjectiveEquity = "equity" // HpOptimizerObjectiveProfit optimize the parameters to maximize trading profit HpOptimizerObjectiveProfit = "profit" // HpOptimizerObjectiveVolume optimize the parameters to maximize trading volume HpOptimizerObjectiveVolume = "volume" )
View Source
const ( // HpOptimizerAlgorithmTPE is the implementation of Tree-structured Parzen Estimators HpOptimizerAlgorithmTPE = "tpe" // HpOptimizerAlgorithmCMAES is the implementation Covariance Matrix Adaptation Evolution Strategy HpOptimizerAlgorithmCMAES = "cmaes" // HpOptimizerAlgorithmSOBOL is the implementation Quasi-monte carlo sampling based on Sobol sequence HpOptimizerAlgorithmSOBOL = "sobol" // HpOptimizerAlgorithmRandom is the implementation random search HpOptimizerAlgorithmRandom = "random" )
Variables ¶
View Source
var TotalEquityDiff = func(summaryReport *backtest.SummaryReport) fixedpoint.Value { if len(summaryReport.SymbolReports) == 0 { return fixedpoint.Zero } initEquity := summaryReport.InitialEquityValue finalEquity := summaryReport.FinalEquityValue return finalEquity.Sub(initEquity) }
View Source
var TotalProfitMetricValueFunc = func(summaryReport *backtest.SummaryReport) fixedpoint.Value {
return summaryReport.TotalProfit
}
View Source
var TotalVolume = func(summaryReport *backtest.SummaryReport) fixedpoint.Value { if len(summaryReport.SymbolReports) == 0 { return fixedpoint.Zero } buyVolume := summaryReport.SymbolReports[0].PnL.BuyVolume sellVolume := summaryReport.SymbolReports[0].PnL.SellVolume return buyVolume.Add(sellVolume) }
Functions ¶
func FormatMetricsTsv ¶ added in v1.39.0
func FormatMetricsTsv(writer io.WriteCloser, metrics map[string][]Metric) error
func FormatResultsTsv ¶ added in v1.39.0
func FormatResultsTsv(writer io.WriteCloser, labelPaths map[string]string, results []*HyperparameterOptimizeTrialResult) error
Types ¶
type AsyncHandle ¶ added in v1.36.0
type AsyncHandle struct { Error error Report *backtest.SummaryReport Done chan struct{} }
type BacktestTask ¶ added in v1.36.0
type BacktestTask struct { ConfigJson []byte Params []interface{} Labels []string Report *backtest.SummaryReport Error error }
type Config ¶
type Config struct { Executor *ExecutorConfig `json:"executor" yaml:"executor"` MaxThread int `yaml:"maxThread,omitempty"` Matrix []SelectorConfig `yaml:"matrix"` Algorithm string `yaml:"algorithm,omitempty"` Objective string `yaml:"objectiveBy,omitempty"` MaxEvaluation int `yaml:"maxEvaluation"` }
func LoadConfig ¶
type Executor ¶
type Executor interface { Execute(configJson []byte) (*backtest.SummaryReport, error) Run(ctx context.Context, taskC chan BacktestTask, bar *pb.ProgressBar) (chan BacktestTask, error) }
type ExecutorConfig ¶ added in v1.36.0
type ExecutorConfig struct { Type string `json:"type" yaml:"type"` LocalExecutorConfig *LocalExecutorConfig `json:"local" yaml:"local"` }
type GridOptimizer ¶
type HyperparameterOptimizeReport ¶ added in v1.39.0
type HyperparameterOptimizeReport struct { Name string `json:"studyName"` Objective string `json:"objective"` Parameters map[string]string `json:"domains"` Best *HyperparameterOptimizeTrialResult `json:"best"` Trials []*HyperparameterOptimizeTrialResult `json:"trials,omitempty"` }
type HyperparameterOptimizeTrialResult ¶ added in v1.39.0
type HyperparameterOptimizeTrialResult struct { Value fixedpoint.Value `json:"value"` Parameters map[string]interface{} `json:"parameters"` ID *int `json:"id,omitempty"` State string `json:"state,omitempty"` }
type HyperparameterOptimizer ¶ added in v1.39.0
type HyperparameterOptimizer struct { SessionName string Config *Config // contains filtered or unexported fields }
func (*HyperparameterOptimizer) Run ¶ added in v1.39.0
func (o *HyperparameterOptimizer) Run(ctx context.Context, executor Executor, configJson []byte) (*HyperparameterOptimizeReport, error)
type LocalExecutorConfig ¶ added in v1.36.0
type LocalExecutorConfig struct {
MaxNumberOfProcesses int `json:"maxNumberOfProcesses" yaml:"maxNumberOfProcesses"`
}
type LocalProcessExecutor ¶
type LocalProcessExecutor struct { Config *LocalExecutorConfig Bin string WorkDir string ConfigDir string OutputDir string }
func (*LocalProcessExecutor) Execute ¶
func (e *LocalProcessExecutor) Execute(configJson []byte) (*backtest.SummaryReport, error)
Execute runs the config json and returns the summary report. This is a blocking operation.
func (*LocalProcessExecutor) ExecuteAsync ¶ added in v1.36.0
func (e *LocalProcessExecutor) ExecuteAsync(configJson []byte) *AsyncHandle
func (*LocalProcessExecutor) Prepare ¶ added in v1.37.0
func (e *LocalProcessExecutor) Prepare(configJson []byte) error
Prepare prepares the environment for the following back tests this is a blocking operation
func (*LocalProcessExecutor) Run ¶ added in v1.36.0
func (e *LocalProcessExecutor) Run(ctx context.Context, taskC chan BacktestTask, bar *pb.ProgressBar) (chan BacktestTask, error)
type Metric ¶
type Metric struct { // Labels is the labels of the given parameters Labels []string `json:"labels,omitempty"` // Params is the parameters used to output the metrics result Params []interface{} `json:"params,omitempty"` // Key is the metric name Key string `json:"key"` // Value is the metric value of the metric Value fixedpoint.Value `json:"value,omitempty"` }
type MetricValueFunc ¶
type MetricValueFunc func(summaryReport *backtest.SummaryReport) fixedpoint.Value
type SelectorConfig ¶
type SelectorConfig struct { Type string `json:"type" yaml:"type"` Label string `json:"label,omitempty" yaml:"label,omitempty"` Path string `json:"path" yaml:"path"` Values []string `json:"values,omitempty" yaml:"values,omitempty"` Min fixedpoint.Value `json:"min,omitempty" yaml:"min,omitempty"` Max fixedpoint.Value `json:"max,omitempty" yaml:"max,omitempty"` Step fixedpoint.Value `json:"step,omitempty" yaml:"step,omitempty"` }
Click to show internal directories.
Click to hide internal directories.