func main() {
	checks()
	initialize()
	configure()
	populate()
	list = fat.Agglomerate(list, delta)
	puts()
}
Beispiel #2
0
func run_with(base string, length int, base_history *map[int]float64) {
	notUsd := true
	if *base_history == nil {
		notUsd = false
	}
	base_price := 1.0
	if notUsd {
		base_price = 0.0
	}
	pivots := make([]float64, 0)
	mmas := ma.New(1827)

	var price, m2, wk float64
	var pv bool
	var nmbr int

	sma := make(map[int]float64)
	lsma := make(map[int]float64)
	mma := make(map[int]float64)
	lmma := make(map[int]float64)

	for _, day := range keys {
		if notUsd {
			price = (*base_history)[day]
			if price > 0.0 {
				base_price = price
			}
		}
		if base_price == 0.0 {
			continue
		}
		price = stock_history[day] / base_price
		if price <= 0.0 {
			panic("WUT!???")
		}

		mmas.Add(price)
		wk, m2, pv = mmas.Rapideco()
		m2 /= wk // relative momentum
		if pv {
			pivots = append(pivots, wk)
		}
		for i := month; i <= quint; i++ {
			nmbr = number[i]
			sma[nmbr] = mmas.SMA(nmbr)
			lsma[nmbr] = mmas.LSMA(nmbr)
			mma[nmbr] = mmas.MMA(nmbr)
			lmma[nmbr] = mmas.LMMA(nmbr)
		}
	}
	sort.Float64s(pivots)
	pivots = fat.Agglomerate(pivots, delta)
	fmt.Printf("### %s / %s ###\n", stock, base)
	fmt.Println("# Moving Averages:")
	for i := month; i <= quint; i++ {
		nmbr = number[i]
		fmt.Printf("# %d Days:\n", nmbr)
		fmt.Printf("$%.2f\t\t%v\tSMA(%d)\n", sma[nmbr]*base_price, sma[nmbr], nmbr)
		fmt.Printf("$%.2f\t\t%v\tLSMA(%d)\n", lsma[nmbr]*base_price, lsma[nmbr], nmbr)
		fmt.Printf("$%.2f\t\t%v\tMMA(%d)\n", mma[nmbr]*base_price, mma[nmbr], nmbr)
		fmt.Printf("$%.2f\t\t%v\tLMMA(%d)\n", lmma[nmbr]*base_price, lmma[nmbr], nmbr)
	}
	fmt.Println("# Levels:")
	rounded0 := ""
	for _, pivot := range pivots {
		rounded := fmt.Sprintf("%.2f", pivot*base_price)
		if rounded != rounded0 {
			rounded0 = rounded
			fmt.Printf("$%s\t\t%v\n", rounded, pivot)
		}
	}
}