opt

package
v0.2.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2025 License: AGPL-3.0 Imports: 44 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ShowNum = 600
)

Variables

View Source
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"
)
View Source
var BarStatChartData []byte
View Source
var LineChartData []byte
View Source
var (
	PairPickers = make(map[string]func(r *BTResult) []string)
)

Functions

func CollectOptLog

func CollectOptLog(args *config.CmdArgs) *errs.Error

CollectOptLog Collect and analyze the logs generated by RunOptimize Sorts all policy tasks in reverse score order of output. 收集分析RunOptimize生成的日志 将所有策略任务按分数倒序排列输出。

func CompareExgBTOrders

func CompareExgBTOrders(args []string) error

CompareExgBTOrders Compare the exchange export order records with the backtest order records. 对比交易所导出订单记录和回测订单记录。

func DescGroups

func DescGroups(items []*OptInfo) ([]*OptInfo, []*OptInfo)

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

func DumpBarStat(path, title string, maxNum int, data []float64) *errs.Error

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

func DumpEnterTagCumProfits(path string, odList []*ormo.InOutOrder, xNum int) *errs.Error

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 RefreshPairJobs(dp data.IProvider, showLog, isFirst bool, pBar *utils.StagedPrg) *errs.Error

func RunBTOverOpt

func RunBTOverOpt(args *config.CmdArgs) *errs.Error

RunBTOverOpt Backtesting mode based on continuous parameter tuning. Approach the real situation and avoid using future information to adjust parameters for backtesting. 基于持续调参的回测模式。接近实盘情况,避免使用未来信息调参回测。

func RunOptimize

func RunOptimize(args *config.CmdArgs) *errs.Error

func RunRollBTPicker

func RunRollBTPicker(args *config.CmdArgs) *errs.Error

func RunSimBT added in v0.1.33

func RunSimBT(args *config.CmdArgs) *errs.Error

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

func SampleOdNums(odList []*ormo.InOutOrder, num int) ([]int, int64, int64)

SampleOdNums 对一系列订单在整个时间范围的每个时间节点采样计算

Types

type AssetData added in v0.2.0

type AssetData struct {
	Title    string     `json:"title"`
	Labels   []string   `json:"labels"`
	Datasets []*ChartDs `json:"datasets"`
	Times    []int64    // 存储解析后的时间戳
}

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"`
	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"`
	TotProfit    float64    `json:"totProfit"`
	TotCost      float64    `json:"totCost"`
	TotFee       float64    `json:"totFee"`
	TotProfitPct float64    `json:"totProfitPct"`
	WinRatePct   float64    `json:"winRatePct"`
	FinBalance   float64    `json:"finBalance"`
	FinWithdraw  float64    `json:"finWithdraw"`
	SharpeRatio  float64    `json:"sharpeRatio"`
	SortinoRatio float64    `json:"sortinoRatio"`
	// contains filtered or unexported fields
}

func NewBTResult

func NewBTResult() *BTResult

func (*BTResult) BriefLine

func (r *BTResult) BriefLine() string

func (*BTResult) Collect

func (r *BTResult) Collect()

func (*BTResult) DelBigObjects added in v0.1.29

func (r *BTResult) DelBigObjects()

DelBigObjects 删除大对象引用,避免内存泄露

func (*BTResult) Score

func (r *BTResult) Score() float64

type BTSection added in v0.1.33

type BTSection struct {
	StartMS int64
	EndMS   int64
	PairMap map[string]bool
}

type BackTest

type BackTest struct {
	*BackTestLite

	PBar *utils.StagedPrg
	// contains filtered or unexported fields
}

func NewBackTest

func NewBackTest(isOpt bool, outDir string) *BackTest

func (*BackTest) FeedKLine

func (b *BackTest) FeedKLine(bar *orm.InfoKline)

func (*BackTest) Init

func (b *BackTest) Init() *errs.Error

func (*BackTest) Run

func (b *BackTest) Run()

type BackTestLite added in v0.1.29

type BackTestLite struct {
	biz.Trader
	*BTResult
	// contains filtered or unexported fields
}

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.

func (*BackTestLite) FeedKLine added in v0.1.29

func (b *BackTestLite) FeedKLine(bar *orm.InfoKline) bool

type Chart added in v0.1.33

type Chart struct {
	TplData   []byte     `json:"-"`
	Precision float64    `json:"-"`
	Title     string     `json:"title"`
	Labels    []string   `json:"labels"`
	Datasets  []*ChartDs `json:"datasets"`
}

func (*Chart) Dump added in v0.1.33

func (g *Chart) Dump() ([]byte, *errs.Error)

func (*Chart) DumpFile added in v0.1.33

func (g *Chart) DumpFile(path string) *errs.Error

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 FnCalcOptBest = func(items []*OptInfo) *OptInfo

type FuncOptTask

type FuncOptTask func(params map[string]float64) (float64, *errs.Error)

type GroupScore

type GroupScore struct {
	Items []*config.RunPolicyConfig
	Score float64
}

type OptGroup

type OptGroup struct {
	Items []*OptInfo
	Score float64
	Name  string
	Pair  string
	TFStr string
}

type OptInfo

type OptInfo struct {
	Dirt   string
	ID     string
	Score  float64
	Params map[string]float64
	Ints   map[string]bool
	*BTResult
}

func AvgGoodDesc

func AvgGoodDesc(items []*OptInfo, startRate float64, endRate float64) *OptInfo

AvgGoodDesc For profitable groups, cut the specified range in descending order of scores and take the average of the parameters 对盈利的组,按分数降序,截取指定范围,取参数平均值

func (*OptInfo) ToLine

func (o *OptInfo) ToLine() string

func (*OptInfo) ToPol

func (o *OptInfo) ToPol(name, dirt, tfStr, pairStr string) *config.RunPolicyConfig

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"`
	// contains filtered or unexported fields
}

type RowItem

type RowItem struct {
	Title string `json:"title"`
	RowPart
}

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:"durations"`
	Orders       []*ormo.InOutOrder `json:"-"`
	Sharpe       float64            `json:"sharpe"` // 夏普比率
	Sortino      float64            `json:"sortino"`
}

type TimeVal added in v0.1.12

type TimeVal struct {
	Time  int64
	Value float64
}

type ValItem

type ValItem struct {
	Tag   string
	Score float64
	Order int
	Res   int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL