As zipline doesn't support
get_fundamentals()
I'm trying to implement an own SQLAlchemy Model that totally replicates the original one and then feed it with my data.
Unfortunately I cannot really figure out how to do it and I hope the the Quantopian developer could help.
Actually I defined this model (it's of course not complete):
Base = declarative_base()
class Balance_sheet(Base):
__tablename__ = 'balance_sheet'
id = Column(Integer, primary_key=True)
total_assets = Column(Integer)
cash = Column(Integer)
# and so on ...
class Income_statement(Base):
__tablename__ = 'income_statement'
id = Column(Integer, primary_key=True)
ebit = Column(Integer)
ebitda = Column(Integer)
# and so on ...
class Fundamentals(Base):
__tablename__ = 'fundamentals'
id = Column(Integer, primary_key=True)
symbol = Column(String)
date = Column(Date)
balance_sheet_id = Column(Integer, ForeignKey('balance_sheet.id'))
balance_sheet = relationship("Balance_sheet", backref="fundamentals", uselist=False)
income_statement_id = Column(Integer, ForeignKey('income_statement.id'))
income_statement = relationship("Income_statement", backref="fundamentals", uselist=False)
def __init__(self, symbol, date):
self.symbol = symbol
self.date = date
It works to query like this:
q = s.query(Balance_sheet).filter(Balance_sheet.total_assets > 0).options(joinedload('fundamentals'))
df = pd.read_sql(q.statement,s.bind)
df.index = df['symbol']
but not like the original Quantopian API, that is i.e.:
s.query(fundamentals.balance_sheet.total_assets).filter(fundamentals.balance_sheet.total_assets> 0)