Beispiel #1
0
//	更新区间极值指数
func UpdateAll() error {

	log.Println("开始更新区间极值指标")

	//	数据保存目录
	dataDir, err := config.GetDataDir()
	if err != nil {
		return err
	}

	//	获取所有股票
	stocks, err := stock.GetAll()
	if err != nil {
		return err
	}

	//log.Printf("共有股票%d只", len(stocks))

	for _, stock := range stocks {
		//	更新每只股票的指标
		err = updateStock(stock.Code, dataDir)
		if err != nil {
			log.Fatal(err)
		}
	}

	log.Println("区间极值指标更新完毕")

	return err
}
Beispiel #2
0
func Default() *TurtleTradingSystem {
	stocks, err := stock.GetAll()
	if err != nil {
		log.Fatal("获取股票列表时发生错误:", err)
		return nil
	}

	codes := make([]string, 0)
	for _, s := range stocks {
		codes = append(codes, s.Code)
	}

	system := &TurtleTradingSystem{
		Codes:       codes,
		StartAmount: 100000,
		Commission:  7,
		StartDate:   "20060101",
		EndDate:     "20141231",
		Start: TurtleTradingSystemParameter{
			Holding: 2,
			N:       2,
			Enter:   2,
			Exit:    2,
			Stop:    2},
		End: TurtleTradingSystemParameter{
			Holding: 20,
			N:       50,
			Enter:   50,
			Exit:    50,
			Stop:    50},
		Current: TurtleTradingSystemParameter{
			Holding: 2,
			N:       2,
			Enter:   2,
			Exit:    2,
			Stop:    2},
		CurrentProfit:        0,
		CurrentProfitPercent: 0,
		Best: TurtleTradingSystemParameter{
			Holding: 2,
			N:       2,
			Enter:   2,
			Exit:    2,
			Stop:    2},
		BestProfit:        0,
		BestProfitPercent: 0,
		CalculatedSeconds: 0,
		RemainTips:        "计算尚未开始",
	}

	system.CalculatingAmount = int64(len(system.Codes) *
		(system.End.Holding - system.Start.Holding + 1) *
		(system.End.N - system.Start.N + 1) *
		(system.End.Enter - system.Start.Enter + 1) *
		(system.End.Exit - system.Start.Exit + 1) *
		(system.End.Stop - system.Start.Stop + 1))

	return system
}
Beispiel #3
0
//	更新股票历史
func UpdateAll() error {

	log.Print("开始更新股票历史")

	//	数据保存目录
	dataDir, err := config.GetDataDir()
	if err != nil {
		return err
	}

	//	获取所有的股票
	stocks, err := stock.GetAll()
	if err != nil {
		return err
	}

	chanSend := make(chan int, updateGoroutinesCount)
	chanReceive := make(chan int)

	//	并发获取股票历史
	go func() {
		for _, stock := range stocks {
			go func(code string) {
				//	更新每只股票的历史
				err = updateStock(code, dataDir)
				if err != nil {
					log.Fatal(err)
				}
				<-chanSend
				chanReceive <- 1
			}(stock.Code)

			chanSend <- 1
		}
	}()

	//	阻塞,直到所有股票更新完历史
	for _, _ = range stocks {
		<-chanReceive
	}

	log.Print("股票历史更新成功")

	return err
}