Beispiel #1
0
def runLambda(q: Q, f):
    connections.create_connection()
    s = Stock.search()
    r = s.query(q)
    #	for stock in r.scan():
    stock = Stock.get(id="FR0000076887")
    f(stock)
    stock.save()
Beispiel #2
0
def main():
	stock = Stock.get(id="FR0000035370")
	#ibg.reqMatchingSymbols(20, stock.symbol)
	c = stock.contract()
	#c.primaryExchange = "SBF"
	result = ibg.getFundamentalData(stock.contract(), "ReportsFinStatements")
	f = open("data/" + stock.symbol + ".xml", "w")
	f.write(result)
	f.close()
	print(result)
Beispiel #3
0
def pollIB():
	s = Stock.search()
	s.query = Bool(must_not=[Q('exists', field='lastFinPoll'), Match(notValid=True)])
	print(json.dumps(s.query.to_dict()))
	#sit = iter(s.scan())
	#for i in range(0,10):
	for stock in s.scan():
		#stock = next(sit)
		print(stock.symbol, stock.isin)
		result = getFundamentalData(stock)
		if result == None:
			print("Invalid")
			stock.notValid = True
		else:
			stock.parseFinancials(result)
			stock.lastFinPoll = datetime.datetime.now()
		stock.save()
Beispiel #4
0
def getFundamentalData(stock: Stock):
	fName = 'data/' + stock.isin + ".xml"
	if (os.path.isfile(fName)):
		with open(fName, "r") as f:
			ret = f.read()
		if ret == '':
			return None
		else:
			return ret
	time.sleep(10)
	ret = ibg.getFundamentalData(stock.contract(), "ReportsFinStatements")
	with open(fName, "w") as f:
		if ret == None:
			f.write('')
		else:
			f.write(ret)
	return ret
Beispiel #5
0
	def generateDF(self):
		s = Stock.search()
		r = s.query(Bool(must=[Q('exists', field='lastFinPoll')], must_not=[Match(notValid=True)]))
		tuples = []
		dates = self.generateDateDimension()
		data = []
		for stock in r:
			print(stock.symbol)
			for d in dates:
				tuples.append((d, stock.symbol))
				row = []
				for f in self.fields:
					row.append(stock.getMetric(d, f))
				data.append(row)
					
		mindex = pandas.MultiIndex.from_tuples(tuples)
		df = pandas.DataFrame(data=data, index=mindex, columns=self.fields)
		return df
Beispiel #6
0
	def parseCsv(self, spamreader):
		it = iter(spamreader)
		header = next(it)
		docs = []

		for row in it:
			dictRow = to_dict(header, row)
			if (dictRow != None):
				s = Stock()
				s.name = dictRow['Name']
				s.isin = dictRow['ISIN']
				s.meta.id = s.isin
				s.symbol = dictRow['Symbol']
				s.market = dictRow['Market']
				s.currency = dictRow['Trading Currency']
				docs.append(s)

		bulk(connections.get_connection(), (d.to_dict(True) for d in docs))
Beispiel #7
0
	def generateDF2(self):
		s = Stock.search()
		r = s.query(Bool(must=[Q('exists', field='lastFinPoll')],
                   must_not=[Match(notValid=True)]))
		tuples = []
		dates = self.generateDateDimension()
		data = []
		i = 0
		for stock in r.scan():
			i = i + 1
			if i % 100 == 0:
				print(i)
			#print(stock.symbol)
			sdf = stock.getMetrics(dates, self.fields)
			data.append(sdf)

		# mindex = pandas.MultiIndex.from_tuples(tuples)
		# df = pandas.DataFrame(data=data, index=mindex, columns=self.fields)
		df = pandas.concat(data)
		return df
Beispiel #8
0
		header = next(it)
		docs = []

		for row in it:
			dictRow = to_dict(header, row)
			if (dictRow != None):
				s = Stock()
				s.name = dictRow['Name']
				s.isin = dictRow['ISIN']
				s.meta.id = s.isin
				s.symbol = dictRow['Symbol']
				s.market = dictRow['Market']
				s.currency = dictRow['Trading Currency']
				docs.append(s)

		bulk(connections.get_connection(), (d.to_dict(True) for d in docs))


	def parse(self):
		with open(self.fileName, newline='') as csvfile:
			spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
			self.parseCsv(spamreader)
	

if __name__ == "__main__":
	enParser = EuroNextParser()
	connections.create_connection()
	Stock.init()
	enParser.downloadAndParse()

Beispiel #9
0
def computeIntermediatePeriods(stock: Stock):
    print(stock.symbol)
    fins = stock.fins
    fins.sort(key=lambda fp: fp['@Type'] + ":" + fp['startDate'])
    stock.fins = fins