trade_analysis_data.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. package trade_analysis
  2. import (
  3. "eta/eta_index_lib/models"
  4. tradeAnalysisModel "eta/eta_index_lib/models/trade_analysis"
  5. "eta/eta_index_lib/utils"
  6. "fmt"
  7. "sort"
  8. "strings"
  9. "time"
  10. )
  11. // FormatCompanyTradeData2EdbData [公司-合约加总]转为指标数据
  12. func FormatCompanyTradeData2EdbData(companyTradeData *tradeAnalysisModel.ContractCompanyTradeData, tradeType int) (edbData []*models.EdbDataList, err error) {
  13. if companyTradeData == nil {
  14. err = fmt.Errorf("持仓数据异常")
  15. return
  16. }
  17. edbData = make([]*models.EdbDataList, 0)
  18. var minData, maxData float64
  19. for dk, dv := range companyTradeData.DataList {
  20. // 交易方向
  21. var val float64
  22. if tradeType == tradeAnalysisModel.WarehouseBuyChartType {
  23. if dv.BuyValType == tradeAnalysisModel.TradeDataTypeNull {
  24. continue
  25. }
  26. val = float64(dv.BuyVal)
  27. }
  28. if tradeType == tradeAnalysisModel.WarehouseSoldChartType {
  29. if dv.SoldValType == tradeAnalysisModel.TradeDataTypeNull {
  30. continue
  31. }
  32. val = float64(dv.SoldVal)
  33. }
  34. if tradeType == tradeAnalysisModel.WarehousePureBuyChartType {
  35. if dv.PureBuyValType == tradeAnalysisModel.TradeDataTypeNull {
  36. continue
  37. }
  38. val = float64(dv.PureBuyVal)
  39. }
  40. if dk == 0 {
  41. minData = val
  42. maxData = val
  43. }
  44. if val < minData {
  45. minData = val
  46. }
  47. if val > maxData {
  48. maxData = val
  49. }
  50. edbData = append(edbData, &models.EdbDataList{
  51. DataTime: dv.Date.Format(utils.FormatDate),
  52. DataTimestamp: dv.Date.UnixNano() / 1e6,
  53. Value: val,
  54. })
  55. }
  56. return
  57. }
  58. // GetOriginTradeData 获取原始持仓数据
  59. func GetOriginTradeData(exchange, classifyName string, contracts, companies []string, predictRatio float64) (companyTradeData []*tradeAnalysisModel.ContractCompanyTradeData, err error) {
  60. // 各原始数据表期货公司名称不一致
  61. companyMap := make(map[string]string)
  62. {
  63. ob := new(tradeAnalysisModel.TradeFuturesCompany)
  64. list, e := ob.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  65. if e != nil {
  66. err = fmt.Errorf("获取期货公司名称失败: %v", e)
  67. return
  68. }
  69. switch exchange {
  70. case "zhengzhou":
  71. for _, v := range list {
  72. companyMap[v.CompanyName] = v.ZhengzhouName
  73. }
  74. case "dalian":
  75. for _, v := range list {
  76. companyMap[v.CompanyName] = v.DalianName
  77. }
  78. case "shanghai":
  79. for _, v := range list {
  80. companyMap[v.CompanyName] = v.ShanghaiName
  81. }
  82. case "cffex":
  83. for _, v := range list {
  84. companyMap[v.CompanyName] = v.CffexName
  85. }
  86. case "ine":
  87. for _, v := range list {
  88. companyMap[v.CompanyName] = v.IneName
  89. }
  90. case "guangzhou":
  91. for _, v := range list {
  92. companyMap[v.CompanyName] = v.GuangzhouName
  93. }
  94. }
  95. }
  96. var queryCompanies []string
  97. for _, v := range companies {
  98. // TOP20用空名称去查询
  99. if v == tradeAnalysisModel.TradeFuturesCompanyTop20 {
  100. queryCompanies = append(queryCompanies, "")
  101. continue
  102. }
  103. companyName, ok := companyMap[v]
  104. if !ok {
  105. utils.FileLog.Info(fmt.Sprintf("交易所%s公司名称映射不存在: %s", exchange, v))
  106. continue
  107. }
  108. queryCompanies = append(queryCompanies, companyName)
  109. }
  110. // 郑商所/广期所查询方式不一样
  111. var tradeAnalysis TradeAnalysisInterface
  112. switch exchange {
  113. case tradeAnalysisModel.TradeExchangeZhengzhou:
  114. tradeAnalysis = &ZhengzhouTradeAnalysis{}
  115. case tradeAnalysisModel.TradeExchangeGuangzhou:
  116. tradeAnalysis = &GuangzhouTradeAnalysis{}
  117. default:
  118. tradeAnalysis = &BaseTradeAnalysis{}
  119. }
  120. // 获取多单/空单原始数据
  121. originList, e := tradeAnalysis.GetTradeDataByClassifyAndCompany(exchange, classifyName, contracts, queryCompanies)
  122. if e != nil {
  123. err = fmt.Errorf("获取多空单原始数据失败, %v", e)
  124. return
  125. }
  126. keyItems := make(map[string]*tradeAnalysisModel.ContractCompanyTradeData)
  127. keyDateData := make(map[string]*tradeAnalysisModel.ContractCompanyTradeDataList)
  128. keyDateDataExist := make(map[string]bool)
  129. for _, v := range originList {
  130. // TOP20对应数据库中的空名称
  131. companyName := v.CompanyName
  132. if companyName == "" {
  133. companyName = tradeAnalysisModel.TradeFuturesCompanyTop20
  134. }
  135. k := fmt.Sprintf("%s-%s", v.ClassifyType, companyName)
  136. if keyItems[k] == nil {
  137. keyItems[k] = new(tradeAnalysisModel.ContractCompanyTradeData)
  138. keyItems[k].CompanyName = companyName
  139. keyItems[k].ClassifyType = v.ClassifyType
  140. keyItems[k].DataList = make([]*tradeAnalysisModel.ContractCompanyTradeDataList, 0)
  141. }
  142. kd := fmt.Sprintf("%s-%s", k, v.DataTime.Format(utils.FormatDate))
  143. if keyDateData[kd] == nil {
  144. keyDateData[kd] = new(tradeAnalysisModel.ContractCompanyTradeDataList)
  145. keyDateData[kd].Date = v.DataTime
  146. }
  147. if v.ValType == 1 {
  148. keyDateData[kd].BuyVal = v.Val
  149. keyDateData[kd].BuyValType = tradeAnalysisModel.TradeDataTypeOrigin
  150. keyDateData[kd].BuyChange = v.ValChange
  151. keyDateData[kd].BuyChangeType = tradeAnalysisModel.TradeDataTypeOrigin
  152. }
  153. if v.ValType == 2 {
  154. keyDateData[kd].SoldVal = v.Val
  155. keyDateData[kd].SoldValType = tradeAnalysisModel.TradeDataTypeOrigin
  156. keyDateData[kd].SoldChange = v.ValChange
  157. keyDateData[kd].SoldChangeType = tradeAnalysisModel.TradeDataTypeOrigin
  158. }
  159. if !keyDateDataExist[kd] {
  160. keyItems[k].DataList = append(keyItems[k].DataList, keyDateData[kd])
  161. keyDateDataExist[kd] = true
  162. }
  163. }
  164. // 获取[合约]每日的末位多空单
  165. contractLastBuyDateVal := make(map[string]map[time.Time]int)
  166. contractLastSoldDateVal := make(map[string]map[time.Time]int)
  167. {
  168. lastOriginList, e := tradeAnalysis.GetLastTradeDataByClassify(exchange, classifyName, contracts)
  169. if e != nil {
  170. err = fmt.Errorf("获取末位多空单原始数据失败, %v", e)
  171. return
  172. }
  173. for _, v := range lastOriginList {
  174. if v.ValType == 1 {
  175. if contractLastBuyDateVal[v.ClassifyType] == nil {
  176. contractLastBuyDateVal[v.ClassifyType] = make(map[time.Time]int)
  177. }
  178. contractLastBuyDateVal[v.ClassifyType][v.DataTime] = v.Val
  179. continue
  180. }
  181. if contractLastSoldDateVal[v.ClassifyType] == nil {
  182. contractLastSoldDateVal[v.ClassifyType] = make(map[time.Time]int)
  183. }
  184. contractLastSoldDateVal[v.ClassifyType][v.DataTime] = v.Val
  185. }
  186. }
  187. // 填充[合约-公司]预估数据, 并根据[公司-多合约]分组, [公司]算作一个指标, 指标值为[多个合约]的计算加总
  188. companyContracts := make(map[string][]*tradeAnalysisModel.ContractCompanyTradeData)
  189. for _, v := range keyItems {
  190. td, fd, ed, e := PredictingTradeData(v.DataList, contractLastBuyDateVal[v.ClassifyType], contractLastSoldDateVal[v.ClassifyType], predictRatio)
  191. if e != nil {
  192. err = fmt.Errorf("数据补全失败, %v", e)
  193. return
  194. }
  195. v.DataList = td
  196. v.StartDate = fd
  197. v.EndDate = ed
  198. if companyContracts[v.CompanyName] == nil {
  199. companyContracts[v.CompanyName] = make([]*tradeAnalysisModel.ContractCompanyTradeData, 0)
  200. }
  201. companyContracts[v.CompanyName] = append(companyContracts[v.CompanyName], v)
  202. }
  203. // 以[公司]为组, 计算合约加总
  204. companyTradeData = make([]*tradeAnalysisModel.ContractCompanyTradeData, 0)
  205. for k, v := range companyContracts {
  206. companyData := new(tradeAnalysisModel.ContractCompanyTradeData)
  207. companyData.CompanyName = k
  208. companyData.DataList = make([]*tradeAnalysisModel.ContractCompanyTradeDataList, 0)
  209. contractArr := make([]string, 0)
  210. // 合约加总
  211. sumDateData := make(map[time.Time]*tradeAnalysisModel.ContractCompanyTradeDataList)
  212. for _, vv := range v {
  213. contractArr = append(contractArr, vv.ClassifyType)
  214. for _, dv := range vv.DataList {
  215. if sumDateData[dv.Date] == nil {
  216. sumDateData[dv.Date] = new(tradeAnalysisModel.ContractCompanyTradeDataList)
  217. sumDateData[dv.Date].Date = dv.Date
  218. }
  219. // 数据类型以第一个非零值为准, 只处理多空和净多, 变化就不管了
  220. if sumDateData[dv.Date].BuyValType == tradeAnalysisModel.TradeDataTypeNull && dv.BuyValType > tradeAnalysisModel.TradeDataTypeNull {
  221. sumDateData[dv.Date].BuyValType = dv.BuyValType
  222. }
  223. if sumDateData[dv.Date].BuyValType == tradeAnalysisModel.TradeDataTypeOrigin && dv.BuyValType == tradeAnalysisModel.TradeDataTypeCalculate {
  224. sumDateData[dv.Date].BuyValType = dv.BuyValType
  225. }
  226. if dv.BuyValType > tradeAnalysisModel.TradeDataTypeNull {
  227. sumDateData[dv.Date].BuyVal += dv.BuyVal
  228. }
  229. // 空单
  230. if sumDateData[dv.Date].SoldValType == tradeAnalysisModel.TradeDataTypeNull && dv.SoldValType > tradeAnalysisModel.TradeDataTypeNull {
  231. sumDateData[dv.Date].SoldValType = dv.SoldValType
  232. }
  233. if sumDateData[dv.Date].SoldValType == tradeAnalysisModel.TradeDataTypeOrigin && dv.SoldValType == tradeAnalysisModel.TradeDataTypeCalculate {
  234. sumDateData[dv.Date].SoldValType = dv.SoldValType
  235. }
  236. if dv.SoldValType > tradeAnalysisModel.TradeDataTypeNull {
  237. sumDateData[dv.Date].SoldVal += dv.SoldVal
  238. }
  239. // 净多单
  240. if sumDateData[dv.Date].PureBuyValType == tradeAnalysisModel.TradeDataTypeNull && dv.PureBuyValType > tradeAnalysisModel.TradeDataTypeNull {
  241. sumDateData[dv.Date].PureBuyValType = dv.PureBuyValType
  242. }
  243. if sumDateData[dv.Date].PureBuyValType == tradeAnalysisModel.TradeDataTypeOrigin && dv.PureBuyValType == tradeAnalysisModel.TradeDataTypeCalculate {
  244. sumDateData[dv.Date].PureBuyValType = dv.PureBuyValType
  245. }
  246. if dv.PureBuyValType > tradeAnalysisModel.TradeDataTypeNull {
  247. sumDateData[dv.Date].PureBuyVal += dv.PureBuyVal
  248. }
  249. }
  250. // 多个合约比对开始结束时间
  251. if companyData.StartDate.IsZero() {
  252. companyData.StartDate = vv.StartDate
  253. }
  254. if vv.StartDate.Before(companyData.StartDate) {
  255. companyData.StartDate = vv.StartDate
  256. }
  257. if companyData.EndDate.IsZero() {
  258. companyData.EndDate = vv.EndDate
  259. }
  260. if vv.EndDate.Before(companyData.EndDate) {
  261. companyData.EndDate = vv.EndDate
  262. }
  263. }
  264. for _, sv := range sumDateData {
  265. companyData.DataList = append(companyData.DataList, sv)
  266. }
  267. sort.Slice(companyData.DataList, func(i, j int) bool {
  268. return companyData.DataList[i].Date.Before(companyData.DataList[j].Date)
  269. })
  270. companyData.ClassifyType = strings.Join(contractArr, ",")
  271. companyTradeData = append(companyTradeData, companyData)
  272. }
  273. return
  274. }
  275. // PredictingTradeData 根据数据库中的多空数据填充预估数据
  276. func PredictingTradeData(originData []*tradeAnalysisModel.ContractCompanyTradeDataList, lastBuyDateVal, lastSoldDateVal map[time.Time]int, predictRatio float64) (newData []*tradeAnalysisModel.ContractCompanyTradeDataList, firstDate, endDate time.Time, err error) {
  277. if len(originData) == 0 {
  278. return
  279. }
  280. if predictRatio < 0 || predictRatio > 1 {
  281. err = fmt.Errorf("估计参数不在0-1之间")
  282. return
  283. }
  284. sort.Slice(originData, func(i, j int) bool {
  285. return originData[i].Date.Before(originData[j].Date)
  286. })
  287. dateVal := make(map[time.Time]*tradeAnalysisModel.ContractCompanyTradeDataList)
  288. for _, v := range originData {
  289. dateVal[v.Date] = v
  290. }
  291. // 生成开始日期-1d(可能会往前面推算一天)至结束日期间的交易日, 以交易日为时间序列遍历
  292. tradeDays := utils.GetTradingDays(originData[0].Date.AddDate(0, 0, -1), originData[len(originData)-1].Date)
  293. for k, v := range tradeDays {
  294. // T日多空均无的情况
  295. //bothLast := false
  296. if dateVal[v] == nil {
  297. // T-1和T+1[原始数据]均无值, 那么T日无数据
  298. hasPrev, hasNext := false, false
  299. if k-1 >= 0 {
  300. hasPrev = true
  301. }
  302. if k+1 <= len(tradeDays)-1 {
  303. hasNext = true
  304. }
  305. if !hasPrev && !hasNext {
  306. continue
  307. }
  308. // T+1有值, 优先从T+1推, 然后继续走下面计算净多单的逻辑
  309. if hasNext {
  310. nextDay := tradeDays[k+1]
  311. if dateVal[nextDay] != nil {
  312. // T+1有多/空及多空变化, 且是原始数据, 那么推出数据并在map中新加一日数据
  313. if dateVal[nextDay].BuyValType == tradeAnalysisModel.TradeDataTypeOrigin && dateVal[nextDay].BuyChangeType == tradeAnalysisModel.TradeDataTypeOrigin {
  314. if _, ok := dateVal[v]; !ok {
  315. dateVal[v] = new(tradeAnalysisModel.ContractCompanyTradeDataList)
  316. dateVal[v].Date = v
  317. }
  318. dateVal[v].BuyVal = dateVal[nextDay].BuyVal - dateVal[nextDay].BuyChange
  319. dateVal[v].BuyValType = tradeAnalysisModel.TradeDataTypeOrigin
  320. }
  321. if dateVal[nextDay].SoldValType == tradeAnalysisModel.TradeDataTypeOrigin && dateVal[nextDay].SoldChangeType == tradeAnalysisModel.TradeDataTypeOrigin {
  322. if _, ok := dateVal[v]; !ok {
  323. dateVal[v] = new(tradeAnalysisModel.ContractCompanyTradeDataList)
  324. dateVal[v].Date = v
  325. }
  326. dateVal[v].SoldVal = dateVal[nextDay].SoldVal - dateVal[nextDay].SoldChange
  327. dateVal[v].SoldValType = tradeAnalysisModel.TradeDataTypeOrigin
  328. }
  329. }
  330. }
  331. // T+1没推出来而T-1有值, 那么T多空均取末位, 计算净多单
  332. _, has := dateVal[v]
  333. if hasPrev && !has {
  334. sv, sok := lastSoldDateVal[v]
  335. bv, bok := lastBuyDateVal[v]
  336. if !sok && !bok {
  337. continue
  338. }
  339. dateVal[v] = new(tradeAnalysisModel.ContractCompanyTradeDataList)
  340. dateVal[v].Date = v
  341. if sok {
  342. dateVal[v].SoldVal = int(predictRatio*float64(sv) + 0.5)
  343. dateVal[v].SoldValType = tradeAnalysisModel.TradeDataTypeCalculate
  344. }
  345. if bok {
  346. dateVal[v].BuyVal = int(predictRatio*float64(bv) + 0.5)
  347. dateVal[v].BuyValType = tradeAnalysisModel.TradeDataTypeCalculate
  348. }
  349. if dateVal[v].BuyValType > tradeAnalysisModel.TradeDataTypeNull && dateVal[v].SoldValType > tradeAnalysisModel.TradeDataTypeNull {
  350. dateVal[v].PureBuyVal = dateVal[v].BuyVal - dateVal[v].SoldVal
  351. dateVal[v].PureBuyValType = tradeAnalysisModel.TradeDataTypeCalculate
  352. }
  353. continue
  354. }
  355. }
  356. // 多空均有的情况下计算净多单
  357. if dateVal[v].BuyValType == tradeAnalysisModel.TradeDataTypeOrigin && dateVal[v].SoldValType == tradeAnalysisModel.TradeDataTypeOrigin {
  358. dateVal[v].PureBuyVal = dateVal[v].BuyVal - dateVal[v].SoldVal
  359. dateVal[v].PureBuyValType = tradeAnalysisModel.TradeDataTypeOrigin // 原始值算出来的也作原始值
  360. }
  361. // 仅有多单, 空单取末位, 计算净多单
  362. if dateVal[v].BuyValType == tradeAnalysisModel.TradeDataTypeOrigin && dateVal[v].SoldValType == tradeAnalysisModel.TradeDataTypeNull {
  363. if sv, ok := lastSoldDateVal[v]; ok {
  364. dateVal[v].SoldVal = int(predictRatio*float64(sv) + 0.5) // 估计参数*末位值, 向上取整
  365. dateVal[v].SoldValType = tradeAnalysisModel.TradeDataTypeCalculate
  366. dateVal[v].PureBuyVal = dateVal[v].BuyVal - dateVal[v].SoldVal
  367. dateVal[v].PureBuyValType = tradeAnalysisModel.TradeDataTypeCalculate
  368. }
  369. }
  370. // 仅有空单, 多单取末位, 计算净多单
  371. if dateVal[v].SoldValType == tradeAnalysisModel.TradeDataTypeOrigin && dateVal[v].BuyValType == tradeAnalysisModel.TradeDataTypeNull {
  372. if sv, ok := lastBuyDateVal[v]; ok {
  373. dateVal[v].BuyVal = int(predictRatio*float64(sv) + 0.5)
  374. dateVal[v].BuyValType = tradeAnalysisModel.TradeDataTypeCalculate
  375. dateVal[v].PureBuyVal = dateVal[v].BuyVal - dateVal[v].SoldVal
  376. dateVal[v].PureBuyValType = tradeAnalysisModel.TradeDataTypeCalculate
  377. }
  378. }
  379. }
  380. // 二次遍历, 计算与T-1的变化值
  381. for k, v := range tradeDays {
  382. // 无T/T-1数据, 忽略
  383. if dateVal[v] == nil {
  384. continue
  385. }
  386. if k-1 < 0 {
  387. continue
  388. }
  389. beforeDay := tradeDays[k-1]
  390. if dateVal[beforeDay] == nil {
  391. continue
  392. }
  393. // 多单变化
  394. if dateVal[v].BuyChangeType == tradeAnalysisModel.TradeDataTypeNull {
  395. if dateVal[v].BuyValType > tradeAnalysisModel.TradeDataTypeNull && dateVal[beforeDay].BuyValType > tradeAnalysisModel.TradeDataTypeNull {
  396. dateVal[v].BuyChange = dateVal[v].BuyVal - dateVal[beforeDay].BuyVal
  397. // 如果当日多单或者前日多单是估计值, 那么多单变化也为估计值
  398. if dateVal[v].BuyValType == tradeAnalysisModel.TradeDataTypeCalculate || dateVal[beforeDay].BuyValType == tradeAnalysisModel.TradeDataTypeCalculate {
  399. dateVal[v].BuyChangeType = tradeAnalysisModel.TradeDataTypeCalculate
  400. }
  401. }
  402. }
  403. // 空单变化
  404. if dateVal[v].SoldChangeType == tradeAnalysisModel.TradeDataTypeNull {
  405. if dateVal[v].SoldValType > tradeAnalysisModel.TradeDataTypeNull && dateVal[beforeDay].SoldValType > tradeAnalysisModel.TradeDataTypeNull {
  406. dateVal[v].SoldChange = dateVal[v].SoldVal - dateVal[beforeDay].SoldVal
  407. // 如果当日空单或者前日空单是估计值, 那么空单变化也为估计值
  408. if dateVal[v].SoldValType == tradeAnalysisModel.TradeDataTypeCalculate || dateVal[beforeDay].SoldValType == tradeAnalysisModel.TradeDataTypeCalculate {
  409. dateVal[v].SoldChangeType = tradeAnalysisModel.TradeDataTypeCalculate
  410. }
  411. }
  412. }
  413. // 净多变化
  414. if dateVal[v].PureBuyChangeType == tradeAnalysisModel.TradeDataTypeNull {
  415. if dateVal[v].PureBuyValType > tradeAnalysisModel.TradeDataTypeNull && dateVal[beforeDay].PureBuyValType > tradeAnalysisModel.TradeDataTypeNull {
  416. dateVal[v].PureBuyChange = dateVal[v].PureBuyVal - dateVal[beforeDay].PureBuyVal
  417. dateVal[v].PureBuyChangeType = tradeAnalysisModel.TradeDataTypeOrigin
  418. // 如果当日净多单或者前日净多单是估计值, 那么净多单变化也为估计值
  419. if dateVal[v].PureBuyValType == tradeAnalysisModel.TradeDataTypeCalculate || dateVal[beforeDay].PureBuyValType == tradeAnalysisModel.TradeDataTypeCalculate {
  420. dateVal[v].PureBuyChangeType = tradeAnalysisModel.TradeDataTypeCalculate
  421. }
  422. }
  423. }
  424. }
  425. // 重新遍历map, 生成数据序列并排序
  426. newData = make([]*tradeAnalysisModel.ContractCompanyTradeDataList, 0)
  427. for _, v := range dateVal {
  428. if v.BuyValType == tradeAnalysisModel.TradeDataTypeNull && v.SoldValType == tradeAnalysisModel.TradeDataTypeNull {
  429. continue
  430. }
  431. newData = append(newData, v)
  432. }
  433. sort.Slice(newData, func(i, j int) bool {
  434. return newData[i].Date.Before(newData[j].Date)
  435. })
  436. if len(newData) > 0 {
  437. firstDate = newData[0].Date
  438. endDate = newData[len(newData)-1].Date
  439. }
  440. return
  441. }