Commit ca469d54 authored by 李煜's avatar 李煜

update readme

parent efcf8151
......@@ -2,36 +2,36 @@
RL 因子计算
# 1、目录架构
.
├── client # 客户端任务执行入口
│   ├── __init__.py
│   ├── all_factor_cal.py # 所有因子合并计算
│   ├── cash_flow.py
│   ├── constrain.py
│   ├── earning.py
│   ├── factor_scale_value.py
│   ├── factor_volatility_value.py
│   ├── growth.py
│   ├── historical_value.py
│   └── per_share_indicator.py
├── factor # 因子计算任务列表
│   ├── __init__.py
│   ├── factor_cash_flow.py # 收益质量
│   ├── factor_constrain.py # 收益质量
│   ├── factor_earning.py # 收益质量
│   ├── factor_per_share_indicators.py # 收益质量
│   ├── factor_growth.py # 历史成长
│   ├── factor_scale_value_task.py # 规模
│   ├── factor_volatility_value_task.py # 波动
│   ├── historical_value.py # 价值
│   ├── factor_base.py # 基类
│   ├── factor_config.py # 因子计算配置文件,包括数据读取地址, 存储地址等
│   ├── ttm_fundamental.py # TTM转换类
│   └── utillities # 工具类
├── README.md
├── cluster_work.py
├── init.py
└── sumbit.py
.
├── client # 客户端任务执行入口
│   ├── __init__.py
│   ├── all_factor_cal.py # 所有因子合并计算
│   ├── cash_flow.py
│   ├── constrain.py
│   ├── earning.py
│   ├── factor_scale_value.py
│   ├── factor_volatility_value.py
│   ├── growth.py
│   ├── historical_value.py
│   └── per_share_indicator.py
├── factor # 因子计算任务列表
│   ├── __init__.py
│   ├── factor_cash_flow.py # 收益质量
│   ├── factor_constrain.py # 收益质量
│   ├── factor_earning.py # 收益质量
│   ├── factor_per_share_indicators.py # 收益质量
│   ├── factor_growth.py # 历史成长
│   ├── factor_scale_value_task.py # 规模
│   ├── factor_volatility_value_task.py # 波动
│   ├── historical_value.py # 价值
│   ├── factor_base.py # 基类
│   ├── factor_config.py # 因子计算配置文件,包括数据读取地址, 存储地址等
│   ├── ttm_fundamental.py # TTM转换类
│   └── utillities # 工具类
├── README.md
├── cluster_work.py
├── init.py
└── sumbit.py
# 2、细节说明
### /factor
......@@ -42,11 +42,8 @@ RL 因子计算
##### 使用示例
```shell
# 更新
python earning.py --end_date 20190101 --count 3 --update True
python constrain.py --end_date 20190101 --count 3 --update True
python cash_flow.py --end_date 20190101 --count 3 --update True
python per_share_indicator.py --end_date 20190101 --count 3 --update True
python all_factor_cal.py --end_date 20190101 --count 3 --update True
python ./client/earning.py --end_date 20190101 --count 3 --update True
python ./client/all_factor_cal.py --end_date 20190101 --count 3 --update True
```
具体参见client中的每个客户端代码。
......
......@@ -22,7 +22,7 @@ import time
import collections
import pandas as pd
from datetime import datetime, timedelta
from jpy.factor.factor_base import FactorBase
from factor.factor_base import FactorBase
from vision.fm.signletion_engine import *
from vision.file_unit.income import Income
from vision.file_unit.valuation import Valuation
......
......@@ -17,12 +17,10 @@ import argparse
from datetime import datetime, timedelta
from factor import historical_value
from factor.ttm_fundamental import *
from vision.file_unit.balance import Balance
from vision.file_unit.cash_flow import CashFlow
from vision.file_unit.income import Income
from vision.file_unit.valuation import Valuation
from vision.file_unit.industry import Industry
from vision.file_unit.indicator import Indicator
from factor.utillities.trade_date import TradeDate
from ultron.cluster.invoke.cache_data import cache_data
......
......@@ -111,21 +111,29 @@ def calculate(**kwargs):
factor_scale_value = nlsize(factor_scale_value, factor_scale_value)
factor_scale_value = lst(factor_scale_value, factor_scale_value)
factor_scale_value = ltlqa(factor_scale_value, factor_scale_value)
factor_scale_value.rename(columns={'market_cap': 'mkt_value',
'circulating_market_cap': 'cir_mkt_value',
'total_operating_revenue': 'sales_ttm'},
inplace=True)
factor_scale_value = factor_scale_value[['symbol',
'mkt_value',
'cir_mkt_value',
'sales_ttm',
'total_assets',
'log_of_mkt_value',
'log_of_neg_mkt_value',
'nl_size',
'log_total_last_qua_assets',
'log_sales_ttm'
]]
factor_scale_value.rename(columns={
'market_cap': 'MktValue',
'circulating_market_cap': 'CirMktValue',
'total_operating_revenue': 'SalesTTM',
'total_assets': 'TotalAssets',
'log_of_mkt_value': 'LogofMktValue',
'log_of_neg_mkt_value': 'LogofNegMktValue',
'nl_size': 'NLSIZE',
'log_total_last_qua_assets': 'LogSalesTTM',
'log_sales_ttm': 'LogTotalLastQuaAssets'
}, inplace=True)
factor_scale_value = factor_scale_value[[
'symbol',
'MktValue',
'CirMktValue',
'SalesTTM',
'TotalAssets',
'LogofMktValue',
'LogofNegMktValue',
'NLSIZE',
'LogSalesTTM',
'LogTotalLastQuaAssets'
]]
factor_scale_value['id'] = factor_scale_value['symbol'] + str(trade_date)
factor_scale_value['trade_date'] = str(trade_date)
......
# coding=utf-8
from pandas.io.json import json_normalize, json
import pandas as pd
import numpy as np
from scipy import stats
import sys
......@@ -417,9 +417,63 @@ def calculate(**kwargs):
factor_list.append(symbol_calcu(tp_price))
factor_volatility_value = pd.DataFrame(factor_list)
factor_volatility_value.rename(columns={
'variance_20d': 'Variance20D', 'variance_60d': 'Variance60D', 'variance_120d': 'Variance120D',
'kurtosis_20d': 'Kurtosis20D', 'kurtosis_60d': 'Kurtosis60D', 'kurtosis_120d': 'Kurtosis120D',
'alpha_20d': 'Alpha20D', 'alpha_60d': 'Alpha60D', 'alpha_120d': 'Alpha120D',
'beta_20d': 'Beta20D', 'beta_60d': 'Beta60D', 'beta_120d': 'Beta120D',
'sharp_20d': 'Sharp20D', 'sharp_60d': 'Sharp60D', 'sharp_120d': 'Sharp120D',
'tr_20d': 'TR20D', 'tr_60d': 'TR60D', 'tr_120d': 'TR120D',
'ir_20d': 'IR20D', 'ir_60d': 'IR60D', 'ir_120d': 'IR120D',
'gain_variance_20d': 'GainVariance20D', 'gain_variance_60d': 'GainVariance60D',
'gain_variance_120d': 'GainVariance120D',
'loss_variance_20d': 'LossVariance20D', 'loss_variance_60d': 'LossVariance60D',
'loss_variance_120d': 'LossVariance120D',
'gain_loss_variance_ratio_20d': 'GainLossVarianceRatio20D',
'gain_loss_variance_ratio_60d': 'GainLossVarianceRatio60D',
'gain_loss_variance_ratio_120d': 'GainLossVarianceRatio120D',
'dastd_252d': 'DailyReturnSTD252D', 'ddnsr_12m': 'DDNSR12M', 'ddncr_12m': 'DDNCR12M', 'dvrat': 'DVRAT'
}, inplace=True)
factor_volatility_value = factor_volatility_value[[
'symbol',
'Variance20D',
'Variance60D',
'Variance120D',
'Kurtosis20D',
'Kurtosis60D',
'Kurtosis120D',
'Alpha20D',
'Alpha60D',
'Alpha120D',
'Beta20D',
'Beta60D',
'Beta120D',
'Sharp20D',
'Sharp60D',
'Sharp120D',
'TR20D',
'TR60D',
'TR120D',
'IR20D',
'IR60D',
'IR120D',
'GainVariance20D',
'GainVariance60D',
'GainVariance120D',
'LossVariance20D',
'LossVariance60D',
'LossVariance120D',
'GainLossVarianceRatio20D',
'GainLossVarianceRatio60D',
'GainLossVarianceRatio120D',
'DailyReturnSTD252D',
'DDNSR12M',
'DDNCR12M',
'DVRAT'
]]
factor_volatility_value['id'] = factor_volatility_value['symbol'] + str(trade_date)
factor_volatility_value['trade_date'] = str(trade_date)
# factor_price_momentum.set_index('symbol', inplace=True)
fb._storage_data(factor_volatility_value, trade_date)
# calculate(factor_name='volatility20180202', trade_date=20180202, session='1562216985610666')
......
......@@ -47,12 +47,8 @@ class HistoricalValue(FactorBase):
`PEG3YChgTTM` decimal(19,4),
`PEG5YChgTTM` decimal(19, 4),
`PBIndu` decimal(19,4),
`historical_value_lcap_latest` decimal(19,4),
`historical_value_lflo_latest` decimal(19,4),
`historical_value_nlsize_latest` decimal(19,4),
`PCFIndu` decimal(19,4),
`CEToPTTM` decimal(19,4),
`historical_value_ctop_latest` decimal(19,4),
PRIMARY KEY(`id`,`trade_date`,`symbol`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;""".format(self._name)
super(HistoricalValue, self)._create_tables(create_sql, drop_sql)
......@@ -346,12 +342,12 @@ def calculate(trade_date, valuation_sets, historical_value):
factor_historical_value = historical_value.peg_3y(valuation_sets, factor_historical_value)
factor_historical_value = historical_value.peg_5y(valuation_sets, factor_historical_value)
factor_historical_value = historical_value.pb_indu(valuation_sets, factor_historical_value)
factor_historical_value = historical_value.lcap(valuation_sets, factor_historical_value)
factor_historical_value = historical_value.lflo(factor_historical_value, factor_historical_value)
factor_historical_value = historical_value.nlsize(factor_historical_value, factor_historical_value)
# factor_historical_value = historical_value.lcap(valuation_sets, factor_historical_value)
# factor_historical_value = historical_value.lflo(factor_historical_value, factor_historical_value)
# factor_historical_value = historical_value.nlsize(factor_historical_value, factor_historical_value)
factor_historical_value = historical_value.pcf_indu(valuation_sets, factor_historical_value)
factor_historical_value = historical_value.cetop(factor_historical_value, factor_historical_value)
factor_historical_value = historical_value.ctop(valuation_sets, factor_historical_value)
# factor_historical_value = historical_value.ctop(valuation_sets, factor_historical_value)
# factor_historical_value = historical_value.ctop5(valuation_sets, factor_historical_value)
# etp5 因子没有提出, 使用该部分的时候, 数据库字段需要添加
......@@ -360,7 +356,8 @@ def calculate(trade_date, valuation_sets, historical_value):
# 'EarnToPrice',
# 'PEIndu', 'PEG3YChgTTM',
# 'PEG5YChgTTM', 'PBIndu',
# 'historical_value_lcap_latest','historical_value_lflo_latest',
# 'historical_value_lcap_latest',
# 'historical_value_lflo_latest',
# 'historical_value_nlsize_latest',
# 'PCFIndu',
# 'CEToPTTM',
......@@ -373,12 +370,9 @@ def calculate(trade_date, valuation_sets, historical_value):
'PEG3YChgTTM',
'PEG5YChgTTM',
'PBIndu',
'historical_value_lcap_latest',
'historical_value_lflo_latest',
'historical_value_nlsize_latest',
'PCFIndu',
'CEToPTTM',
'historical_value_ctop_latest']]
]]
factor_historical_value['id'] = factor_historical_value['symbol'] + str(trade_date)
factor_historical_value['trade_date'] = str(trade_date)
......
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