opt Package
The opt package provides strategy optimization functionality.
Main Structures
BackTest
Backtest instance structure.
Fields:
Trader biz.Trader
- Trader interface implementationBTResult *BTResult
- Backtest resultlastDumpMs int64
- Last timestamp when backtest status was saveddp *data.HistProvider
- Historical data providerisOpt bool
- Whether in hyperparameter optimization modePBar *utils.StagedPrg
- Progress bar
BTResult
Backtest result structure.
Fields:
MaxOpenOrders int
- Maximum number of concurrent open ordersMinReal float64
- Minimum assetsMaxReal float64
- Maximum assetsMaxDrawDownPct float64
- Maximum drawdown percentageShowDrawDownPct float64
- Displayed maximum drawdown percentageMaxDrawDownVal float64
- Maximum drawdown valueShowDrawDownVal float64
- Displayed maximum drawdown valueBarNum int
- Number of candlesticksTimeNum int
- Number of time periodsOrderNum int
- Number of ordersPlots *PlotData
- Plot dataStartMS int64
- Start timestamp (milliseconds)EndMS int64
- End timestamp (milliseconds)PlotEvery int
- Plot intervalTotalInvest float64
- Total investment amountOutDir string
- Output directoryTotProfit float64
- Total profitTotCost float64
- Total costTotFee float64
- Total feesTotProfitPct float64
- Total profit percentageWinRatePct float64
- Win rateSharpeRatio float64
- Sharpe ratioSortinoRatio float64
- Sortino ratio
PlotData
Plot data structure.
Fields:
Labels []string
- Time labelsOdNum []int
- Number of ordersJobNum []int
- Number of jobsReal []float64
- Actual assetsAvailable []float64
- Available assetsProfit []float64
- Realized profitUnrealizedPOL []float64
- Unrealized profit/lossWithDraw []float64
- Withdrawal amount
RowPart
Backtest statistics row data structure.
Fields:
WinCount int
- Number of profitable ordersOrderNum int
- Total number of ordersProfitSum float64
- Total profit amountProfitPctSum float64
- Total profit percentageCostSum float64
- Total costDurations []int
- List of holding durationsOrders []*InOutOrder
- List of ordersSharpe float64
- Sharpe ratioSortino float64
- Sortino ratio
Main Features
NewBackTest
Create a new backtest instance.
Parameters:
isOpt bool
- Whether in hyperparameter optimization modeoutDir string
- Output directory path
Returns:
*BackTest
- Backtest instance pointer
RunBTOverOpt
Run backtest mode based on continuous parameter tuning, approximating live trading conditions and avoiding using future information for parameter tuning.
Parameters:
args *config.CmdArgs
- Command line argument configuration
Returns:
*errs.Error
- Error information
RunRollBTPicker
Execute rolling backtest stock picker.
Parameters:
args *config.CmdArgs
- Command line argument configuration
Returns:
*errs.Error
- Error information
RunOptimize
Execute strategy parameter optimization.
Parameters:
args *config.CmdArgs
- Command line argument configuration
Returns:
*errs.Error
- Error information
CollectOptLog
Collect and analyze optimization logs.
Parameters:
args *config.CmdArgs
- Command line argument configuration
Returns:
*errs.Error
- Error information
NewBTResult
Create a new backtest result instance.
Returns:
*BTResult
- Backtest result instance pointer
AvgGoodDesc
Calculate average optimization results within specified return rate range.
Parameters:
items []*OptInfo
- Optimization information liststartRate float64
- Start return rateendRate float64
- End return rate
Returns:
*OptInfo
- Average optimization information
DescGroups
Group optimization results by return rate.
Parameters:
items []*OptInfo
- Optimization information list
Returns:
[]*OptInfo, []*OptInfo
- Good group and bad group optimization information lists
DumpLineGraph
Generate and save line graph.
Parameters:
path string
- Output file pathtitle string
- Chart titlelabel []string
- Label listprec float64
- PrecisiontplData []byte
- Template dataitems []*ChartDs
- Chart datasets
Returns:
*errs.Error
- Error information
CompareExgBTOrders
Compare exchange backtest orders.
Parameters:
args []string
- Command line argument list