2022-06-20 18:17:29 +00:00
|
|
|
package moneymoney
|
|
|
|
|
2022-07-03 00:38:06 +00:00
|
|
|
import (
|
2022-07-04 17:47:54 +00:00
|
|
|
"encoding/gob"
|
|
|
|
"os"
|
2022-07-03 00:38:06 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/474420502/structure/tree/treelist"
|
2022-07-04 17:47:54 +00:00
|
|
|
"github.com/klauspost/compress/zstd"
|
2022-07-03 00:38:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMoney(t *testing.T) {
|
2022-07-09 21:19:48 +00:00
|
|
|
HistoryRun()
|
2022-07-03 00:38:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
// 统计历史关系参数.
|
2022-07-03 00:38:06 +00:00
|
|
|
func TestCase3(t *testing.T) {
|
2022-07-09 21:19:48 +00:00
|
|
|
cday := GetDate("2017-04-15")
|
2022-07-03 16:21:35 +00:00
|
|
|
citer := DateStocks.Iterator()
|
|
|
|
citer.SeekToFirst()
|
|
|
|
citer.SeekGE(cday.Unix())
|
|
|
|
|
|
|
|
for citer.Valid() {
|
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
stocks := citer.Value()
|
|
|
|
todayIter := stocks.Iterator() // 获取当天 所有股票的迭代器
|
2022-07-03 16:21:35 +00:00
|
|
|
|
|
|
|
cmpiter := citer.Clone()
|
2022-07-03 00:38:06 +00:00
|
|
|
|
2022-07-03 16:21:35 +00:00
|
|
|
var i = 0
|
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
// 向后移动的天数
|
2022-07-03 16:21:35 +00:00
|
|
|
for cmpiter.Valid() {
|
|
|
|
|
|
|
|
todayIter.SeekToFirst()
|
2022-07-09 21:19:48 +00:00
|
|
|
cmpday := cmpiter.Value()
|
2022-07-03 16:21:35 +00:00
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
stocks.Traverse(func(s *treelist.Slice[int64, *Stock]) bool {
|
2022-07-03 16:21:35 +00:00
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
todaystock := s.Value
|
|
|
|
if todaystock.Extend == nil {
|
|
|
|
todaystock.Extend = &StockExtend{
|
|
|
|
MaxPriceDays: 0,
|
|
|
|
MinPriceDays: 100000000000,
|
|
|
|
}
|
|
|
|
todaystock.Extend.UpsDownsRatioDays = append(todaystock.Extend.UpsDownsRatioDays, &UpsDownsDays{})
|
|
|
|
}
|
2022-07-03 16:21:35 +00:00
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
// 根据股票代码 获取对比的股票
|
|
|
|
c, ok := cmpday.Get(todaystock.Code)
|
2022-07-03 16:21:35 +00:00
|
|
|
if ok {
|
2022-07-09 21:19:48 +00:00
|
|
|
|
|
|
|
// 对比的历史前移时间股票
|
|
|
|
var ClosingPrice float64 = 0
|
|
|
|
|
|
|
|
if c.ClosingPrice == 0 {
|
|
|
|
ClosingPrice = c.PreviousClosingPrice
|
|
|
|
} else {
|
|
|
|
ClosingPrice = c.ClosingPrice
|
2022-07-04 17:47:54 +00:00
|
|
|
}
|
2022-07-09 21:19:48 +00:00
|
|
|
|
|
|
|
if ClosingPrice != 0 {
|
|
|
|
if ClosingPrice > todaystock.Extend.MaxPriceDays {
|
|
|
|
todaystock.Extend.MaxPriceDays = ClosingPrice
|
|
|
|
}
|
|
|
|
|
|
|
|
if ClosingPrice < todaystock.Extend.MinPriceDays {
|
|
|
|
todaystock.Extend.MinPriceDays = ClosingPrice
|
2022-07-04 17:47:54 +00:00
|
|
|
}
|
2022-07-09 21:19:48 +00:00
|
|
|
|
|
|
|
// 满足相邻天数的处理
|
|
|
|
|
|
|
|
// TODO: 其他的统计处理
|
2022-07-04 17:47:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
last := todaystock.Extend.UpsDownsRatioDays[len(todaystock.Extend.UpsDownsRatioDays)-1]
|
|
|
|
last.DownsCount++
|
|
|
|
last.UpsCount++
|
|
|
|
if _, ok := CountedDays[i]; ok {
|
|
|
|
last.Ratio = ((ClosingPrice - todaystock.ClosingPrice) / ClosingPrice)
|
|
|
|
todaystock.Extend.UpsDownsRatioDays = append(todaystock.Extend.UpsDownsRatioDays, &UpsDownsDays{
|
|
|
|
UpsCount: last.UpsCount,
|
|
|
|
DownsCount: last.DownsCount,
|
|
|
|
})
|
|
|
|
}
|
2022-07-04 17:47:54 +00:00
|
|
|
|
2022-07-03 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
2022-07-09 21:19:48 +00:00
|
|
|
return true
|
|
|
|
})
|
2022-07-03 16:21:35 +00:00
|
|
|
|
2022-07-04 17:47:54 +00:00
|
|
|
if i >= 1<<7 {
|
|
|
|
break
|
2022-07-03 16:21:35 +00:00
|
|
|
}
|
2022-07-04 17:47:54 +00:00
|
|
|
|
|
|
|
cmpiter.Prev()
|
|
|
|
i++
|
2022-07-03 16:21:35 +00:00
|
|
|
}
|
2022-07-09 21:19:48 +00:00
|
|
|
|
|
|
|
todayIter.SeekToFirst()
|
|
|
|
for todayIter.Valid() {
|
|
|
|
s := todayIter.Value()
|
|
|
|
if s.Extend != nil {
|
|
|
|
// if len(s.Extend.UpsDownsRatioDays) <= 1 {
|
|
|
|
// log.Println(s.Name, s.Date.Local().String(), s.Code)
|
|
|
|
// }
|
|
|
|
s.Extend.UpsDownsRatioDays = s.Extend.UpsDownsRatioDays[0 : len(s.Extend.UpsDownsRatioDays)-1]
|
|
|
|
}
|
|
|
|
todayIter.Next()
|
|
|
|
}
|
|
|
|
|
2022-07-03 16:21:35 +00:00
|
|
|
citer.Next()
|
|
|
|
}
|
2022-07-04 17:47:54 +00:00
|
|
|
|
|
|
|
var stocks []*Stock
|
2022-07-09 21:19:48 +00:00
|
|
|
|
|
|
|
DateStocks.Traverse(func(s *treelist.Slice[int64, *treelist.Tree[int64, *Stock]]) bool {
|
|
|
|
s.Value.Traverse(func(s *treelist.Slice[int64, *Stock]) bool {
|
|
|
|
stocks = append(stocks, s.Value)
|
2022-07-04 17:47:54 +00:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
if stocks != nil {
|
|
|
|
f, err := os.OpenFile("./stocks1.gob", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
enc, err := zstd.NewWriter(f)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer enc.Close()
|
|
|
|
|
|
|
|
err = gob.NewEncoder(enc).Encode(stocks)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-03 00:38:06 +00:00
|
|
|
}
|
2022-06-20 18:17:29 +00:00
|
|
|
|
2022-06-23 09:06:00 +00:00
|
|
|
func TestCase2(t *testing.T) {
|
2022-07-03 00:38:06 +00:00
|
|
|
GetFromAPI() // 获取基础数据
|
2022-06-23 09:06:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 18:17:29 +00:00
|
|
|
func TestCase1(t *testing.T) {
|
|
|
|
main()
|
|
|
|
}
|