Exemplo n.º 1
0
func socketMain(DoneLinks []LinksType) (<-chan string, int, [PORTS_NUMBER]Connect) {
	results := make(chan string)
	checkServ := make(chan *Connect)

	q := fifo_queue.NewQueue()

	for _, Link := range DoneLinks {
		q.PushBack(Link.Link)
	}
	len_q := q.Len()

	connects, err := CreateConnects()

	if err != nil {
		panic(err)
	}

	var success bool

	go CheckServ(checkServ, results, q, len_q)

	//Test closed connections. First 4 success -- true, last one -- false
	for i := 0; i < len_q; i++ {
		item := q.PopFront().(string)
		success, err = SendData(item, &connects, results, checkServ)
		if success == false {
			q.PushBack(item)
		}
	}

	if err != nil {
		fmt.Println(err)
	}

	return results, len_q, connects
}
Exemplo n.º 2
0
func TestEff(t *testing.T) {
	err := os.MkdirAll("/tmp/portopt_test", 0700)
	if err != nil {
		t.Fatal(err)
	}

	path := "/tmp/portopt_test/eff.db"
	db := CreateDb(path)

	dateRange := NewDateRange(time.Date(1980, time.Month(1), 1, 0, 0, 0, 0, time.UTC),
		time.Now(),
		time.Duration(time.Hour*24*90))
	/*	portfolio := NewPortfolio(db, dateRange, map[string]float64{
				"VCADX": 1.0,  // CA interm bond
		 		"VTMGX": 1.0, // tax-managed intl
				"VPCCX": 1.0, // Primecap core
				"VVIAX": 1.0, // value index adm
				"VMVIX": 1.0, // mid-cap value index inv
				"VMVAX": 1.0, // mid-cap value index adm
				"VIMSX": 1.0, // mid-cap index inv
				"VIMAX": 1.0, // mid-cap index adm
				"VTMSX": 1.0, // T-M smallcap
				"VGHAX": 1.0, // Healthcare adm
				"VGHCX": 1.0, // Healthcare inv
				"VSS": 1.0,  // Ex-us smallcap ETF
				"DLS": 1.0,  // Wisdomtree intl smallcap dividend
				"VWO": 1.0,  // Emerging market ETF
				"VSIAX": 1.0, // Small-cap value index adm
				"VISVX": 1.0, // small-cap value index inv
			})*/
	/*	portfolio := NewPortfolio(db, dateRange, map[string]float64{
		"^GSPC": 1.0,  // S&P 500 index
		"VBMFX" : 1.0,  // Vanguard total bond market index
		"VGTSX" : 1.0,  // Vanguard total intl index
	})*/

	portfolio := NewPortfolio(db, dateRange, map[string]float64{
		"^GSPC": 1.0, // S&P 500 index
		"VFSTX": 1.0, // Vanguard short-term investment grade
		"VGTSX": 1.0, // Vanguard total intl index
	})

	frontier := newFrontier()
	fifo := fifo_queue.NewQueue()
	fifo.PushBack(portfolio)

	for fifo.Len() > 0 {
		p := fifo.PopFront().(*Portfolio)
		stats := p.Stats()
		maxTries := 20
		if stats.perPeriodReturn >= frontier.MaxX() {
			// Try many times to find a better return
			maxTries = 100
			// fmt.Print(fifo.Len(), " New: Mean: ", mean, " Stddev: ", stddev, "\n")
		} else {
			// fmt.Print(fifo.Len(), " Ins: Mean: ", mean, " Stddev: ", stddev, "\n")
		}

		for i := 0; i < maxTries; i++ {
			newP := p.RandomMutate()
			stats := newP.Stats()
			maxX := frontier.MaxX()
			inserted := frontier.Insert(stats.perPeriodReturn, stats.stddev, newP)
			if inserted {
				fifo.PushBack(newP)
				if stats.perPeriodReturn > maxX {
					// Found a portfolio with the
					// best return so far. We'll
					// start searching from newP
					// with a large maxTries
					// later, so shortcut the
					// search from p now.
					break
				}
			}
		}
	}

	fmt.Print(frontier.String())
}