Esempio n. 1
0
 def setUp(self) -> None:
     set_global_config('config.json')
     self.target = ContinuousFactor('自合成指数', '收益率')
     self.target.bind_params(ids='ST.IND')
     self.benchmark = ContinuousFactor('自合成指数', '收益率')
     self.benchmark.bind_params(ids='全市场.IND')
     self.start = dt.datetime(2012, 1, 1)
     self.end = dt.datetime(2020, 1, 1)
Esempio n. 2
0
 def test_plot_index(self):
     index_factor = ContinuousFactor('自合成指数', '收益率')
     index_factor.bind_params(ids='ST.IND')
     benchmark_factor = ContinuousFactor('自合成指数', '收益率')
     benchmark_factor.bind_params(ids='全市场.IND')
     start_date = None
     end_date = None
     ids = 'ST.IND'
     plot_index(index_factor)
     plot_index(index_factor, benchmark_factor=benchmark_factor)
Esempio n. 3
0
 def __init__(self,
              date: dt.datetime = None,
              db_interface: DBInterface = None):
     self.db_interface = db_interface if db_interface else get_db_interface(
     )
     self.calendar = TradingCalendar(self.db_interface)
     if date is None:
         date = dt.datetime.combine(dt.date.today(), dt.time())
     self.date = date
     records = utils.load_excel('自编指数配置.xlsx')
     self.tickers = [it['ticker'] for it in records]
     self.tbd_indexes = list(
         set(self.tickers) - set(self.must_keep_indexes))
     start_date = self.calendar.offset(date, -22)
     index_factor = ContinuousFactor('自合成指数',
                                     '收益率',
                                     db_interface=self.db_interface)
     self.cache = index_factor.get_data(start_date=start_date,
                                        end_date=date).unstack()
     self.industry_cache = []
Esempio n. 4
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        set_global_config('config.json')
        self.target = ContinuousFactor('自合成指数', '收益率')
        self.target.bind_params(ids='ST.IND')
        self.benchmark = ContinuousFactor('自合成指数', '收益率')
        self.benchmark.bind_params(ids='全市场.IND')
        self.start = dt.datetime(2012, 1, 1)
        self.end = dt.datetime(2020, 1, 1)

    def test_max_drawdown(self):
        returns = self.target.get_data(start_date=self.start, end_date=self.end).unstack().iloc[:, 0]
        print(locate_max_drawdown(returns))
        returns = self.benchmark.get_data().unstack().iloc[:, 0]
        print(locate_max_drawdown(returns))

    def test_aggregate_return(self):
        print(aggregate_returns(target=self.target, convert_to='monthly', benchmark_factor=self.benchmark))
Esempio n. 5
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        set_global_config('config.json')
        self.target = ContinuousFactor('自合成指数', '收益率')
        self.target.bind_params(ids='ST.IND')
        self.benchmark = ContinuousFactor('自合成指数', '收益率')
        self.benchmark.bind_params(ids='全市场.IND')
        self.start = dt.datetime(2012, 1, 1)
        self.end = dt.datetime(2020, 1, 1)

    def test_max_drawdown(self):
        returns = self.target.get_data(start_date=self.start,
                                       end_date=self.end).unstack().iloc[:, 0]
        print(locate_max_drawdown(returns))
        returns = self.benchmark.get_data().unstack().iloc[:, 0]
        print(locate_max_drawdown(returns))

    def test_aggregate_return(self):
        print(
            aggregate_returns(target=self.target,
                              convert_to='monthly',
                              benchmark_factor=self.benchmark))

    @staticmethod
    def test_holding():
        h = FundHolding()
        date = dt.datetime(2021, 3, 8)
        print(h.get_holding(date))
        print(h.get_holding(date, fund='指增1号 - 东财 - 普通户'))
        print(h.get_holding(date, fund='ALL'))

    def test_fund_nav_analysis(self):
        fund_nav_analysis = FundNAVAnalysis('110011.OF')
        fund_nav_analysis.compute_correlation('399006.SZ')
        model = FamaFrench3FactorModel()
        fund_nav_analysis.compute_exposure(model)
        fund_nav_analysis.get_latest_published_portfolio_holding()

    def test_public_fund_holding(self):
        ticker = '000001.SZ'
        date = dt.datetime(2020, 12, 31)
        rec = PublicFundHoldingRecords(ticker, date)
        self = rec