Documentation ¶
Index ¶
- Variables
- func AlignTfMSecs(timeMSecs int64, tfMSecs int64) int64
- func AlignTfMSecsOffset(timeMSecs, tfMSecs, offset int64) int64
- func AlignTfSecs(timeSecs int64, tfSecs int) int64
- func AlignTfSecsOffset(timeSecs int64, tfSecs int, offset int) int64
- func ArrToMap[T1 comparable, T2 any](arr []T2, doMap func(T2) T1) map[T1][]T2
- func AutoCorrPenalty(returns []float64) float64
- func BuildOHLCV(arr []*banexg.Kline, toTFMSecs int64, preFire float64, ...) ([]*banexg.Kline, bool)
- func CalcCorrMat(dataArr [][]float64, useChgRate bool) (*mat.SymDense, []float64, error)
- func CalcEnvsCorr(envs []*ta.BarEnv, hisNum int) (*mat.SymDense, []float64, error)
- func CalcExpectancy(profits []float64) (float64, float64)
- func CalcMaxDrawDown(profits []float64, initBalance float64) (float64, float64, int, int, float64, float64)
- func Check(err error)
- func ConvertArr[T1, T2 any](arr []T1, doMap func(T1) T2) []T2
- func ConvertFloat64(i interface{}) float64
- func ConvertInt64(i interface{}) int64
- func Copy(srcFile, dstFile string) error
- func CopyDir(src, dst string) error
- func CopySymLink(source, dest string) error
- func CutMap[M ~map[K]V, K comparable, V any](m M, keys ...K) M
- func DecArithMean(values []decimal.Decimal) (decimal.Decimal, error)
- func DecArrToFloats(arr []decimal.Decimal) []float64
- func DecFinaGeomMean(values []decimal.Decimal) (decimal.Decimal, error)
- func DecPow(x, y decimal.Decimal) decimal.Decimal
- func DecSharpeRatio(moReturns []decimal.Decimal, riskFree decimal.Decimal) (decimal.Decimal, error)
- func DecSharpeRatioAdv(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecSharpeRatioBy(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecSharpeRatioSmart(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecSortinoRatio(moReturns []decimal.Decimal, riskFree decimal.Decimal) (decimal.Decimal, error)
- func DecSortinoRatioAdv(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecSortinoRatioBy(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecSortinoRatioSmart(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, ...) (decimal.Decimal, error)
- func DecStdDev(values []decimal.Decimal) (decimal.Decimal, error)
- func DecodeMsgData(input interface{}, out interface{}, name string) bool
- func DeepCopyMap(dst, src map[string]interface{})
- func DelNetLock(key string, lockVal int32) *errs.Error
- func DoHttp(client *http.Client, req *http.Request) *banexg.HttpRes
- func EnsureDir(dir string, perm os.FileMode) error
- func EqualIn(a, b, thres float64) bool
- func EqualNearly(a, b float64) bool
- func Exists(filePath string) bool
- func FloatsToDecArr(arr []float64) []decimal.Decimal
- func FormatWithMap(text string, args map[string]interface{}) string
- func GcdInts(numbers []int) int
- func GenCorrImg(m *mat.SymDense, title string, names []string, fontName string, ...) ([]byte, error)
- func GetFilesWithPrefix(filePath string) ([]string, error)
- func GetFontData(name string) ([]byte, error)
- func GetNetLock(key string, timeout int) (int32, *errs.Error)
- func GetOpenFont(name string) (*opentype.Font, error)
- func GetServerData(key string) (interface{}, *errs.Error)
- func GetTfAlignOrigin(secs int) (string, int)
- func KeysOfMap[M ~map[K]V, K comparable, V any](m M) []K
- func KlineToStr(klines []*banexg.Kline, loc *time.Location) [][]string
- func MD5(data []byte) string
- func MapToStr(m map[string]float64) (string, int)
- func NearScore(x, mid, rate float64) float64
- func NumSign(obj interface{}) int
- func PadCenter(s string, width int, padText string) string
- func ParallelRun[T any](items []T, concurNum int, handle func(int, T) *errs.Error) *errs.Error
- func PrintErr(e error) string
- func ReadCSV(path string) ([][]string, *errs.Error)
- func ReadConfirm(tips []string, ok, fail string, exitAny bool) bool
- func ReadInput(tips []string) (string, error)
- func ReadLastNLines(filePath string, lineCount int) ([]string, error)
- func ReadXlsx(path, sheet string) ([][]string, *errs.Error)
- func RemoveFromArr[T comparable](arr []T, it T, num int) []T
- func ReverseArr[T any](s []T)
- func SecsToTF(tfSecs int) string
- func SetServerData(args *KeyValExpire) *errs.Error
- func SharpeRatio(moReturns []float64, riskFree float64) (float64, error)
- func SharpeRatioAdv(moReturns []float64, riskFree float64, periods int, annualize, smart bool) (float64, error)
- func SharpeRatioBy(moReturns []float64, riskFree float64, periods int, annualize bool) (float64, error)
- func SharpeRatioSmart(moReturns []float64, riskFree float64, periods int, annualize bool) (float64, error)
- func SnakeToCamel(input string) string
- func SortinoRatio(moReturns []float64, riskFree float64) (float64, error)
- func SortinoRatioAdv(moReturns []float64, riskFree float64, periods int, annualize, smart bool) (float64, error)
- func SortinoRatioBy(moReturns []float64, riskFree float64, periods int, annualize bool) (float64, error)
- func SortinoRatioSmart(moReturns []float64, riskFree float64, periods int, annualize bool) (float64, error)
- func SplitSolid(text string, sep string) []string
- func StdDevVolatility(data []float64, rate float64) float64
- func TFToSecs(timeFrame string) int
- func UnionArr[T comparable](arrs ...[]T) []T
- func UniqueItems[T comparable](arr []T) ([]T, []T)
- func ValsOfMap[M ~map[K]V, K comparable, V any](m M) []V
- func WriteCsvFile(path string, rows [][]string, compress bool) *errs.Error
- func WriteFile(path string, data []byte) *errs.Error
- type BanConn
- func (c *BanConn) GetRemote() string
- func (c *BanConn) HasTag(tag string) bool
- func (c *BanConn) IsClosed() bool
- func (c *BanConn) Read() ([]byte, *errs.Error)
- func (c *BanConn) ReadMsg() (*IOMsg, *errs.Error)
- func (c *BanConn) RunForever() *errs.Error
- func (c *BanConn) Subscribe(tags ...string)
- func (c *BanConn) UnSubscribe(tags ...string)
- func (c *BanConn) Write(data []byte, locked bool) *errs.Error
- func (c *BanConn) WriteMsg(msg *IOMsg) *errs.Error
- type ClientIO
- type Cluster
- type ClusterRes
- type ConnCB
- type IBanConn
- type IOKeyVal
- type IOMsg
- type KeyValExpire
- type PrgBar
- type PrgBarJob
- type ServerIO
- type TFOrigin
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoNegativeResults is returned when no negative results are allowed ErrNoNegativeResults = errors.New("cannot calculate with no negative values") )
Functions ¶
func AlignTfMSecs ¶
AlignTfMSecs Convert the given 13 millisecond timestamp to the header start timestamp for the specified time period 将给定的13位毫秒级时间戳,转为指定时间周期下,的头部开始时间戳
func AlignTfMSecsOffset ¶
func AlignTfSecs ¶
AlignTfSecs Convert the given 10 second timestamp to the header start timestamp for the specified time period 将给定的10位秒级时间戳,转为指定时间周期下,的头部开始时间戳
func AlignTfSecsOffset ¶
AlignTfSecsOffset Convert the given 10 second timestamp to the header start timestamp for the specified time period, using the specified offset 将给定的10位秒级时间戳,转为指定时间周期下,的头部开始时间戳,使用指定偏移
func ArrToMap ¶
func ArrToMap[T1 comparable, T2 any](arr []T2, doMap func(T2) T1) map[T1][]T2
func AutoCorrPenalty ¶
AutoCorrPenalty Metric to account for auto correlation
func BuildOHLCV ¶
func BuildOHLCV(arr []*banexg.Kline, toTFMSecs int64, preFire float64, resOHLCV []*banexg.Kline, fromTFMS, offMS int64) ([]*banexg.Kline, bool)
BuildOHLCV Build or update coarser grained OHLC arrays from transactions or sub OHLC arrays. Arr: List of sub OHLC. ToTFSecs: Specify the time granularity to be built, in milliseconds PreFire: The rate at which builds are triggered ahead of schedule; ResOHLCV: Existing array to be updated From TFSets: The interval between the arr subarrays passed in, calculated when not provided, in milliseconds OffMS: offset of alignment time 从交易或子OHLC数组中,构建或更新更粗粒度OHLC数组。 arr: 子OHLC列表。 toTFSecs: 指定要构建的时间粒度,单位:毫秒 preFire: 提前触发构建完成的比率; resOHLCV: 已有的待更新数组 fromTFSecs: 传入的arr子数组间隔,未提供时计算,单位:毫秒 offMS: 对齐时间的偏移
func CalcCorrMat ¶
CalcCorrMat calculate Correlation Matrix for given data
func CalcEnvsCorr ¶ added in v0.1.7
func CalcExpectancy ¶
CalcExpectancy Calculate expected returns and risk return ratio 计算收益期望、风险回报率
func CalcMaxDrawDown ¶
func CalcMaxDrawDown(profits []float64, initBalance float64) (float64, float64, int, int, float64, float64)
CalcMaxDrawDown Calculate maximum drawdown Calculate the maximum drawdown percentage position when initBalance is provided; No location provided for calculating the maximum loss Return: Maximum drawdown percentage, maximum drawdown amount, maximum value index, minimum value index, maximum value, minimum value 计算最大回撤 initBalance 提供时计算最大回撤百分比位置;未提供计算亏损最多时位置 返回:最大回撤百分比、最大回撤额、最大值索引、最小值索引、最大值、最小值
func ConvertArr ¶
func ConvertArr[T1, T2 any](arr []T1, doMap func(T1) T2) []T2
func ConvertFloat64 ¶
func ConvertFloat64(i interface{}) float64
func ConvertInt64 ¶
func ConvertInt64(i interface{}) int64
func CopySymLink ¶
func CutMap ¶
func CutMap[M ~map[K]V, K comparable, V any](m M, keys ...K) M
func DecArithMean ¶
DecArithMean is the basic form of calculating an average. Divide the sum of all values by the length of values
func DecArrToFloats ¶
func DecFinaGeomMean ¶
DecFinaGeomMean is a modified geometric average to assess the negative returns of investments. It accepts It adds +1 to each This does impact the final figures as it is modifying values It is still ultimately calculating a geometric average which should only be compared to other financial geometric averages
func DecSharpeRatio ¶
DecSharpeRatio use 252 as default periods to calculate annualize
func DecSharpeRatioAdv ¶
func DecSharpeRatioBy ¶
func DecSharpeRatioSmart ¶
func DecSortinoRatio ¶
func DecSortinoRatioAdv ¶
func DecSortinoRatioAdv(moReturns []decimal.Decimal, riskFree decimal.Decimal, periods int, annualize, smart bool) (decimal.Decimal, error)
DecSortinoRatioAdv returns sortino ratio of backtest compared to risk-free
func DecSortinoRatioBy ¶
func DecSortinoRatioSmart ¶
func DecodeMsgData ¶
func DeepCopyMap ¶
func DeepCopyMap(dst, src map[string]interface{})
func EqualIn ¶
EqualIn Determine whether two floats are approximately equal within a certain range 判断两个float是否在一定范围内近似相等
func EqualNearly ¶
EqualNearly Determine whether two floats are approximately equal and solve the problem of inequality caused by floating-point close reading 判断两个float是否近似相等,解决浮点精读导致不等
func FloatsToDecArr ¶
func FormatWithMap ¶
func GcdInts ¶
GcdMultiple Calculate the greatest common divisor of all elements in a slice 计算一个切片中所有元素的最大公约数
func GenCorrImg ¶
func GetFilesWithPrefix ¶ added in v0.1.7
func GetFontData ¶
func GetServerData ¶
func GetTfAlignOrigin ¶
func KeysOfMap ¶
func KeysOfMap[M ~map[K]V, K comparable, V any](m M) []K
func NearScore ¶
NearScore Formula: y=e ^ - abs (x-a) At the given maxAt, i.e. a, y takes its maximum value of 1, x moves towards both sides, y gradually approaches 0, and the slope decreases from large to small The default rate is 1, and when x is offset by 40, it decays by 70%; When rate>1, attenuation accelerates 公式:y=e^-abs(x-a) 在给定的maxAt即a处,y取最大值1,x向两侧移动,y逐渐趋近于0,斜率由大变小 rate默认1,x偏移40时,衰减70%;rate>1时,衰减加速
func NumSign ¶
func NumSign(obj interface{}) int
NumSign Obtain the direction of numbers; 1, -1 or 0 获取数字的方向;1,-1或0
func ParallelRun ¶
func RemoveFromArr ¶
func RemoveFromArr[T comparable](arr []T, it T, num int) []T
func ReverseArr ¶
func ReverseArr[T any](s []T)
func SetServerData ¶
func SetServerData(args *KeyValExpire) *errs.Error
func SharpeRatioAdv ¶
func SharpeRatioBy ¶
func SharpeRatioSmart ¶
func SnakeToCamel ¶
func SortinoRatioAdv ¶
func SortinoRatioBy ¶
func SortinoRatioSmart ¶
func SplitSolid ¶
SplitSolid String segmentation, ignore empty strings in the return result 字符串分割,忽略返回结果中的空字符串
func StdDevVolatility ¶
StdDevVolatility Calculate the standard deviation of K-line volatility Data: It should be a set of numbers with a slight fluctuation above and below the mean of 1 Rate: default 1. If you need to enlarge the difference, pass in a value between 1-1000 计算K线的波动性标准差
data: 应该是均值为1的上下轻微浮动的一组数 rate: 默认1,如需要放大差异,则传入1~1000之间的值
func TFToSecs ¶
TFToSecs Convert the time cycle to seconds Supporting units: s, m, h, d, M, Q, Y 将时间周期转为秒 支持单位:s, m, h, d, M, Q, Y
func UnionArr ¶
func UnionArr[T comparable](arrs ...[]T) []T
func UniqueItems ¶
func UniqueItems[T comparable](arr []T) ([]T, []T)
func ValsOfMap ¶
func ValsOfMap[M ~map[K]V, K comparable, V any](m M) []V
Types ¶
type BanConn ¶
type BanConn struct { Conn net.Conn // Original socket connection 原始的socket连接 Tags map[string]bool // Message subscription list 消息订阅列表 Remote string // Remote Name 远端名称 Listens map[string]ConnCB // Message processing function 消息处理函数 RefreshMS int64 // Connection ready timestamp 连接就绪的时间戳 Ready bool DoConnect func(conn *BanConn) // Reconnect function, no attempt to reconnect provided 重新连接函数,未提供不尝试重新连接 ReInitConn func() // Initialize callback function after successful reconnection 重新连接成功后初始化回调函数 // contains filtered or unexported fields }
func (*BanConn) RunForever ¶
RunForever Monitor the information sent by the connection and process it. According to the action of the message: Call the corresponding member function for processing; Directly input msd_data Or find the corresponding processing function from listeners. If there is an exact match, pass msd_data. Otherwise, pass action and msd_data Both the server-side and client-side will call this method 监听连接发送的信息并处理。 根据消息的action:
调用对应成员函数处理;直接传入msg_data 或从listens中找对应的处理函数,如果精确匹配,传入msg_data,否则传入action, msg_data
服务器端和客户端都会调用此方法
func (*BanConn) UnSubscribe ¶
type ClusterRes ¶
func KMeansVals ¶
func KMeansVals(vals []float64, num int) *ClusterRes
type KeyValExpire ¶
type PrgBar ¶
type ServerIO ¶
type ServerIO struct { Addr string Name string Conns []IBanConn Data map[string]interface{} // Cache data available for remote access 缓存的数据,可供远程端访问 DataExp map[string]int64 // Cache data expiration timestamp, 13 bits 缓存数据的过期时间戳,13位 InitConn func(*BanConn) }
func NewBanServer ¶
func (*ServerIO) RunForever ¶
func (*ServerIO) SetVal ¶
func (s *ServerIO) SetVal(args *KeyValExpire)