Commit ec000409 authored by Dr.李's avatar Dr.李
parents 88d00b30 03a5e1cf
......@@ -5,7 +5,8 @@ Created on 2017-6-29
@author: cheng.li
"""
from sqlalchemy import BigInteger, Column, DateTime, Float, Index, Integer, JSON, String, Text, Boolean, text
from sqlalchemy import BigInteger, Column, DateTime, Float, Index, Integer, String, Text, Boolean, text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
......@@ -614,6 +615,7 @@ class Experimental(Base):
EPAfterNonRecurring = Column(Float(53))
DROEAfterNonRecurring = Column(Float(53))
CFinc1 = Column(Float(53))
xueqiu_hotness = Column(Float(53))
class FactorMaster(Base):
......@@ -800,7 +802,8 @@ class Models(Base):
model_type = Column(String(30), nullable=False)
model_version = Column(BigInteger, nullable=False)
update_time = Column(DateTime, nullable=False)
model_desc = Column(JSON, nullable=False)
model_desc = Column(JSONB, nullable=False)
is_primary = Column(Boolean, default=False)
model_id = Column(Integer, primary_key=True, server_default=text("nextval('models_model_id_seq'::regclass)"))
......@@ -856,7 +859,7 @@ class Positions(Base):
trade_date = Column(DateTime, primary_key=True, nullable=False)
portfolio = Column(String(50), primary_key=True, nullable=False)
type = Column(String(50), primary_key=True, nullable=False)
weight = Column(JSON)
weight = Column(JSONB)
class QuantileAnalysis(Base):
......@@ -931,6 +934,19 @@ class RiskCovDay(Base):
FoodBever = Column(Float(53))
Electronics = Column(Float(53))
Computer = Column(Float(53))
LightIndus = Column(Float(53))
Utilities = Column(Float(53))
Telecom = Column(Float(53))
AgriForest = Column(Float(53))
CHEM = Column(Float(53))
Media = Column(Float(53))
IronSteel = Column(Float(53))
NonBankFinan = Column(Float(53))
ELECEQP = Column(Float(53))
AERODEF = Column(Float(53))
Conglomerates = Column(Float(53))
COUNTRY = Column(Float(53))
updateTime = Column(DateTime)
class RiskCovLong(Base):
......@@ -1738,5 +1754,5 @@ class Uqer(Base):
if __name__ == '__main__':
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://postgres:we083826@192.168.0.102/alpha')
engine = create_engine('postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha')
Base.metadata.create_all(engine)
......@@ -534,11 +534,19 @@ class SqlEngine(object):
return total_data
def fetch_model(self,
ref_date,
ref_date=None,
model_type=None,
model_version=None) -> pd.DataFrame:
model_version=None,
is_primary=True,
model_id=None) -> pd.DataFrame:
conditions = [Models.trade_date == ref_date]
conditions = []
if ref_date:
conditions.append(Models.trade_date == ref_date)
if model_id:
conditions.append(Models.model_id == model_id)
if model_type:
conditions.append(Models.model_type == model_type)
......@@ -546,6 +554,8 @@ class SqlEngine(object):
if model_version:
conditions.append(Models.model_version == model_version)
conditions.append(Models.is_primary == is_primary)
query = select([Models]).where(and_(*conditions))
model_df = pd.read_sql(query, self.engine)
......
......@@ -8,5 +8,5 @@ scipy >= 0.19.0
simpleutils >= 0.1.0
sqlalchemy >= 1.1.9
pandas >= 0.19.2
psycopg2 >= 2.7.3
psycopg2 >= 2.7.1
Finance-Python >= 0.5.5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment