Documentation
¶
Index ¶
- Constants
- Variables
- func BacktestToCompare()
- func BtFactors(args []string) error
- func BuildBtResult(args *config.CmdArgs) *errs.Error
- func CalcBtScore(profitPct, drawDownPct float64) float64
- func CalcMeasureByOrders(ods []*ormo.InOutOrder) (float64, float64, *errs.Error)
- func CalcMeasuresByReal(real []float64, rangeSecs int64, tf string, factor int, riskFree float64) (float64, float64, *errs.Error)
- func CollectOptLog(args *config.CmdArgs) *errs.Error
- func CompareExgBTOrders(args []string) error
- func CutOrdersInRange(orders []*ormo.InOutOrder, startMS, endMS int64) (map[string][]*ormo.InOutOrder, *errs.Error)
- func DescGroups(items []*OptInfo) ([]*OptInfo, []*OptInfo)
- func DumpBarStat(path, title string, maxNum int, data []float64) *errs.Error
- func DumpChart(path, title string, label []string, prec float64, tplData []byte, ...) *errs.Error
- func DumpEnterTagCumProfits(path string, odList []*ormo.InOutOrder, xNum int) *errs.Error
- func DumpOrdersCSV(orders []*ormo.InOutOrder, outPath string) error
- func MergeAssetsHtml(outPath string, files map[string]string, tags []string, useRate bool) *errs.Error
- func RefreshPairJobs(dp data.IProvider, showLog, isFirst bool, pBar *utils.StagedPrg) *errs.Error
- func RunBTOverOpt(args *config.CmdArgs) *errs.Error
- func RunOptimize(args *config.CmdArgs) *errs.Error
- func RunRollBTPicker(args *config.CmdArgs) *errs.Error
- func RunSimBT(args *config.CmdArgs) *errs.Error
- func SampleOdNums(odList []*ormo.InOutOrder, num int) ([]int, int64, int64)
- func ZipBacktestResult(resultPath string, cleanIfSuccess, withOrders bool, maxFileSize int64) ([]byte, error)
- type AssetData
- type BTResult
- type BTSection
- type BackTest
- type BackTestLite
- type Chart
- type ChartDs
- type FacArgs
- type FnCalcOptBest
- type FuncOptTask
- type GroupScore
- type OptGroup
- type OptInfo
- type PairStat
- type PlotData
- type RowItem
- type RowPart
- type TimeVal
- type ValItem
Constants ¶
const (
ShowNum = 600
)
Variables ¶
var ( MapCalcOptBest = map[string]FnCalcOptBest{ "score": getBestByScore, "good3": optGood3, "good0t3": optGood0t3, "goodAvg": optGoodMa, "good1t4": optGood1t4, "good4": optGood4, "good2": optGood2, "good5": optGood5, "good7": optGood7, "good2t5": optGood2t5, "good3t7": optGood3t7, "good0t7": optGood0t7, "good3t10": optGood3t10, } DefCalcOptBest = "good3" AfterBacktest func(bt *BackTest) )
var BarStatChartData []byte
var LineChartData []byte
var (
PairPickers = make(map[string]func(r *BTResult) []string)
)
Functions ¶
func CalcBtScore ¶ added in v0.2.16
func CalcMeasureByOrders ¶ added in v0.2.16
func CalcMeasuresByReal ¶ added in v0.2.16
func CalcMeasuresByReal(real []float64, rangeSecs int64, tf string, factor int, riskFree float64) (float64, float64, *errs.Error)
CalcMeasuresByReal real & rangeSecs are required, tf=1d, factor=365, riskFree=0
func CollectOptLog ¶
CollectOptLog Collect and analyze the logs generated by RunOptimize Sorts all policy tasks in reverse score order of output. 收集分析RunOptimize生成的日志 将所有策略任务按分数倒序排列输出。
func CompareExgBTOrders ¶
CompareExgBTOrders Compare the exchange export order records with the backtest order records. 对比交易所导出订单记录和回测订单记录。
func CutOrdersInRange ¶ added in v0.2.16
func CutOrdersInRange(orders []*ormo.InOutOrder, startMS, endMS int64) (map[string][]*ormo.InOutOrder, *errs.Error)
func DescGroups ¶
DescGroups Divide the parameter group into profit and loss groups, both in descending order of scores; Return: Profit group, loss group 将参数组划分为盈利和亏损两组,都按分数降序;返回:盈利组,亏损组
func DumpBarStat ¶ added in v0.1.33
DumpBarStat generate bar chart for data Distribution Statistics 生成数据分布的条形图
func DumpChart ¶ added in v0.1.33
func DumpChart(path, title string, label []string, prec float64, tplData []byte, items []*ChartDs) *errs.Error
DumpChart dump a chart html with datasets. draw line chart if tplData is nil
func DumpEnterTagCumProfits ¶ added in v0.1.33
DumpEnterTagCumProfits
export line chart of cumulative profit based on entry tag statistics
按入场信号统计累计利润导出折线图
func DumpOrdersCSV ¶ added in v0.1.33
func DumpOrdersCSV(orders []*ormo.InOutOrder, outPath string) error
func MergeAssetsHtml ¶ added in v0.2.0
func MergeAssetsHtml(outPath string, files map[string]string, tags []string, useRate bool) *errs.Error
MergeAssetsHtml 合并多个assets.html文件的曲线到一个html文件中
files assets.html文件路径Map,键是路径,值是代表此文件的字符串ID outPath 输出文件路径 lines 需要提取的曲线名称列表,默认为["Real", "Available"]
func RefreshPairJobs ¶ added in v0.1.29
func RunBTOverOpt ¶
RunBTOverOpt Backtesting mode based on continuous parameter tuning. Approach the real situation and avoid using future information to adjust parameters for backtesting. 基于持续调参的回测模式。接近实盘情况,避免使用未来信息调参回测。
func RunSimBT ¶ added in v0.1.33
RunSimBT Perform rolling simulation backtest, extract trading symbols for each time range from the log file, export orders & enters2.html
执行滚动模拟回测,从日志文件中提取每个区间的交易品种,并进行回测;导出订单记录和enters2.html
func SampleOdNums ¶ added in v0.2.1
SampleOdNums 对一系列订单在整个时间范围的每个时间节点采样计算
Types ¶
type BTResult ¶
type BTResult struct {
MaxOpenOrders int `json:"maxOpenOrders"`
MinReal float64 `json:"minReal"`
MaxReal float64 `json:"maxReal"` // Maximum Assets 最大资产
MaxDrawDownPct float64 `json:"maxDrawDownPct"` // Maximum drawdown percentage 最大回撤百分比
ShowDrawDownPct float64 `json:"showDrawDownPct"` // Displays the maximum drawdown percentage 显示最大回撤百分比
MaxDrawDownVal float64 `json:"maxDrawDownVal"` // Maximum drawdown percentage 最大回撤金额
ShowDrawDownVal float64 `json:"showDrawDownVal"` // Displays the maximum drawdown percentage 显示最大回撤金额
MaxFundOccup float64 `json:"maxFundOccup"`
MaxOccupForPair float64 `json:"maxOccupForPair"`
BarNum int `json:"barNum"`
TimeNum int `json:"timeNum"`
OrderNum int `json:"orderNum"`
Plots *PlotData `json:"plots"`
EntLabels []string `json:"entLabels"`
EntDatasets []*ChartDs `json:"entDatasets"`
CreateMS int64 `json:"createMS"`
StartMS int64 `json:"startMS"`
EndMS int64 `json:"endMS"`
PlotEvery int `json:"plotEvery"`
TotalInvest float64 `json:"totalInvest"`
OutDir string `json:"outDir"`
PairGrps []*RowItem `json:"pairGrps"`
DateGrps []*RowItem `json:"dateGrps"`
EnterGrps []*RowItem `json:"enterGrps"`
ExitGrps []*RowItem `json:"exitGrps"`
ProfitGrps []*RowItem `json:"profitGrps"`
DrawDowns []*core.TimeValueRange `json:"drawDowns"`
TmpDrawDown *core.TimeValueRange `json:"-"`
TotProfit float64 `json:"totProfit"`
TotCost float64 `json:"totCost"`
TotFee float64 `json:"totFee"`
TotProfitPct float64 `json:"totProfitPct"`
TfHits map[string]int `json:"tfHits"`
WinRatePct float64 `json:"winRatePct"`
FinBalance float64 `json:"finBalance"`
FinWithdraw float64 `json:"finWithdraw"`
SharpeRatio float64 `json:"sharpeRatio"`
SortinoRatio float64 `json:"sortinoRatio"`
CalcDiff float64 `json:"calcDiff"`
Stability float64 `json:"stability"`
HitSlTp int `json:"hitSlTp"`
// contains filtered or unexported fields
}
func NewBTResult ¶
func NewBTResult() *BTResult
func (*BTResult) DelBigObjects ¶ added in v0.1.29
func (r *BTResult) DelBigObjects()
DelBigObjects 删除大对象引用,避免内存泄露
func (*BTResult) DumpCharts ¶ added in v0.2.21
func (r *BTResult) DumpCharts()
type BackTest ¶
type BackTest struct {
*BackTestLite
PBar *utils.StagedPrg
// contains filtered or unexported fields
}
type BackTestLite ¶ added in v0.1.29
func NewBackTestLite ¶ added in v0.1.29
func NewBackTestLite(isOpt bool, onBar data.FnPairKline, getEnd data.FnGetInt64, pBar *utils.StagedPrg) *BackTestLite
NewBackTestLite 创建一个临时内部回测,仅用于寻找回测未平仓订单来接力 Create a temporary internal backtest, solely for the purpose of finding backtest open orders to relay.
type Chart ¶ added in v0.1.33
type ChartDs ¶ added in v0.1.9
type ChartDs struct {
Label string `json:"label"`
Data []float64 `json:"data"`
Color string `json:"color,omitempty"`
BorderColor string `json:"borderColor,omitempty"`
BackgroundColor string `json:"backgroundColor,omitempty"`
YAxisID string `json:"yAxisID,omitempty"`
Hidden bool `json:"hidden"`
}
func CalcGroupCumProfits ¶ added in v0.1.33
func CalcGroupCumProfits(odList []*ormo.InOutOrder, genKey func(o *ormo.InOutOrder) string, xNum int) ([]string, []*ChartDs, *errs.Error)
CalcGroupCumProfits
calculate cumulative profit curve data for orders (obtain K-line and calculate real-time cumulative profit for open positions)
生成订单累计利润曲线数据(获取K线,计算实时持仓累计利润)
func CalcGroupEndProfits ¶ added in v0.1.33
func CalcGroupEndProfits(odList []*ormo.InOutOrder, genKey func(o *ormo.InOutOrder) string, xNum int) ([]string, []*ChartDs)
CalcGroupEndProfits
calculate cumulative profit curve data for orders (directly using profit accumulation when closing positions)
生成订单累计利润曲线数据(直接使用平仓时利润累加)
type FnCalcOptBest ¶
type GroupScore ¶
type GroupScore struct {
Items []*config.RunPolicyConfig
Score float64
}
type OptInfo ¶
type OptInfo struct {
Dirt string
ID string
Score float64
Params map[string]float64
Ints map[string]bool
*BTResult
}
func AvgGoodDesc ¶
AvgGoodDesc For profitable groups, cut the specified range in descending order of scores and take the average of the parameters 对盈利的组,按分数降序,截取指定范围,取参数平均值
type PairStat ¶ added in v0.2.16
type PairStat struct {
*orm.ExSymbol
Orders []*ormo.InOutOrder
KLines []*banexg.Kline
Returns []float64
Idx int
}
func CalcPairStats ¶ added in v0.2.16
type PlotData ¶
type PlotData struct {
Labels []string `json:"labels"`
OdNum []int `json:"odNum"`
JobNum []int `json:"jobNum"`
Real []float64 `json:"real"`
Available []float64 `json:"available"`
Profit []float64 `json:"profit"`
UnrealizedPOL []float64 `json:"unrealizedPOL"`
WithDraw []float64 `json:"withDraw"`
More []*ChartDs `json:"more"`
// contains filtered or unexported fields
}
type RowPart ¶
type RowPart struct {
WinCount int `json:"winCount"`
OrderNum int `json:"orderNum"`
ProfitSum float64 `json:"profitSum"`
ProfitPctSum float64 `json:"profitPctSum"`
CostSum float64 `json:"costSum"`
Durations []int `json:"-"`
Orders []*ormo.InOutOrder `json:"-"`
Sharpe float64 `json:"sharpe"` // 夏普比率
Sortino float64 `json:"sortino"`
}