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" // HpOptimizerObjectiveProfitFactor optimize the parameters to maximize profit factor HpOptimizerObjectiveProfitFactor = "profitfactor" )
WARNING: the text here could only be lower cases
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 ProfitFactorMetricValueFunc = func(summaryReport *backtest.SummaryReport) float64 { if len(summaryReport.SymbolReports) == 0 { return 0 } if len(summaryReport.SymbolReports) > 1 { panic("multiple symbols' profitfactor optimization not supported") } report := summaryReport.SymbolReports[0] pf := report.ProfitFactor.Float64() win := report.WinningRatio.Float64() return pf*0.9 + win*0.1 }
View Source
var TotalEquityDiff = func(summaryReport *backtest.SummaryReport) float64 { if len(summaryReport.SymbolReports) == 0 { return 0 } initEquity := summaryReport.InitialEquityValue.Float64() finalEquity := summaryReport.FinalEquityValue.Float64() return finalEquity - initEquity }
View Source
var TotalProfitMetricValueFunc = func(summaryReport *backtest.SummaryReport) float64 {
return summaryReport.TotalProfit.Float64()
}
View Source
var TotalVolume = func(summaryReport *backtest.SummaryReport) float64 { if len(summaryReport.SymbolReports) == 0 { return 0 } buyVolume := summaryReport.SymbolReports[0].PnL.BuyVolume.Float64() sellVolume := summaryReport.SymbolReports[0].PnL.SellVolume.Float64() return buyVolume + sellVolume }
Functions ¶
func FormatMetricsTsv ¶
func FormatMetricsTsv(writer io.WriteCloser, metrics map[string][]Metric) error
func FormatResultsTsv ¶
func FormatResultsTsv(writer io.WriteCloser, labelPaths map[string]string, results []*HyperparameterOptimizeTrialResult) error
Types ¶
type AsyncHandle ¶
type AsyncHandle struct { Error error Report *backtest.SummaryReport Done chan struct{} }
type BacktestTask ¶
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 ¶
type ExecutorConfig struct { Type string `json:"type" yaml:"type"` LocalExecutorConfig *LocalExecutorConfig `json:"local" yaml:"local"` }
type GridOptimizer ¶
type HyperparameterOptimizeReport ¶
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 ¶
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 ¶
type HyperparameterOptimizer struct { SessionName string Config *Config // contains filtered or unexported fields }
func (*HyperparameterOptimizer) Run ¶
func (o *HyperparameterOptimizer) Run(ctx context.Context, executor Executor, configJson []byte) (*HyperparameterOptimizeReport, error)
type LocalExecutorConfig ¶
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 ¶
func (e *LocalProcessExecutor) ExecuteAsync(configJson []byte) *AsyncHandle
func (*LocalProcessExecutor) Prepare ¶
func (e *LocalProcessExecutor) Prepare(configJson []byte) error
Prepare prepares the environment for the following back tests this is a blocking operation
func (*LocalProcessExecutor) Run ¶
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 float64 `json:"value,omitempty"` }
type MetricValueFunc ¶
type MetricValueFunc func(summaryReport *backtest.SummaryReport) float64
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.