Esempio n. 1
0
    def __init__(self) -> None:
        """Constructor"""
        super().__init__()
        self.factor_data_manager: FactorDataManager = FactorDataManager()
        self.industry_data_manager: IndustryDataManager = IndustryDataManager()
        self.continuous_contract_data_manager: ContinuousContractDataManager = ContinuousContractDataManager(
        )
        self.factor_test_result_path: Path = Path(
            __file__).parent.parent.joinpath("output_result")

        self.factor_info: Dict[str, str] = {}
        self.factor: BaseFactor = None
        self.factor_params: Dict[str, Any] = {}
Esempio n. 2
0
    def __init__(self, **params) -> None:
        """Constructor"""
        super().__init__(**params)

        self.group: str = Path(inspect.getfile(self.__class__)).parent.name
        self.name: str = self.__class__.__name__

        self.daily_data_manager: DailyDataManager = DailyDataManager()
        self.basics_data_manager: BasicsDataManager = BasicsDataManager()
        self.continuous_contract_data_manager: ContinuousContractDataManager = ContinuousContractDataManager(
        )

        self.daily_volume: DataFrame = None
        self.listed_date_df: DataFrame = None
        self.all_instruments: DataFrame = None
        self.commodity_pool_value: DataFrame = None
Esempio n. 3
0
    def __init__(self, file_path: str) -> None:
        """Constructor"""
        self.file_path: Path = Path(file_path)

        self.factor_name: str = None
        self.factor_data: DataFrame = None
        self.factor_data_with_pool: DataFrame = None

        self.commodity_pool: DataFrame = None

        self.long_short_quantile_func: Callable = None

        self.quantile1: Series = None
        self.quantile2: Series = None

        self.continuous_contract_data_manager: ContinuousContractDataManager = ContinuousContractDataManager()

        # 如果不存在因子绩效保存路径,则需要先创建
        self.init_file_path()
Esempio n. 4
0
    def __init__(self, **params) -> None:
        """Constructor"""
        super().__init__(**params)

        self.group: str = Path(inspect.getfile(self.__class__)).parent.name
        self.name: str = self.__class__.__name__

        self.all_instruments: DataFrame = None
        self.symbol_industry_map: DataFrame = None

        self.daily_data_manager: DailyDataManager = DailyDataManager()
        self.basics_data_manager: BasicsDataManager = BasicsDataManager()
        self.continuous_contract_data_manager: ContinuousContractDataManager = ContinuousContractDataManager(
        )

        self.maturity_date_dict: Dict[str, DataFrame] = {}

        self.factor_value: DataFrame = None
        self.init_basics_data()
Esempio n. 5
0
## 导入库
import pandas as pd
from data_manager.DailyDataManager import DailyDataManager
from data_manager.ContinuousContractDataManager import ContinuousContractDataManager

## 导入数据
volume_df = DailyDataManager().daily_data.groupby(
    ['datetime', 'underlying_symbol'])['volume'].sum().unstack(level=-1)
price_df = ContinuousContractDataManager().get_field(field='continuous_price')

## 检查index和columns是否完全相等
print("index is equal: ", volume_df.index.equals(price_df.index))
print("columns is equal: ", volume_df.columns.equals(price_df.columns))

## 检查volume_df有数据的位置price_df是否一定有数据
check1_df = pd.DataFrame(data=False,
                         index=volume_df.index,
                         columns=volume_df.columns)
check1_df[(volume_df.notnull()) & (price_df.isnull())] = True
print(check1_df.astype(int).sum().sum())

check1_series = check1_df.sum()
check1_series[check1_series == 1]

check1_df.loc[check1_df == True, 'LR']

from datetime import datetime
price_df.loc[datetime(2020, 7, 15), 'LR']
# price_df.loc[datetime(2020, 7,15), 'LR'] = price_df.loc[datetime(2020,7,14), 'LR']

## 检查price_df有数据的位置volume_df一定有数据
Esempio n. 6
0
import pandas as pd
import matplotlib.pyplot as plt
from data_manager.BasicsDataManager import BasicsDataManager
from data_manager.ContinuousContractDataManager import ContinuousContractDataManager

symbol_list = BasicsDataManager().get_symbol_list()
self = ContinuousContractDataManager()

data_list = []
contract = 'main'
for price in ['close', 'settlement']:
    for rebalance_num in [1, 3, 5]:
        df = self.get_continuous_contract_data(contract=contract, price=price, rebalance_num=rebalance_num)
        df = df[['datetime', 'underlying_symbol', 'continuous_price']]
        df['contract'] = contract
        df['price'] = price
        df['rebalance_num'] = rebalance_num
        data_list.append(df)

data = pd.concat(data_list, axis=0)

for symbol in symbol_list:
    df = data[data.underlying_symbol == symbol]
    plt.figure()
    df.groupby(['price', 'rebalance_num'])['continuous_price'].plot(legend=True)
    plt.savefig(f"C:/Users/qtg_i/Desktop/LFNotes/笔记/期货连续合约/主力连续合约/主力连续合约对比/{symbol}.png")
    plt.show()

import os
import pandas as pd
folder_path = "D:/LFProjects/NewPythonProject/data/continuous_contract_series"
    def __init__(self) -> None:
        """"""
        self.index_data_path: Path = Path(__file__).parent.parent.joinpath("data").joinpath("index")

        self.industry_data_manager: IndustryDataManager = IndustryDataManager()
        self.continuous_contract_data_manager: ContinuousContractDataManager = ContinuousContractDataManager()
from data_manager.ContinuousContractDataManager import ContinuousContractDataManager

from correlation_analysis.analysis import get_industry_correlation_result, get_period_industry_correlation_result
##
# 导入代码名称列表
all_instruments: DataFrame = BasicsDataManager().get_all_instruments()[[
    'underlying_symbol', 'symbol', 'industry_name'
]]
all_instruments['name'] = all_instruments['symbol'].str.extract(r"([^0-9]+)")
all_instruments = all_instruments[['underlying_symbol',
                                   'name']].drop_duplicates()
symbol_name_map: Dict[str, str] = all_instruments.set_index(
    'underlying_symbol')['name'].to_dict()
##
# 导入连续合约数据
price_df: DataFrame = ContinuousContractDataManager().get_field(
    field='continuous_price')
return_df = ContinuousContractDataManager().get_field(field='return')

##
# 导入行业数据
industry_data_manager = IndustryDataManager()
industry_data_manager.get_all_industry_symbol_maps()

# 从行业数据中导出谷物的组
arg_groups = {}
arg_groups[
    'Huatai_industry_map'] = industry_data_manager.get_industry_symbol_map(
        group='original_industry', name='Huatai_industry_map')['谷物']
arg_groups['RQ_industry_map'] = industry_data_manager.get_industry_symbol_map(
    group='original_industry', name='RQ_industry_map')['谷物']
##