backtest

package
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OriginEChartsJs = "https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"
	MyEChartsJs     = "https://cdnjs.cloudflare.com/ajax/libs/echarts/4.7.0/echarts.min.js"

	OriginEChartsBulmaCss = "https://go-echarts.github.io/go-echarts-assets/assets/bulma.min.css"
	MyEChartsBulmaCss     = "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.8.2/css/bulma.min.css"

	SimpleDateTimeFormat = "2006-01-02 15:04:05.000"
)
View Source
const (
	LogTsKey = "log_ts"
)

Variables

This section is empty.

Functions

func NewCore

NewCore creates a Core that writes logs to a WriteSyncer.

Types

type Backtest

type Backtest struct {
	// contains filtered or unexported fields
}

func NewBacktest

func NewBacktest(datas []*dataloader.Data, symbol string, start time.Time, end time.Time, strategy Strategy, exchanges []ExchangeSim, outputDir string) *Backtest

NewBacktest 创建回测 datas: 数据 symbol: 标 start: 起始时间 end: 结束时间 strategy: 策略 exchanges: 交易所对象 outputDir: 回测输出目录

func NewBacktestFromParams

func NewBacktestFromParams(datas []*dataloader.Data, symbol string, start time.Time, end time.Time,
	strategyParamsList []*StrategyTesterParams, outputDir string) *Backtest

NewBacktest 创建回测 datas: 数据 symbol: 标 start: 起始时间 end: 结束时间 strategyHold: 策略和交易所 outputDir: 回测输出目录

func (*Backtest) ComputeStats

func (b *Backtest) ComputeStats() (result *Stats)

ComputeStats Calculating Backtest Statistics

func (*Backtest) ComputeStatsByIndex

func (b *Backtest) ComputeStatsByIndex(index int) (result *Stats)

func (*Backtest) GetLogs

func (b *Backtest) GetLogs(index int) LogItems

func (*Backtest) GetPrices

func (b *Backtest) GetPrices() (result []float64)

func (*Backtest) GetTime

func (b *Backtest) GetTime() time.Time

GetTime get current time

func (*Backtest) HtmlReport

func (b *Backtest) HtmlReport()

HTMLReport 创建Html报告文件

func (*Backtest) Plot

func (b *Backtest) Plot()

Plot Output backtest results

func (*Backtest) Run

func (b *Backtest) Run()

Run Run backtest

func (*Backtest) SetDatas

func (b *Backtest) SetDatas(datas []*dataloader.Data)

SetData Set data for backtest

type BtLogger

type BtLogger struct {
	Path        string // 文件路径,如:./app.log
	Level       string // 日志输出的级别
	MaxFileSize int    // 日志文件大小的最大值,单位(M)
	MaxBackups  int    // 最多保留备份数
	MaxAge      int    // 日志文件保存的时间,单位(天)
	Compress    bool   // 是否压缩
	Caller      bool   // 日志是否需要显示调用位置
	JsonFormat  bool   // 是否以Json格式输出
	Stdout      bool   // 是否输出到控制台
	// contains filtered or unexported fields
}

func NewBtLogger

func NewBtLogger(gct GetCurrentTime, path string, level string, jsonFormat bool, stdout bool) *BtLogger

func (*BtLogger) Debug

func (l *BtLogger) Debug(args ...interface{})

func (*BtLogger) Debugf

func (l *BtLogger) Debugf(template string, args ...interface{})

func (*BtLogger) Debugw

func (l *BtLogger) Debugw(msg string, keysAndValues ...interface{})

func (*BtLogger) Error

func (l *BtLogger) Error(args ...interface{})

func (*BtLogger) Errorf

func (l *BtLogger) Errorf(template string, args ...interface{})

func (*BtLogger) Errorw

func (l *BtLogger) Errorw(msg string, keysAndValues ...interface{})

func (*BtLogger) Info

func (l *BtLogger) Info(args ...interface{})

func (*BtLogger) Infof

func (l *BtLogger) Infof(template string, args ...interface{})

func (*BtLogger) Infow

func (l *BtLogger) Infow(msg string, keysAndValues ...interface{})

func (*BtLogger) Sync

func (l *BtLogger) Sync()

func (*BtLogger) Warn

func (l *BtLogger) Warn(args ...interface{})

func (*BtLogger) Warnf

func (l *BtLogger) Warnf(template string, args ...interface{})

func (*BtLogger) Warnw

func (l *BtLogger) Warnw(msg string, keysAndValues ...interface{})

type DataState

type DataState struct {
	PrevTime int64 // ns
	Time     int64 // ns
	Index    int   // datas 中的索引
}

type EmptyLogger

type EmptyLogger struct {
}

func (*EmptyLogger) Debug

func (l *EmptyLogger) Debug(args ...interface{})

func (*EmptyLogger) Debugf

func (l *EmptyLogger) Debugf(template string, args ...interface{})

func (*EmptyLogger) Debugw

func (l *EmptyLogger) Debugw(msg string, keysAndValues ...interface{})

func (*EmptyLogger) Error

func (l *EmptyLogger) Error(args ...interface{})

func (*EmptyLogger) Errorf

func (l *EmptyLogger) Errorf(template string, args ...interface{})

func (*EmptyLogger) Errorw

func (l *EmptyLogger) Errorw(msg string, keysAndValues ...interface{})

func (*EmptyLogger) Info

func (l *EmptyLogger) Info(args ...interface{})

func (*EmptyLogger) Infof

func (l *EmptyLogger) Infof(template string, args ...interface{})

func (*EmptyLogger) Infow

func (l *EmptyLogger) Infow(msg string, keysAndValues ...interface{})

func (*EmptyLogger) Sync

func (l *EmptyLogger) Sync()

func (*EmptyLogger) Warn

func (l *EmptyLogger) Warn(args ...interface{})

func (*EmptyLogger) Warnf

func (l *EmptyLogger) Warnf(template string, args ...interface{})

func (*EmptyLogger) Warnw

func (l *EmptyLogger) Warnw(msg string, keysAndValues ...interface{})

type GetCurrentTime

type GetCurrentTime interface {
	GetTime() time.Time
}

type PlotData

type PlotData struct {
	NameItems []string
	Prices    []float64
	Equities  []float64
}

type SOrder

type SOrder struct {
	Ts        time.Time   // ts: 2019-10-02T07:03:53.584+0800
	Order     *Order      // order
	OrderBook *OrderBook  // orderbook
	Positions []*Position // positions
	Balances  []float64   // balances
	Comment   string      // msg: Place order/Match order
}

SOrder "event":"order"/"deal"

func (*SOrder) BalancesString

func (o *SOrder) BalancesString() string

type StrategyTester

type StrategyTester struct {
	*StrategyTesterParams
	// contains filtered or unexported fields
}

func (*StrategyTester) CalAnnReturn

func (t *StrategyTester) CalAnnReturn(s *Stats) float64

计算年化收益

func (*StrategyTester) CalMaxDrawDown

func (t *StrategyTester) CalMaxDrawDown() (result float64)

计算最大回撤

func (*StrategyTester) ComputeStats

func (t *StrategyTester) ComputeStats() (result *Stats)

ComputeStats Calculating Backtest Statistics

func (*StrategyTester) GetLogs

func (t *StrategyTester) GetLogs() LogItems

func (*StrategyTester) HtmlReport

func (t *StrategyTester) HtmlReport()

HTMLReport 创建Html报告文件

func (*StrategyTester) Init

func (t *StrategyTester) Init()

func (*StrategyTester) OnExit

func (t *StrategyTester) OnExit() error

func (*StrategyTester) OnInit

func (t *StrategyTester) OnInit() error

func (*StrategyTester) OnTick

func (t *StrategyTester) OnTick() error

func (*StrategyTester) RunEventLoopOnce

func (t *StrategyTester) RunEventLoopOnce()

func (*StrategyTester) Setup

func (t *StrategyTester) Setup() error

func (*StrategyTester) Sync

func (t *StrategyTester) Sync()

type StrategyTesterParams

type StrategyTesterParams struct {
	// contains filtered or unexported fields
}

func NewStrategyTesterParams

func NewStrategyTesterParams(strategy Strategy, exchanges []ExchangeSim) *StrategyTesterParams

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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