deving
This commit is contained in:
@@ -3,13 +3,11 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.apinb.com/quant/gostock/internal/config"
|
"git.apinb.com/quant/gostock/internal/config"
|
||||||
"git.apinb.com/quant/gostock/internal/impl"
|
"git.apinb.com/quant/gostock/internal/impl"
|
||||||
"git.apinb.com/quant/gostock/internal/logic/strategy"
|
"git.apinb.com/quant/gostock/internal/logic/strategy"
|
||||||
"git.apinb.com/quant/gostock/internal/logic/strategy/rule"
|
"git.apinb.com/quant/gostock/internal/logic/types"
|
||||||
"git.apinb.com/quant/gostock/internal/models"
|
|
||||||
"github.com/gocarina/gocsv"
|
"github.com/gocarina/gocsv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,15 +15,6 @@ var (
|
|||||||
ServiceKey = "gostock"
|
ServiceKey = "gostock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResultData struct { // Our example struct, you can use "-" to ignore a field
|
|
||||||
Code string `csv:"code"`
|
|
||||||
Name string `csv:"name"`
|
|
||||||
ROE float64 `csv:"roe"`
|
|
||||||
RSI float64 `csv:"rsi"`
|
|
||||||
Desc string `csv:"desc"`
|
|
||||||
Pass string `csv:"pass"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Hello Cli!")
|
log.Println("Hello Cli!")
|
||||||
config.New(ServiceKey)
|
config.New(ServiceKey)
|
||||||
@@ -39,11 +28,11 @@ func main2() {
|
|||||||
config.New(ServiceKey)
|
config.New(ServiceKey)
|
||||||
impl.NewImpl()
|
impl.NewImpl()
|
||||||
|
|
||||||
data_ok := []*ResultData{}
|
data_ok := []*types.ResultData{}
|
||||||
data_not := []*ResultData{}
|
data_not := []*types.ResultData{}
|
||||||
for _, code := range strategy.GetStocks() {
|
for _, code := range strategy.GetStocks() {
|
||||||
basic := strategy.GetBasic(code)
|
basic := strategy.GetBasic(code)
|
||||||
if ok, data := RuleFilter(basic); ok {
|
if ok, data := strategy.MustFilter(basic); ok {
|
||||||
data_ok = append(data_ok, data)
|
data_ok = append(data_ok, data)
|
||||||
} else {
|
} else {
|
||||||
data_not = append(data_not, data)
|
data_not = append(data_not, data)
|
||||||
@@ -56,7 +45,7 @@ func main2() {
|
|||||||
log.Println("Done!")
|
log.Println("Done!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteResults(data []*ResultData, tag string) {
|
func WriteResults(data []*types.ResultData, tag string) {
|
||||||
rf, err := os.OpenFile("./result/stocks_"+tag+".csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
|
rf, err := os.OpenFile("./result/stocks_"+tag+".csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -69,69 +58,3 @@ func WriteResults(data []*ResultData, tag string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RuleFilter(basic *models.StockBasic) (bool, *ResultData) {
|
|
||||||
var descripts []string
|
|
||||||
data := &ResultData{
|
|
||||||
Code: basic.TsCode,
|
|
||||||
Name: basic.Name,
|
|
||||||
ROE: 0,
|
|
||||||
RSI: 0,
|
|
||||||
Desc: "",
|
|
||||||
Pass: "NOT",
|
|
||||||
}
|
|
||||||
if re := rule.NewUpDate().Run(basic.ListDate); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewST().Run(basic.Name); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewIdustry().Run(basic.Industry); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewPrice().Run(basic.TsCode); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewAmount().Run(basic.TsCode); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewRoe().Run(basic.TsCode); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
data.ROE = re.Roe
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
if re := rule.NewRsi(strategy.GetArgs(basic.TsCode)).Run(basic.TsCode); re.Score <= 0 {
|
|
||||||
data.Desc = re.Desc
|
|
||||||
return false, data
|
|
||||||
} else {
|
|
||||||
data.RSI = re.Rsi
|
|
||||||
descripts = append(descripts, re.Desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Desc = strings.Join(descripts, "#")
|
|
||||||
data.Pass = "OK"
|
|
||||||
return true, data
|
|
||||||
}
|
|
||||||
|
|||||||
87
internal/logic/strategy/filter.go
Normal file
87
internal/logic/strategy/filter.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package strategy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.apinb.com/quant/gostock/internal/logic/strategy/rule"
|
||||||
|
"git.apinb.com/quant/gostock/internal/logic/types"
|
||||||
|
"git.apinb.com/quant/gostock/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MustFilter(basic *models.StockBasic) (bool, *types.ResultData) {
|
||||||
|
var descripts []string
|
||||||
|
data := &types.ResultData{
|
||||||
|
Code: basic.TsCode,
|
||||||
|
Name: basic.Name,
|
||||||
|
ROE: 0,
|
||||||
|
RSI: 0,
|
||||||
|
Desc: "",
|
||||||
|
Pass: "NOT",
|
||||||
|
}
|
||||||
|
if re := rule.NewUpDate().Run(basic.ListDate); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewST().Run(basic.Name); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewIdustry().Run(basic.Industry); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewPrice().Run(basic.TsCode); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewAmount().Run(basic.TsCode); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewRoe().Run(basic.TsCode); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
data.ROE = re.Roe
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if re := rule.NewRsi(GetArgs(basic.TsCode)).Run(basic.TsCode); re.Score <= 0 {
|
||||||
|
data.Desc = re.Desc
|
||||||
|
return false, data
|
||||||
|
} else {
|
||||||
|
data.RSI = re.Rsi
|
||||||
|
descripts = append(descripts, re.Desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Desc = strings.Join(descripts, "#")
|
||||||
|
data.Pass = "OK"
|
||||||
|
return true, data
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClacFilter(basic *models.StockBasic) (bool, *types.ResultData) {
|
||||||
|
var descripts []string
|
||||||
|
data := &types.ResultData{
|
||||||
|
Code: basic.TsCode,
|
||||||
|
Name: basic.Name,
|
||||||
|
ROE: 0,
|
||||||
|
RSI: 0,
|
||||||
|
Desc: "",
|
||||||
|
Pass: "NOT",
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,3 +8,12 @@ type RuleResult struct {
|
|||||||
Rsi float64
|
Rsi float64
|
||||||
Desc string
|
Desc string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResultData struct { // Our example struct, you can use "-" to ignore a field
|
||||||
|
Code string `csv:"code"`
|
||||||
|
Name string `csv:"name"`
|
||||||
|
ROE float64 `csv:"roe"`
|
||||||
|
RSI float64 `csv:"rsi"`
|
||||||
|
Desc string `csv:"desc"`
|
||||||
|
Pass string `csv:"pass"`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user