通过优矿API python获取财报

使用优矿平台的API:
import pandas as pd
universe = set_universe('A')
whole_set = pd.DataFrame()
for stock in universe:
    try:
        data = DataAPI.FdmtBSGet(ticker=u"",secID=stock,reportType=u"",endDate=u"20150930",beginDate=u"20150830",publishDateEnd=u"",publishDateBegin=u"",endDateRep="",beginDateRep="",beginYear="",endYear="",fiscalPeriod="",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
        whole_set = whole_set.append(data, ignore_index=True)
    except Exception:
        # print stock
        pass
       
whole_set = whole_set.set_index(['ticker'], inplace=False).fillna(0)
whole_set.columns = ['名称', '期末日期', '类型', '交易性金融资产', '持有至到期投资', '可供出售金融资产', '长期股权投资', '买入返售金融资产', '投资性房地产']
whole_set.to_csv('invest_asset.csv', encoding='GB18030')
whole_set.sort('交易性金融资产', ascending=False).head(20)
ata = DataAPI.FdmtBSAllLatestGet(ticker=u"601398",secID=u"",reportType=u"",endDate=u"",beginDate=u"",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
data = data.set_index('endDate', inplace=False).sort_index()
data['tradingFA'].plot(figsize=(15,8))
whole_set.sort('持有至到期投资', ascending=False).head(20)
whole_set.sort('持有至到期投资', ascending=False)[20:30]
data = DataAPI.FdmtBSAllLatestGet(ticker=u"600291",secID=u"",reportType=u"",endDate=u"",beginDate=u"",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
data = data.set_index('endDate', inplace=False).sort_index()
data['htmInvest'].plot(figsize=(15,8))
whole_set.sort('可供出售金融资产', ascending=False).head(20)
whole_set.sort('可供出售金融资产', ascending=False)[20:30]
ata = DataAPI.FdmtBSAllLatestGet(ticker=u"600104",secID=u"",reportType=u"",endDate=u"",beginDate=u"",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
data = data.set_index('endDate', inplace=False).sort_index()
data['availForSaleFa'].plot(figsize=(15,8))
whole_set.sort('长期股权投资', ascending=False).head(20)
data = DataAPI.FdmtBSAllLatestGet(ticker=u"601857",secID=u"",reportType=u"",endDate=u"",beginDate=u"",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
data = data.set_index('endDate', inplace=False).sort_index()
data['LTEquityInvest'].plot(figsize=(15,8))
whole_set.sort('买入返售金融资产', ascending=False).head(20)
whole_set.sort('投资性房地产', ascending=False).head(20)
data = DataAPI.FdmtBSAllLatestGet(ticker=u"000926",secID=u"",reportType=u"",endDate=u"",beginDate=u"",field=u"ticker,secShortName,endDate,reportType,tradingFA,htmInvest,availForSaleFa,LTEquityInvest,purResaleFa,investRealEstate",pandas="1")
data = data.set_index('endDate', inplace=False).sort_index()
data['investRealEstate'].plot(figsize=(15,8))

你可能感兴趣的:(量化)