コード例 #1
0
ファイル: main.py プロジェクト: fengwu2004/Quantitative
def saveToDB():

    mypath = 'C:/Users/Administrator/Desktop/tdx-gbk/'

    f = []

    for (dirpath, dirname, filenames) in walk(mypath):

        f.extend(filenames)

    print(f)

    stocks = []

    securitiesList = []

    for file in f:

        filePath = mypath + file

        if filePath.find('.txt') == -1:

            continue

        stock = formatData(getLines(filePath))

        securitiesList.append(stock)

        stocks.append(stock.toJson())

    DatabaseMgr.instance().stocks.remove({})

    DatabaseMgr.instance().stocks.insert_many(stocks)

    result = []

    for stock in stocks:

        codeInfo = CodeInfo()

        codeInfo.code = stock['code']

        codeInfo.name = stock['name']

        result.append(codeInfo.toJson())

    DatabaseMgr.instance().stockInfos.remove({})

    DatabaseMgr.instance().stockInfos.insert_many(result)
コード例 #2
0
    def fromJson(cls, jsonvalue):

        if jsonvalue is None:

            return None

        obj = Securities()

        obj.codeInfo = CodeInfo()

        obj.codeInfo.name = jsonvalue['name']

        obj.codeInfo.code = jsonvalue['code']

        obj.klines = []

        index = 0

        for item in jsonvalue['klines']:

            kLine = KLineModel.fromJson(item)

            kLine.index = index

            index += 1

            obj.klines.append(kLine)

        return obj
コード例 #3
0
    def createCodeList(self, items:List):

        for item in items:

            codeInfo = CodeInfo(code=item["code"], name=item["name"])

            self.codeList.append(codeInfo)
コード例 #4
0
import numpy
import pandas
from data.securities import Securities
from storemgr.storemgr import SecuritiesMgr
from data.codeInfo import CodeInfo
from data.klineModel import KLineModel
import matplotlib.pyplot as plt

cdkj = SecuritiesMgr.instance().getSecurities(
    codeInfo=CodeInfo(code="600584", name="长电科技"))

jfkj = SecuritiesMgr.instance().getSecurities(
    codeInfo=CodeInfo(code="600519", name="贵州茅台"))

print(cdkj)

cdkjClose = [x.close for x in cdkj.klines]

jfkjClose = [x.close for x in jfkj.klines]

df1 = pandas.DataFrame(numpy.array(cdkjClose), columns=[cdkj.codeInfo.name])

df2 = pandas.DataFrame(numpy.array(jfkjClose), columns=[jfkj.codeInfo.name])

df = pandas.concat([df1, df2], axis=1)

corr = df.corr(method="pearson", min_periods=1)

df1.to_csv("cdkj_jfkj.csv")

df.plot(figsize=(20, 12))