#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-22 15:17 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import ttm_factory dd = DataDescription(ttm_factory('NPParentCompanyOwners', 'IS'), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='归属上市公司股东的净利润TTM')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-25 15:46 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from index_template import get_index_weights dd = DataDescription(get_index_weights('000852'), trans_date('2018-05-25'), DataType.PANEL_NUMERIC, dep=['UNIVERSE'], desc='中证1000指数成分权重,数值表示权重((0, 100)),其他(NA)表示非指数成分')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-25 16:27 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory dd = DataDescription( divide_data_factory( pitcache_getter('EQUITY', 10).get_tsdata, pitcache_getter('TOTAL_CMKV', 10).get_tsdata), trans_date('2018-05-25'), DataType.PANEL_NUMERIC, ['EQUITY', 'TOTAL_CMKV', 'LIST_STATE'], '归属母公司的权益TTM/总市值')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-22 13:48 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import lnmkv_factory dd = DataDescription(lnmkv_factory('TOTAL_CMKV'), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, dep=['TOTAL_CMKV', 'LIST_STATE'], desc='对数总市值')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-24 11:00 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('ISY', 'NPParentCompanyOwners', 4, 4), trans_date('2018-05-24'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='往前推4个财年的归属母公司净利润')
Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-07-30 16:51 """ from sys import path as sys_path from os.path import dirname import numpy as np from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory, abs_wrapper def numerator(start_time, end_time): # 营业利润=营业收入-营业成本-销售费用-管理费用-财务费用 opr_ttm = pitcache_getter('OPR_TTM', 10).get_tsdata(start_time, end_time) opcost_ttm = pitcache_getter('OPCOST_TTM', 10).get_tsdata(start_time, end_time) opexp_ttm = pitcache_getter('OPEXP_TTM', 10).get_tsdata(start_time, end_time) adminexp_ttm = pitcache_getter('ADMINEXP_TTM', 10).get_tsdata(start_time, end_time) fiexp_ttm = pitcache_getter('FIEXP_TTM', 10).get_tsdata(start_time, end_time) return opr_ttm - opcost_ttm - opexp_ttm - adminexp_ttm - fiexp_ttm dd = DataDescription(divide_data_factory(numerator, abs_wrapper(pitcache_getter('OPR_TTM', 10).get_tsdata)), trans_date('2018-07-30'), DataType.PANEL_NUMERIC, ['OPR_TTM', 'OPCOST_TTM', 'OPEXP_TTM', 'ADMINEXP_TTM', 'FIEXP_TTM'], '总营业利润率 = (营业收入-营业成本-销售费用-管理费用-财务费用) / abs(营业收入)')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-08-21 16:54 """ from sys import path as sys_path from os.path import dirname import numpy as np from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import momentum_factory dd = DataDescription(momentum_factory(66, 22), trans_date('2018-08-21'), DataType.PANEL_NUMERIC, ['UNIVERSE', 'CLOSE_ADJ', 'LIST_STATE'], '3月动量,剔除最近一个月', True)
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-07-30 14:02 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('BS', 'TotalAssets', 5, 1), trans_date('2018-07-30'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='往前推5个报告期的总资产')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-23 16:40 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('BS', 'EPreferStock', 1, 1), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='最近一个报告期的优先股')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-14 16:43:54 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import mkv_factory dd = DataDescription(mkv_factory('FLOAT_SHARES', 'CLOSE'), trans_date('2018-05-14'), DataType.PANEL_NUMERIC, dep=['CLOSE', 'FLOAT_SHARES', 'LIST_STATE'], desc='流通市值(由收盘价计算)')
Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-25 16:49 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory def get_ev(start_time, end_time): mkv_data = pitcache_getter('TOTAL_CMKV', 10).get_tsdata(start_time, end_time) ncl_data = pitcache_getter('TNCL', 10).get_tsdata(start_time, end_time).fillna(0) cash_data = pitcache_getter('CASH', 10).get_tsdata(start_time, end_time).fillna(0) return mkv_data + ncl_data - cash_data dd = DataDescription( divide_data_factory(pitcache_getter('OPR_TTM', 10).get_tsdata, get_ev), trans_date('2018-05-25'), DataType.PANEL_NUMERIC, ['CASH', 'TNCL', 'OPR_TTM', 'TOTAL_CMKV', 'LIST_STATE'], '营业收入TTM/(总市值+非流动性负债合计-现金)')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-09 10:34:02 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from index_template import get_index_weights dd = DataDescription( get_index_weights('000016'), trans_date('2018-05-09'), DataType.PANEL_NUMERIC, dep=['UNIVERSE'], desc='上证50指数成分权重,数值表示权重((0, 100)),其他(NA)表示非指数成分;数据库中该数据起始时间为2011-03-27')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-24 09:53 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('BS', 'TotalAssets', 2, 4), trans_date('2018-05-24'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='次近财年的总资产')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-10 14:52:51 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from stock_share_template import get_shares dd = DataDescription(get_shares('TotalShares'), trans_date('2018-05-10'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='总股本')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-10 11:00:30 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from index_template import get_index_quote dd = DataDescription(get_index_quote('000016', 'LowPrice'), trans_date('2018-05-10'), DataType.TS_NUMERIC, desc='上证50最低价')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-23 16:25 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('BS', 'TotalCurrentAssets', 1, 1), trans_date('2018-05-23'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='最近一个报告期的流动性资产')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-02 16:49:05 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import quotes_factory dd = DataDescription(quotes_factory('TurnoverDeals'), trans_date('2018-05-02'), DataType.PANEL_NUMERIC, dep=['UNIVERSE'], desc='成交笔数')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-22 16:07 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import ttm_factory dd = DataDescription(ttm_factory('OperatingProfit', 'IS'), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='营业利润TTM')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-02 16:50:12 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import quotes_factory dd = DataDescription(quotes_factory('PrevClosePrice'), trans_date('2018-05-02'), DataType.PANEL_NUMERIC, dep=['UNIVERSE'], desc='未复权前收盘价')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-22 13:13 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import sto_factory dd = DataDescription(sto_factory(1, 21), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, ['TO_RATE', 'LIST_STATE'], '月换手率因子')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-06-07 15:06 """ from sys import path as sys_path from os.path import dirname import numpy as np from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory dd = DataDescription( divide_data_factory( pitcache_getter('NI_TTM', 10).get_tsdata, pitcache_getter('TOTAL_SHARES', 10).get_tsdata), trans_date('2018-06-07'), DataType.PANEL_NUMERIC, ['NI_TTM', 'TOTAL_SHARES'], 'Earnings per share TTM')
Github: https://github.com/SAmmer0 Created: 2018-07-27 17:08 """ from sys import path as sys_path from os.path import dirname import numpy as np from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory def equity_dropped_negetive(start_time, end_time): ''' 将归属母公司权益为负的公司权益设置为NA ''' data = pitcache_getter('EQUITY5S', 10).get_tsdata(start_time, end_time) data = data.where(data > 0, np.nan) return data dd = DataDescription( divide_data_factory( pitcache_getter('NI_TTM', 10).get_tsdata, equity_dropped_negetive), trans_date('2018-07-27'), DataType.PANEL_NUMERIC, ['NI_TTM', 'EQUITY5S'], 'ROE TTM等于NI_TTM/EQUITY5S')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-07-17 13:34 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import xps_shift_factory dd = DataDescription(xps_shift_factory('ISY', 'NPParentCompanyOwners', 2, 4), trans_date('2018-07-17'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='上一个财年的EPS=上一个财年归属母公司的净利润/总股本')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-08-07 16:44 """ from sys import path as sys_path from os.path import dirname import numpy as np from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import divide_data_factory dd = DataDescription( divide_data_factory( pitcache_getter('OPNCF_TTM', 10).get_tsdata, pitcache_getter('OPP_TTM', 10).get_tsdata), trans_date('2018-08-07'), DataType.PANEL_NUMERIC, ['OPNCF_TTM', 'OPP_TTM'], '经营活动中的现金流量净额TTM/营业利润TTM')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-23 16:47 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import shift_factory dd = DataDescription(shift_factory('ISY', 'TotalOperatingRevenue', 1, 1), trans_date('2018-05-23'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='最近一个季度的营业收入')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-05-22 14:06 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from quotes_template import nl_lnmkv_factory dd = DataDescription(nl_lnmkv_factory('TOTAL_LNCMKV', 3), trans_date('2018-05-22'), DataType.PANEL_NUMERIC, dep=['TOTAL_LNCMKV'], desc='对数总市值的3次方')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-07-18 11:08 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription, pitcache_getter if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from derivate_template import growth_rate_factory dd = DataDescription(growth_rate_factory('EPS{i:d}Y', 5), trans_date('2018-07-18'), DataType.PANEL_NUMERIC, ['EPS{i:d}Y'.format(i=i) for i in range(1, 6)], desc='过去5年EPS增长率')
#!/usr/bin/env python # -*- coding:utf-8 """ Author: Hao Li Email: [email protected] Github: https://github.com/SAmmer0 Created: 2018-07-17 13:41 """ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from fundamental_template import xps_shift_factory dd = DataDescription(xps_shift_factory('ISY', 'TotalOperatingRevenue', 4, 4), trans_date('2018-07-17'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='往前推4个年度的SPS=往前推4个财年的总营业收入/总股本')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-10 15:22:15 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from stock_share_template import get_shares dd = DataDescription(get_shares('NonResiSharesJY'), trans_date('2018-05-10'), DataType.PANEL_NUMERIC, dep=['UNIVERSE', 'LIST_STATE'], desc='流通股本')
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-05-11 16:02:12 # @Author : Hao Li ([email protected]) # @Link : https://github.com/SAmmer0 # @Version : $Id$ from sys import path as sys_path from os.path import dirname from tdtools import trans_date from pitdata.const import CALCULATION_FOLDER_PATH, DataType from pitdata import DataDescription if CALCULATION_FOLDER_PATH not in sys_path: sys_path.append(dirname(CALCULATION_FOLDER_PATH)) from stock_adjprice_template import get_adjprice dd = DataDescription(get_adjprice('CLOSE', 'PADJ_FACTOR'), trans_date('2018-05-11'), DataType.PANEL_NUMERIC, dep=['CLOSE', 'PADJ_FACTOR', 'UNIVERSE'], desc='后复权收盘价')