Skip to content

Commit

Permalink
暴露策略中的Point
Browse files Browse the repository at this point in the history
  • Loading branch information
lion committed Jan 22, 2020
1 parent 90b3600 commit 176e7af
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions commonstock/CCI.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ cci =(典型价格 - tp的20周期平均值)/(.015 x平均偏差)
type CCI struct {
Period int //默认计算几天的
factor float64 //计算系数
points []cciPoint
points []CCIPoint
typicalPrice []float64
avedevPrice []float64
maPrice []float64
list []*commonmodels.Kline
}

type cciPoint struct {
type CCIPoint struct {
point
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (e *CCI) Calculation() *CCI {
//计算 CCI
// cci =(典型价格 - tp的20周期平均值)/(.015 x平均偏差)
for i := 0; i < len(e.maPrice); i++ {
var p cciPoint
var p CCIPoint
p.Time = e.list[i].KlineTime
if i < e.Period-1 {
p.Value = 0
Expand All @@ -111,7 +111,7 @@ func (e *CCI) Calculation() *CCI {
}

// GetPoints return Point
func (e *CCI) GetPoints() []cciPoint {
func (e *CCI) GetPoints() []CCIPoint {
return e.points
}

Expand Down
8 changes: 4 additions & 4 deletions commonstock/EMA.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
// EMA struct
type EMA struct {
Period int //默认计算几天的EMA
points []emaPoint
points []EMAPoint
kline []*commonmodels.Kline
}

type emaPoint struct {
type EMAPoint struct {
point
}

Expand All @@ -32,14 +32,14 @@ func (e *EMA) Calculation() *EMA {
}

// GetPoints return Point
func (e *EMA) GetPoints() []emaPoint {
func (e *EMA) GetPoints() []EMAPoint {
return e.points
}

// Add adds a new Value to Ema
// 使用方法,先添加最早日期的数据,最后一条应该是当前日期的数据,结果与 AICoin 对比完全一致
func (e *EMA) Add(timestamp time.Time, value float64) {
p := emaPoint{}
p := EMAPoint{}
p.Time = timestamp

//平滑指数,一般取作2/(N+1)
Expand Down
8 changes: 4 additions & 4 deletions commonstock/KDJ.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
// KDJ is the main object
type KDJ struct {
Period int //默认计算几天的
points []kdjPoint
points []KDJPoint
kline []*commonmodels.Kline
}

type kdjPoint struct {
type KDJPoint struct {
Time time.Time
RSV float64
K float64
Expand All @@ -33,7 +33,7 @@ func (e *KDJ) Calculation() *KDJ {
rsv, k, d := e.calculationKD(e.kline)
arrayLen := len(rsv)
for i := 0; i < arrayLen; i++ {
e.points = append(e.points, kdjPoint{
e.points = append(e.points, KDJPoint{
RSV: rsv[i],
K: k[i],
D: d[i],
Expand All @@ -48,7 +48,7 @@ func (e *KDJ) Calculation() *KDJ {
}

// GetPoints return Point
func (e *KDJ) GetPoints() []kdjPoint {
func (e *KDJ) GetPoints() []KDJPoint {
return e.points
}

Expand Down
8 changes: 4 additions & 4 deletions commonstock/MACD.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type MACD struct {
PeriodShort int //默认12
PeriodSignal int //信号长度默认9
PeriodLong int //默认26
points []macdPoint
points []MACDPoint
kline []*commonmodels.Kline
}

type macdPoint struct {
type MACDPoint struct {
Time time.Time
DIF float64
DEA float64
Expand All @@ -52,7 +52,7 @@ func (e *MACD) Calculation() *MACD {
//计算DIF
for i := 0; i < len(e.kline); i++ {
dif := emaShort[i].Value - emaLong[i].Value
e.points = append(e.points, macdPoint{DIF: dif, Time: emaShort[i].Time})
e.points = append(e.points, MACDPoint{DIF: dif, Time: emaShort[i].Time})
}

//临时变量,用于计算DEA
Expand All @@ -71,6 +71,6 @@ func (e *MACD) Calculation() *MACD {
}

// GetPoints return Point
func (e *MACD) GetPoints() []macdPoint {
func (e *MACD) GetPoints() []MACDPoint {
return e.points
}
8 changes: 4 additions & 4 deletions commonstock/OBV.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (

// OBV struct
type OBV struct {
points []obvPoint
points []OBVPoint
kline []*commonmodels.Kline
}

type obvPoint struct {
type OBVPoint struct {
point
}

Expand Down Expand Up @@ -46,7 +46,7 @@ func (e *OBV) Calculation() *OBV {
} else if item.Close == e.kline[i-1].Close {
value = e.points[i-1].Value
}
var p obvPoint
var p OBVPoint
p.Value = value
p.Time = item.KlineTime
e.points = append(e.points, p)
Expand All @@ -55,6 +55,6 @@ func (e *OBV) Calculation() *OBV {
}

// GetPoints Func
func (e *OBV) GetPoints() []obvPoint {
func (e *OBV) GetPoints() []OBVPoint {
return e.points
}
8 changes: 4 additions & 4 deletions commonstock/RSI.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
// RSI is the main object
type RSI struct {
Period int //默认计算几天的
points []rsiPoint
points []RSIPoint
kline []*commonmodels.Kline
}

type rsiPoint struct {
type RSIPoint struct {
point
}

Expand All @@ -32,7 +32,7 @@ func (e *RSI) Calculation() *RSI {

rsiArrayLen := len(rsiArray)
for i := 0; i <= (rsiArrayLen - 1); i++ {
var p rsiPoint
var p RSIPoint
p.Time = e.kline[i].KlineTime
p.Value = rsiArray[i]
e.points = append(e.points, p)
Expand All @@ -41,7 +41,7 @@ func (e *RSI) Calculation() *RSI {
}

// GetPoints return Point
func (e *RSI) GetPoints() []rsiPoint {
func (e *RSI) GetPoints() []RSIPoint {
return e.points
}

Expand Down
8 changes: 4 additions & 4 deletions commonstock/SMA.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
// SMA struct
type SMA struct {
Period int //默认计算几天的MA,KDJ一般是9,OBV是10、20、30
points []smaPoint
points []SMAPoint
kline []*commonmodels.Kline
}

type smaPoint struct {
type SMAPoint struct {
point
}

Expand All @@ -24,7 +24,7 @@ func NewSMA(list []*commonmodels.Kline, period int) *SMA {
// Calculation Func
func (e *SMA) Calculation() *SMA {
for i := 0; i < len(e.kline); i++ {
var smaPointStruct smaPoint
var smaPointStruct SMAPoint
if i > e.Period-1 {
var sum float64
for j := i; j >= (i - (e.Period - 1)); j-- {
Expand All @@ -45,6 +45,6 @@ func (e *SMA) Calculation() *SMA {
}

// GetPoints Func
func (e *SMA) GetPoints() []smaPoint {
func (e *SMA) GetPoints() []SMAPoint {
return e.points
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ require (
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
github.com/stretchr/testify v1.2.2 // indirect
)

go 1.13

0 comments on commit 176e7af

Please sign in to comment.