Ejemplo n.º 1
0
Archivo: tsa.py Proyecto: zhilim/TSA
	def fit(self):
		pso.dmn = self.dimensions
		pso.searchRange = float(1)/float(pso.dmn)
		pso.maxIterations = 100
		s,i,g = pso.particleSwarmOptimize(self.divinecost, True, True)
		self.weights = s
		return s,i,g
Ejemplo n.º 2
0
def learn(search):
	pso.dmn = len(qds[0])
	pso.searchRange = float(search)
	s,i,g = pso.particleSwarmOptimize(MCC, True, True)
	f = open('weight.txt', 'w')
	f.write(str(s))
	f.close()
	return s, i, g
Ejemplo n.º 3
0
Archivo: tsa.py Proyecto: zhilim/TSA
	def fit(self):
		pso.dmn = self.dimensions
		s, i, g = pso.particleSwarmOptimize(self.costfunction, True, True)
		self.ar = s[:self.p]
		self.ma = s[self.p:self.p+self.q]
		#self.varC = s[self.p+self.q]
		#self.wnC = s[self.p+self.q+1]
		#self.error = s[self.p+self.q]
		print s, i, g
		return s, i, g
Ejemplo n.º 4
0
def famaLearn():
	print "the year is now " + year
	logname = 'results/newfamaWeights.txt'
	f = open(logname, 'a')
	pso.dmn = len(ratios)

	ans, i, opt = pso.particleSwarmOptimize(famaFrench, True, True)

	yearString = str(year)
	report = "Weights: " + str(ans) + ", Spearman: " + str(opt)
	famaPlot(ans)
	f.write("\n")
	f.write(str(year) + " to " + str(int(year) + 4))
	f.write("\n")
	f.write(report)
	f.close()
	return ans
Ejemplo n.º 5
0
def famaLearn():
    print "the year is now " + year
    logname = 'results/newfamaWeights.txt'
    f = open(logname, 'a')
    pso.dmn = len(ratios)

    ans, i, opt = pso.particleSwarmOptimize(famaFrench, True, True)

    yearString = str(year)
    report = "Weights: " + str(ans) + ", Spearman: " + str(opt)
    famaPlot(ans)
    f.write("\n")
    f.write(str(year) + " to " + str(int(year) + 4))
    f.write("\n")
    f.write(report)
    f.close()
    return ans
Ejemplo n.º 6
0
def learn(y):
	
	print "the year is now " + year
	logname = 'results/weights.txt'
	f = open(logname, 'a')
	pso.dmn = len(ratios)
	
	ans, i, opt = pso.particleSwarmOptimize(calculateFitness, True, True)
		
	yearstring = str(year)
	report =  "Weights: " + str(ans) + ", Spearman: " + str(opt)
	ps = plotFitness(ans)
	f.write("\n")
	f.write(yearstring + ", Portfolio Size: " + str(ps) + ", 30 Portfolios")
	f.write("\n")
	f.write(report)

	f.close()
Ejemplo n.º 7
0
def spearLearn():
    global year
    print "the year is now " + year
    logname = 'results/avgSpearWeights.txt'
    f = open(logname, 'a')
    pso.dmn = len(ratios)

    ans, i, opt = pso.particleSwarmOptimize(bestAvgSpear, True, True)

    yearString = str(year)
    report = "Weights: " + str(ans) + ", Spearman: " + str(opt)

    f.write("\n")
    f.write(str(year) + " to " + str(int(year) + 3))
    f.write("\n")
    f.write(report)
    f.close()
    return ans
Ejemplo n.º 8
0
def learn(y):

    print "the year is now " + year
    logname = 'results/weights.txt'
    f = open(logname, 'a')
    pso.dmn = len(ratios)

    ans, i, opt = pso.particleSwarmOptimize(calculateFitness, True, True)

    yearstring = str(year)
    report = "Weights: " + str(ans) + ", Spearman: " + str(opt)
    ps = plotFitness(ans)
    f.write("\n")
    f.write(yearstring + ", Portfolio Size: " + str(ps) + ", 30 Portfolios")
    f.write("\n")
    f.write(report)

    f.close()
Ejemplo n.º 9
0
def spearLearn():
	global year
	print "the year is now " + year
	logname = 'results/avgSpearWeights.txt'
	f = open(logname, 'a')
	pso.dmn = len(ratios)

	ans, i, opt = pso.particleSwarmOptimize(bestAvgSpear, True, True)

	yearString = str(year)
	report = "Weights: " + str(ans) + ", Spearman: " + str(opt)
	

	f.write("\n")
	f.write(str(year) + " to " + str(int(year) + 3))
	f.write("\n")
	f.write(report)
	f.close()
	return ans