1 Star 0 Fork 0

yutiansut / QAFACTOR

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
factorManager.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
yutiansut 提交于 2021-05-22 20:44 . #update manager
import clickhouse_driver
import datetime
import pandas as pd
class QAFactorManager():
def __init__(self) -> None:
self.client = clickhouse_driver.Client(host='localhost',database='factor')
#self.client.execute('CREATE DATABASE factor')
def get_all_factorname(self):
data = self.client.query_dataframe('select factorname from regfactor').drop_duplicates().factorname.tolist()
return data
def get_all_tables(self):
return self.client.query_dataframe('show tables').drop_duplicates()
def get_single_factor(self, factorname):
print(factorname)
res = self.client.query_dataframe('select * from {}'.format(factorname))
if len(res)>0:
res.columns = ['date', 'code', factorname]
return res.set_index(['date', 'code']).sort_index()
else:
return pd.DataFrame([])
def unreg_factor(self, factorname):
self.client.execute("ALTER TABLE regfactor DELETE WHERE factorname='{}'".format(factorname))
self.client.execute('drop table {}'.format(factorname))
def get_all_factor_values(self, factorlist=None):
factorlist = self.get_all_factorname() if factorlist is None else factorlist
res = pd.concat([self.get_single_factor(factor) for factor in factorlist], axis=1)
return res
Python
1
https://gitee.com/yutiansut/QAFACTOR.git
git@gitee.com:yutiansut/QAFACTOR.git
yutiansut
QAFACTOR
QAFACTOR
main

搜索帮助