Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31',
'2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30',
'2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31',
'2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30',
'2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31',
'2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30',
'2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
'2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30', '2002-06-30',
'2002-03-31', '2001-12-31', '2001-06-30', '2000-12-31', '2000-06-30', '1999-12-31',
'1999-06-30', '1998-12-31', '1998-06-30', '1997-12-31', '1997-06-30', '1996-12-31',
'1995-12-31', '1994-12-31']
result = fundamental.get_finance_factor(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000778'], end_timestamp='2018-09-30',
order=FinanceFactor.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: FinanceFactor = result[0]
assert latest.basic_eps == 0.4537
assert latest.diluted_eps == 0.4537
assert latest.bps == 5.0919
assert latest.capital_reserve_ps == 2.1769
assert latest.undistributed_profit_ps == 1.8132
assert latest.op_cash_flow_ps == 1.0148
assert latest.total_op_income == 31710000000
assert latest.gross_profit == 5491000000
assert latest.net_profit == 1811000000
assert latest.deducted_net_profit == 1897000000
assert latest.op_income_growth_yoy == -0.1024
assert latest.net_profit_growth_yoy == 1.2404
assert latest.deducted_net_profit_growth_yoy == 1.4813
'2011-06-30', '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31',
'2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30',
'2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31',
'2006-12-31', '2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30',
'2005-06-30', '2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31',
'2003-12-31', '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30',
'2002-06-30', '2002-03-31', '2001-12-31', '2001-09-30', '2001-06-30', '2001-03-31',
'2000-12-31', '2000-06-30', '1999-12-31', '1999-06-30', '1998-12-31', '1998-06-30',
'1997-12-31', '1997-06-30', '1996-12-31', '1996-06-30', '1995-12-31', '1995-06-30',
'1994-12-31', '1994-06-30', '1993-12-31', '1993-06-30', '1992-12-31', '1991-12-31',
'1990-12-31', '1989-12-31']
result = fundamental.get_income_statement(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000001'], end_timestamp='2018-09-30',
order=IncomeStatement.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: IncomeStatement = result[0]
assert latest.operating_income == 86660000000
assert latest.fi_net_interest_income == 54530000000
assert latest.fi_interest_income == 121700000000
assert latest.fi_interest_expenses == 67130000000
assert latest.fi_net_incomes_from_fees_and_commissions == 23710000000
assert latest.fi_incomes_from_fees_and_commissions == 28920000000
assert latest.fi_expenses_for_fees_and_commissions == 5218000000
assert latest.investment_income == 7099000000
assert latest.fi_income_from_fair_value_change == 1047000000
assert latest.fi_income_from_exchange == -40000000
assert latest.fi_other_income == 144000000
assert latest.operating_costs == 26430000000
'2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31',
'2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30',
'2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31',
'2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30',
'2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31',
'2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30',
'2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
'2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30', '2002-06-30',
'2002-03-31', '2001-12-31', '2001-06-30', '2000-12-31', '2000-06-30', '1999-12-31',
'1999-06-30', '1998-12-31', '1998-06-30', '1997-12-31', '1997-06-30', '1996-12-31',
'1995-12-31', '1994-12-31']
result = fundamental.get_income_statement(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000778'], end_timestamp='2018-09-30',
order=IncomeStatement.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: IncomeStatement = result[0]
assert latest.operating_income == 31710000000
assert latest.total_operating_costs == 29230000000
assert latest.operating_costs == 26220000000
assert latest.rd_costs == 185500000
assert latest.net_change_in_insurance_contract_reserves == 0
assert latest.business_taxes_and_surcharges == 359700000
assert latest.sales_costs == 771400000
assert latest.managing_costs == 472900000
assert latest.financing_costs == 397500000
assert latest.assets_devaluation == 824400000
assert latest.investment_income == 104100000
assert latest.investment_income_from_related_enterprise == 61290000
'2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31',
'2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30',
'2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31',
'2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30',
'2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
'2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30', '2002-06-30',
'2002-03-31', '2001-12-31', '2001-09-30', '2001-06-30', '2001-03-31', '2000-12-31',
'2000-06-30', '1999-12-31', '1999-06-30', '1998-12-31', '1998-06-30', '1997-12-31',
'1997-06-30', '1996-12-31', '1996-06-30', '1995-12-31', '1995-06-30', '1994-12-31',
'1994-06-30', '1993-12-31', '1993-06-30', '1992-12-31', '1991-12-31', '1990-12-31',
'1989-12-31']
result = fundamental.get_finance_factor(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000001'], end_timestamp='2018-09-30',
order=FinanceFactor.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: FinanceFactor = result[0]
assert latest.basic_eps == 1.14
assert latest.deducted_eps == 1.13
assert latest.diluted_eps == 1.14
assert latest.bps == 12.538
assert latest.capital_reserve_ps == 3.2886
assert latest.undistributed_profit_ps == 5.3566
assert latest.op_cash_flow_ps == -0.6587
assert latest.total_op_income == 86660000000
assert latest.net_profit == 20460000000
assert latest.deducted_net_profit == 20350000000
assert latest.op_income_growth_yoy == 0.0856
assert latest.net_profit_growth_yoy == 0.068
assert latest.deducted_net_profit_growth_yoy == 0.0636
'2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31', '2014-12-31', '2014-09-30',
'2014-06-30', '2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31',
'2012-12-31', '2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30',
'2011-06-30', '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31',
'2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30',
'2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31',
'2006-12-31', '2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30',
'2005-06-30', '2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31',
'2003-12-31', '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-06-30',
'2001-12-31', '2001-06-30', '2000-12-31', '2000-06-30', '1999-12-31', '1999-06-30',
'1998-12-31', '1998-06-30']
result = fundamental.get_cash_flow_statement(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000001'], end_timestamp='2018-09-30',
order=CashFlowStatement.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: CashFlowStatement = result[0]
# 00000000
assert latest.fi_deposit_increase == 104700000000
assert latest.fi_borrow_from_central_bank_increase == 18960000000
assert latest.fi_deposit_in_others_decrease == 60880000000
assert latest.fi_lending_and_buy_repurchase_decrease == 12330000000
assert latest.fi_lending_decrease == 12270000000
assert latest.fi_buy_repurchase_decrease == 56000000
assert latest.fi_cash_from_interest_commission == 133700000000
assert latest.cash_from_other_op == 20540000000
assert latest.total_op_cash_inflows == 381200000000
assert latest.fi_loan_advance_increase == 250300000000
assert latest.fi_borrowing_and_sell_repurchase_decrease == 14350000000
assert latest.fi_borrowing_decrease == 10190000000
'2017-03-31', '2016-12-31', '2016-09-30', '2016-06-30', '2016-03-31', '2015-12-31',
'2015-09-30', '2015-06-30', '2015-03-31', '2014-12-31', '2014-09-30', '2014-06-30',
'2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31',
'2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30',
'2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31',
'2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30',
'2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31',
'2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30',
'2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
'2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-06-30', '2001-12-31',
'2001-06-30', '2000-12-31', '2000-06-30', '1999-12-31', '1998-12-31', '1998-06-30']
result = fundamental.get_cash_flow_statement(session=session, provider=Provider.EASTMONEY, return_type='domain',
codes=['000778'], end_timestamp='2018-09-30',
order=CashFlowStatement.timestamp.desc())
assert len(correct_timestamps) == len(result)
timestamps = [to_time_str(item.timestamp) for item in result]
assert set(correct_timestamps) == set(timestamps)
latest: CashFlowStatement = result[0]
assert latest.cash_from_selling == 27784000000
assert latest.tax_refund == 60700000
assert latest.cash_from_other_op == 1463000000
assert latest.total_op_cash_inflows == 29310000000
assert latest.cash_to_goods_services == 21210000000
assert latest.cash_to_employees == 1460000000
assert latest.taxes_and_surcharges == 2016000000
assert latest.cash_to_other_related_op == 573700000
assert latest.total_op_cash_outflows == 25260000000
assert latest.net_op_cash_flows == 4050000000
assert latest.cash_from_disposal_of_investments == 556500000
assert latest.cash_from_returns_on_investments == 44180000
def on_finish(self, security_item):
kdatas = get_kdata(security_id=security_item.id, level=self.level.value, order=StockDayKdata.timestamp.asc(),
return_type='domain',
session=self.session,
filters=[StockDayKdata.hfq_close.is_(None),
StockDayKdata.timestamp >= to_pd_timestamp('2005-01-01')])
if kdatas:
start = kdatas[0].timestamp
end = kdatas[-1].timestamp
# get hfq from joinquant
df = get_price(to_jq_security_id(security_item), start_date=to_time_str(start), end_date=now_time_str(),
frequency='daily',
fields=['factor', 'open', 'close', 'low', 'high'],
skip_paused=True, fq='post')
if df is not None and not df.empty:
# fill hfq data
for kdata in kdatas:
if kdata.timestamp in df.index:
kdata.hfq_open = df.loc[kdata.timestamp, 'open']
kdata.hfq_close = df.loc[kdata.timestamp, 'close']
kdata.hfq_high = df.loc[kdata.timestamp, 'high']
kdata.hfq_low = df.loc[kdata.timestamp, 'low']
kdata.factor = df.loc[kdata.timestamp, 'factor']
self.session.commit()
latest_factor = df.factor[-1]
# factor not change yet, no need to reset the qfq past
def draw_positions(trader_name, render='html'):
df_position = get_position(trader_name=trader_name)
time_line = get_default_timeline()
for timestamp in df_position.index:
securities = df_position.loc[timestamp, ['security_id']].values.tolist()
positions = zip(securities,
df_position.loc[timestamp, ['value']].values.tolist())
if len(securities) > 1:
security_positions = [(x[0], y[0]) for x, y in positions]
else:
security_positions = [(x, y) for x, y in positions]
print(security_positions)
pie = Pie().add('{} positions'.format(trader_name), security_positions)
time_line.add(pie, to_time_str(timestamp))
if render == 'html':
file_name = '{}_positions'.format(trader_name)
time_line.render(get_ui_path(file_name))
elif render == 'notebook':
time_line.render_notebook()
return time_line
def request(self, url=None, method='get', param=None, path_fields=None):
security_item = param['security_item']
start_timestamp = param['start_timestamp']
# 不复权
df = get_price(to_jq_security_id(security_item), start_date=to_time_str(start_timestamp),
end_date=now_time_str(),
frequency='daily',
fields=['open', 'close', 'low', 'high', 'volume', 'money'],
skip_paused=True, fq=None)
df.index.name = 'timestamp'
df.reset_index(inplace=True)
df['name'] = security_item.name
df.rename(columns={'money': 'turnover'}, inplace=True)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['provider'] = Provider.JOINQUANT.value
df['level'] = param['level']
return df.to_dict(orient='records')
def generate_request_param(self, security_item, start, end, size, timestamp):
return {
'security_item': security_item,
'start_timestamp': to_time_str(start, fmt=TIME_FORMAT_DAY1),
'end_timestamp': now_time_str(fmt=TIME_FORMAT_DAY1),
'level': self.level.value
}