fix
This commit is contained in:
63
cmd/top/main.go
Normal file
63
cmd/top/main.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.apinb.com/quant/gostock/internal/config"
|
||||
"git.apinb.com/quant/gostock/internal/impl"
|
||||
"git.apinb.com/quant/gostock/internal/logic/strategy"
|
||||
)
|
||||
|
||||
var (
|
||||
ServiceKey = "gostock"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.New(ServiceKey)
|
||||
impl.NewImpl()
|
||||
|
||||
fmt.Println("")
|
||||
ymd := lastYmd()
|
||||
strategy.TotalScore(ymd)
|
||||
//run(lastYmd())
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func lastYmd() int {
|
||||
var ymd int
|
||||
sql := "select ymd from strat_model sm group by ymd order by ymd desc limit 1"
|
||||
impl.DBService.Raw(sql).Scan(&ymd)
|
||||
return ymd
|
||||
}
|
||||
|
||||
func run(ymd int) {
|
||||
// tw := table.NewWriter()
|
||||
// tw.SetStyle(table.StyleLight)
|
||||
// tw.AppendHeader(table.Row{"ID", "Code", "Name", "OpenDate", "OpenPrice", "TodayPrice", "PNL/Per", "PNLRate(%)"})
|
||||
// var data []models.StratModel
|
||||
// impl.DBService.Where("status=?", 0).Find(&data)
|
||||
// var tPNL, tPNLR, cost, sell float64
|
||||
// for _, item := range data {
|
||||
// var stock models.StockBasic
|
||||
// impl.DBService.Where("ts_code=?", item.Code).First(&stock)
|
||||
|
||||
// var daily models.StockDaily
|
||||
// impl.DBService.Model(&models.StockDaily{}).Where("ts_code=?", item.Code).Order("id desc").Limit(1).First(&daily)
|
||||
|
||||
// high := utils.FloatRound(daily.High*0.995, 2)
|
||||
// pnl := utils.FloatRound(high-item.OpenPrice, 2)
|
||||
// pnlRate := utils.FloatRound(pnl/item.OpenPrice*100, 2)
|
||||
|
||||
// tPNL = tPNL + pnl
|
||||
// cost = cost + item.OpenPrice
|
||||
// sell = sell + high
|
||||
|
||||
// tw.AppendRow(table.Row{item.ID, item.Code, stock.Name, item.CreatedAt.Format("2006-01-02"), item.OpenPrice, high, pnl, pnlRate})
|
||||
// }
|
||||
|
||||
// tPNLR = utils.FloatRound(((sell-cost)/cost)*100, 2)
|
||||
|
||||
// tw.AppendFooter(table.Row{"", "", "", "TOTAL", utils.FloatRound(cost, 2), utils.FloatRound(sell, 2), utils.FloatRound(tPNL, 2), tPNLR})
|
||||
|
||||
// fmt.Println(tw.Render())
|
||||
}
|
||||
@@ -57,5 +57,6 @@ func Starter(ctx *gin.Context) {
|
||||
// AI分析:根据基本资料,过去200交易日的数据,200日的财务指标,3年财报给出得分
|
||||
strategy.BootAiStart("selector", ymd)
|
||||
log.Println("Strategy END.")
|
||||
strategy.TotalScore(ymd)
|
||||
mock.Run("selector", ymd)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ func (r *RuleFactory) RunRsi(code string) {
|
||||
return
|
||||
}
|
||||
|
||||
if args.RsiOversold == 0 {
|
||||
r.Model.ScoreRsi = -1
|
||||
r.Model.AddDesc("RSI RsiOversold=0,参数错误!")
|
||||
return
|
||||
}
|
||||
|
||||
if conf.BestByProfit != "rsi" {
|
||||
r.Model.ScoreRsi = -1
|
||||
r.Model.AddDesc("BestByProfit不是RSI")
|
||||
@@ -72,6 +78,12 @@ func (r *RuleFactory) RunRsi(code string) {
|
||||
prveRsiInt := int(prveRsi)
|
||||
lastRsiInt := int(lastRsi)
|
||||
|
||||
if lastRsiInt == 0 {
|
||||
r.Model.ScoreRsi = -1
|
||||
r.Model.AddDesc("RSI lastRsiInt=0,计算错误!")
|
||||
return
|
||||
}
|
||||
|
||||
// 跌破RSI下轨
|
||||
if lastRsiInt > args.RsiOversold {
|
||||
if CheckLowest(close, lastRsiInt, 14) {
|
||||
|
||||
23
internal/logic/strategy/total.go
Normal file
23
internal/logic/strategy/total.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package strategy
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/quant/gostock/internal/impl"
|
||||
"git.apinb.com/quant/gostock/internal/models"
|
||||
)
|
||||
|
||||
func TotalScore(ymd int) {
|
||||
log.Println("Total Score", ymd)
|
||||
impl.DBService.Model(&models.StratModel{}).Where("ymd=?", ymd).Update("total_score", 0)
|
||||
where := "where up_date_day>180 and st_score>0 and gt_amount>0 and gt_price>0 and gt_roe>0 and score_rsi>0 and ai_score>=5 and ymd=" + utils.Int2String(ymd)
|
||||
sql := "update strat_model set total_score=industry_score+val_roe+ai_score " + where
|
||||
|
||||
log.Println("SQL:", sql)
|
||||
err := impl.DBService.Exec(sql).Error
|
||||
if err != nil {
|
||||
log.Println("Failed to update total score:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
@@ -42,6 +42,9 @@ type StratModel struct {
|
||||
AiResisLevel float64
|
||||
AiAction string
|
||||
AiRisk string
|
||||
|
||||
TotalDesc string
|
||||
TotalScore float64
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -53,7 +56,12 @@ func (StratModel) TableName() string {
|
||||
return "strat_model"
|
||||
}
|
||||
|
||||
var (
|
||||
desc []string
|
||||
)
|
||||
|
||||
func NewStratModel(key, code string, ymd int) *StratModel {
|
||||
desc = []string{}
|
||||
obj := StratModel{
|
||||
StratKey: key,
|
||||
Ymd: ymd,
|
||||
@@ -63,22 +71,13 @@ func NewStratModel(key, code string, ymd int) *StratModel {
|
||||
}
|
||||
|
||||
func (s *StratModel) AddDesc(d string) {
|
||||
hash := utils.Md5(fmt.Sprintf("%s-%d-%s:%s", s.StratKey, s.Ymd, s.Code, d))
|
||||
|
||||
var cnt int64
|
||||
impl.DBService.Model(&StratDesc{}).Where("hash=?", hash).Count(&cnt)
|
||||
if cnt > 0 {
|
||||
return
|
||||
}
|
||||
s.Desc = append(s.Desc, StratDesc{
|
||||
Hash: hash,
|
||||
Desc: d,
|
||||
})
|
||||
desc = append(desc, d)
|
||||
}
|
||||
|
||||
func (s *StratModel) Save() error {
|
||||
var cnt int64
|
||||
impl.DBService.Model(&StratModel{}).Where("strat_key=? and ymd=? and code=?", s.StratKey, s.Ymd, s.Code).Count(&cnt)
|
||||
s.TotalDesc = strings.Join(desc, "||")
|
||||
|
||||
if cnt == 0 {
|
||||
// create record.
|
||||
|
||||
Reference in New Issue
Block a user