cache

package
v1.12.13 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KBarIndex = "barIndex"
	KLineMin  = 120 // K线最少记录数
)
View Source
const (
	FORMAT_PROTOCOL_DATE = "20060102"   // 通达信协议的日期字符串格式
	CACHE_DATE           = "20060102"   // 缓存日期
	INDEX_DATE           = "2006-01-02" // 索引日期格式
	PROTOCOL_DATE        = "20060102"   // 协议日期格式
	YearOnly             = "2006"       // 仅年份
	TimeStampMilli       = "2006-01-02 15:04:05.000"
	TimeStampMicro       = "2006-01-02 15:04:05.000000"
	TimeStampNano        = "2006-01-02 15:04:05.000000000"
)
View Source
const (
	// DefaultDataProvider 默认数据提供者
	DefaultDataProvider = "engine"
)
View Source
const (
	FilenameDate = "20060102" // 缓存文件相关的日期格式
)
View Source
const (
	UseGoroutine = false // 更新和修复数据是否启用协程
)

Variables

View Source
var (
	ErrAlreadyExists = errors.New("the plugin already exists")
)
View Source
var OpMap = map[OpKind]string{
	OpUpdate:   "更新",
	OpRepair:   "修复",
	OpIncr:     "增量",
	OpBackTest: "回测",
}

Functions

func BacktestFilename added in v1.11.12

func BacktestFilename(factorName, date string) string

BacktestFilename 回测结果文件

func CacheId

func CacheId(code string) string

CacheId 通过代码构建目录结构

func CacheIdPath

func CacheIdPath(code string) string

CacheIdPath code从后保留3位, 市场缩写+从头到倒数第3的代码, 确保每个目录只有000~999个代码

func ChipsFilename added in v1.9.9

func ChipsFilename(securityCode string) string

ChipsFilename 筹码分布文件

func CorrectDate added in v0.1.5

func CorrectDate(date string) (cacheDate, resourcesDate string)

CorrectDate 校正日期

func DefaultCanReadDate added in v0.1.5

func DefaultCanReadDate() string

DefaultCanReadDate 获取默认可以读缓存文件的日期

func DefaultCanUpdateDate added in v0.1.5

func DefaultCanUpdateDate() string

DefaultCanUpdateDate 获取默认可以更新缓存文件的日期

func FundFlowFilename added in v0.5.1

func FundFlowFilename(securityCode string) string

FundFlowFilename 通过证券代码获取资金流向的缓存文件路径

func GetBacktestCachePath added in v1.11.12

func GetBacktestCachePath() string

GetBacktestCachePath 回测结果路径

func GetChipsPath added in v1.9.9

func GetChipsPath() string

GetChipsPath 筹码分布路径

func GetDayPath

func GetDayPath() string

GetDayPath 历史数据-日线缓存路径

func GetFundFlowPath

func GetFundFlowPath() string

GetFundFlowPath 资金流向目录

func GetHoldingPath

func GetHoldingPath() string

GetHoldingPath 十大流通股股东数据路径

func GetInfoPath added in v0.1.5

func GetInfoPath() string

GetInfoPath 信息路径

func GetKLinePath added in v1.10.4

func GetKLinePath(freq string) string

GetKLinePath 历史数据-K线缓存路径

func GetLoggerPath

func GetLoggerPath() string

GetLoggerPath 获取日志路径

func GetMetaPath

func GetMetaPath() string

GetMetaPath 元数据路径

func GetMinutePath added in v0.5.3

func GetMinutePath() string

GetMinutePath 分时路径

func GetQmtCachePath added in v1.0.7

func GetQmtCachePath() string

GetQmtCachePath QMT订单文件路径

func GetQuarterlyPath deprecated added in v0.1.5

func GetQuarterlyPath() string

GetQuarterlyPath 季报路径

Deprecated: 不推荐

func GetRootPath

func GetRootPath() string

GetRootPath 获取缓存根路径

func GetSnapshotPath

func GetSnapshotPath() string

GetSnapshotPath 快照路径

func GetTransPath added in v1.1.5

func GetTransPath() string

GetTransPath 成交数据路径

func GetVariablePath

func GetVariablePath() string

GetVariablePath 获取VAR路径

func GetWidePath added in v1.1.5

func GetWidePath() string

GetWidePath 获取特征路径

func GetXdxrPath

func GetXdxrPath() string

GetXdxrPath 除权除息文件存储路径

func GetZxgFile added in v0.2.3

func GetZxgFile() string

GetZxgFile 自选股文件路径

func KLineFilename

func KLineFilename(code string) string

KLineFilename 基础K线缓存路径

func KLineFilenameEx added in v1.10.4

func KLineFilenameEx(code string, freq string) string

KLineFilenameEx K线缓存路径

func MinuteFilename added in v0.5.3

func MinuteFilename(code, date string) string

func PreviewReportFilename added in v0.6.2

func PreviewReportFilename(date string) string

PreviewReportFilename 业绩预告文件名

func QuarterlyReportFilename added in v0.1.5

func QuarterlyReportFilename(code, date string) string

QuarterlyReportFilename 季报存储路径

info
  |-- YYYYQ1
        |--  sh600105.report
  |-- YYYYQ2
  |-- YYYYQ3
  |-- YYYYQ4
Deprecated: 不推荐使用

func Register added in v0.1.7

func Register(plugin DataAdapter) error

Register 注册插件

func ReportsFilename added in v0.1.5

func ReportsFilename(date string) string

ReportsFilename 报告数据文件名

func Reset

func Reset()

Reset 重置日志记录器

func SnapshotFilename added in v0.5.1

func SnapshotFilename(securityCode string, date string) string

SnapshotFilename 快照数据文件

func Today added in v0.5.4

func Today() string

func Top10HoldersFilename added in v0.1.5

func Top10HoldersFilename(code, date string) string

Top10HoldersFilename 前十大流通股股东缓存文件名

func TransFilename added in v1.1.5

func TransFilename(code, date string) string

TransFilename 历史成交数据文件比较多, 目录结构${tick}/${YYYY}/${YYYYMMDD}/${CacheIdPath}

func WideFilename added in v1.1.5

func WideFilename(code string) string

WideFilename 宽表据缓存路径

func XdxrFilename

func XdxrFilename(code string) string

XdxrFilename XDXR缓存路径

Types

type DataAdapter added in v0.3.2

type DataAdapter interface {
	// Schema 继承基础特性接口
	Schema
	// Print 控制台输出指定日期的数据
	Print(code string, date ...string)
}

DataAdapter 数据插件

func GetDataAdapter added in v1.3.0

func GetDataAdapter(kind Kind) DataAdapter

GetDataAdapter 获取数据适配器

func Plugins added in v0.1.7

func Plugins(mask ...Kind) (list []DataAdapter)

Plugins 按照类型标志位捡出数据插件

func PluginsWithName added in v0.2.0

func PluginsWithName(pluginType Kind, keywords ...string) (list []DataAdapter)

type DataFile added in v0.3.2

type DataFile interface {
	// Checkout 捡出指定日期的缓存数据
	Checkout(securityCode, date string)
	// Filename 缓存文件名
	//	接受两个参数 日期和证券代码
	// 	文件名为空不缓存
	Filename(date, securityCode string) string
	// Check 数据校验
	Check(cacheDate, featureDate string) error
}

DataFile 基础数据文件接口

type DataSummary added in v0.3.2

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

DataSummary 数据概要

func Summary added in v0.3.2

func Summary(kind Kind, key, name, owner string, usage ...string) DataSummary

func (DataSummary) Key added in v0.3.2

func (d DataSummary) Key() string

func (DataSummary) Kind added in v0.3.2

func (d DataSummary) Kind() Kind

func (DataSummary) Name added in v0.3.2

func (d DataSummary) Name() string

func (DataSummary) Owner added in v0.3.2

func (d DataSummary) Owner() string

func (DataSummary) Usage added in v0.3.4

func (d DataSummary) Usage() string

type Depend added in v0.1.7

type Depend interface {
	DependOn() []Kind
}

type FactorMetrics added in v1.11.12

type FactorMetrics struct {
	Name           string        `name:"name"`            // 名称
	Kind           Kind          `name:"kind"`            // 类型
	Count          int           `name:"count"`           // 总数(处理样本数)
	Signals        int           `name:"signals"`         // 信号数
	Passed         int           `name:"passed"`          // 通过检测数
	Max            time.Duration `name:"max"`             // 最大值
	Min            time.Duration `name:"min"`             // 最小值
	TotalDuration  time.Duration `name:"total_duration"`  // 总耗时
	Speed          float64       `name:"speed"`           // 速度 = Count / seconds
	SignalCoverage float64       `name:"signal_coverage"` // 信号覆盖率 = Signals / Count
	WinRate        float64       `name:"win_rate"`        // 胜率 = Passed / Signals
}

FactorMetrics 适配器性能/绩效指标

type FactorSignalEvaluator added in v1.11.12

type FactorSignalEvaluator interface {
	// Check 对指定cacheDate和featureDate进行特征数据验证。
	// 返回值含义:
	//   hasSignal == true : 该日期产生了有效信号(用于统计信号覆盖率)
	//   err == nil        : 校验通过(即数据有效/逻辑正确)
	//   err != nil        : 校验失败, 需要记录或输出错误信息, hasSignal值在此场景下不参与胜率统计
	// 统计建议:
	//   Signals 计数: hasSignal==true 且 err==nil
	//   Passed  计数: err==nil (通过的数据样本)
	//   WinRate = PassedSignals / Signals (若需要区分“通过且有信号”)
	//   当前接口保持最小语义, 扩展需求可引入 ValidationResult 结构
	// NOTE: 不将 err==nil 自动推导为 hasSignal=true, 两者独立
	//
	Check(cacheDate, featureDate string) (hasSignal bool, err error)
}

FactorSignalEvaluator 因子验证接口

type Future added in v0.3.2

type Future interface {
	// Update 更新数据
	// 	whole 是否完整的数据, false是加工成半成品数据, 为了配合Increase
	Update(securityCode, cacheDate, featureDate string, whole bool)
	// Repair 回补数据
	Repair(securityCode, cacheDate, featureDate string, whole bool)
}

Future 预备数据的接口

type Handover added in v0.1.7

type Handover interface {
	// ChangingOverDate 缓存数据转换日期
	//	数据集等基础数据不需要切换日期
	ChangingOverDate(date string)
}

Handover 缓存切换接口

type Increase added in v0.3.2

type Increase[T any] interface {
	Add(data T) T
}

Increase 增量数据计算接口

deprecated: 不推荐

type Initialization added in v0.3.4

type Initialization interface {
	// Init 初始化, 接受context, 日期作为入参
	Init(ctx context.Context, date string) error
}

Initialization 初始化接口

type Kind added in v0.1.7

type Kind = uint64
const (
	PluginMaskBaseData Kind = 0x1000000000000000 // 基础数据
	PluginMaskFeature  Kind = 0x2000000000000000 // 特征数据
	PluginMaskStrategy Kind = 0x3000000000000000 // 策略
)

type Manifest added in v0.3.8

type Manifest interface {
	Schema         // 概要信息
	Properties     // 属性
	Initialization // 初始化
}

Manifest 提要

type OpKind added in v0.2.7

type OpKind int
const (
	OpUpdate   OpKind = iota + 1 // 更新
	OpRepair                     // 修复
	OpIncr                       // 增量
	OpBackTest                   // 回测
)

type Operator added in v0.3.2

type Operator interface {
	// Pull 拉取数据
	Pull(date, securityCode string) Operator
}

Operator 缓存操作接口

数据操作, 包含初始化和拉取两个接口

type Properties added in v0.3.4

type Properties interface {
	// GetDate 日期
	GetDate() string
	// GetSecurityCode 证券代码
	GetSecurityCode() string
}

Properties 属性接口

type Schema added in v0.3.9

type Schema interface {
	// Kind 数据类型
	Kind() Kind
	// Owner 提供者
	Owner() string
	// Key 数据关键词, key与cache落地强关联
	Key() string
	// Name 特性名称
	Name() string
	// Usage 控制台参数提示信息, 数据描述(data description)
	Usage() string
}

Schema 缓存的概要信息

type ScoreBoard added in v0.3.2

type ScoreBoard struct {
	FactorMetrics
	// contains filtered or unexported fields
}

ScoreBoard 记分牌, 线程安全

func (*ScoreBoard) Add added in v0.3.2

func (s *ScoreBoard) Add(delta int, take time.Duration, signal, pass bool)

Add 记录一次处理的性能及结果 参数说明:

delta  : 本次增加的样本数量(通常=1)
take   : 本次处理耗时
signal : 是否产生信号(hasSignal && err==nil)
pass   : 是否校验通过(err==nil)

统计逻辑:

Count   += delta
Signals += signal?1:0
Passed  += pass?1:0
SignalCoverage = Signals / Count
WinRate        = Passed / Signals (Signals==0时为0)

func (*ScoreBoard) From added in v1.3.0

func (s *ScoreBoard) From(adapter DataAdapter)

func (*ScoreBoard) Metric added in v1.9.4

func (s *ScoreBoard) Metric() FactorMetrics

func (*ScoreBoard) String added in v0.3.2

func (s *ScoreBoard) String() string

Jump to

Keyboard shortcuts

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