Пример #1
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        set_global_config('config.json')
        self.db = AShareDataReader()

    def test_calendar(self):
        print(self.db.calendar.calendar)

    def test_adj_factor(self):
        start_date = dt.date(2018, 5, 10)
        end_date = dt.date(2018, 7, 10)
        dates = [start_date, end_date]
        ids = ['000001.SZ', '600000.SH', '000002.SZ']
        print(
            self.db.adj_factor.get_data(start_date=start_date,
                                        end_date=end_date,
                                        ids=ids))
        print(self.db.adj_factor.get_data(start_date=start_date, ids=ids))
        print(self.db.adj_factor.get_data(end_date=end_date, ids=ids))
        print(self.db.adj_factor.get_data(dates=dates, ids=ids))

    def test_stocks(self):
        print(self.db.stocks)

    def test_get_sec_name(self):
        start_date = dt.date(2018, 5, 10)
        print(self.db.sec_name.get_data(dates=[start_date]))

    def test_get_financial_factor(self):
        self.fail()

    def test_industry(self):
        start_date = dt.date(2018, 5, 10)
        print(self.db.industry('中信', 3).get_data(dates=[start_date]))
        print(self.db.industry('中证', 3).get_data(dates=[start_date]))

    #
    # def test_financial_query(self):
    #     print(self.db.query_financial_statements('资产负债表', '资产总计', '20181231'))
    #
    # def test_financial_snapshot(self):
    #     print(self.db.get_financial_snapshot('资产负债表', '资产总计', yearly=True))
    #     print(self.db.get_financial_snapshot('资产负债表', '资产总计', quarterly=True))

    def test_index_constitute(self):
        print(self.db.index_constitute.get_data('000300.SH', '20201130'))
Пример #2
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        set_global_config('config.json')
        self.db = AShareDataReader()
        self.start_date = dt.datetime(2018, 5, 10)
        self.end_date = dt.datetime(2018, 7, 10)
        self.ids = ['000001.SZ', '600000.SH', '000002.SZ']
        self.dates = [self.start_date, self.end_date]

    def test_calendar(self):
        print(self.db.calendar.calendar)

    def test_adj_factor(self):
        print(
            self.db.adj_factor.get_data(start_date=self.start_date,
                                        end_date=self.end_date,
                                        ids=self.ids))
        print(
            self.db.adj_factor.get_data(start_date=self.start_date,
                                        ids=self.ids))
        print(self.db.adj_factor.get_data(end_date=self.end_date,
                                          ids=self.ids))
        print(self.db.adj_factor.get_data(dates=self.dates, ids=self.ids))

    def test_stocks(self):
        print(self.db.stocks)

    def test_get_sec_name(self):
        start_date = dt.date(2018, 5, 10)
        print(self.db.sec_name.get_data(dates=[start_date]))

    def test_industry(self):
        start_date = dt.date(2018, 5, 10)
        print(self.db.industry('中信', 3).get_data(dates=[start_date]))
        print(self.db.industry('中证', 3).get_data(dates=[start_date]))

    def test_index_constitute(self):
        print(self.db.index_constitute.get_data('000300.SH', '20201130'))

    def test_pe_ttm(self):
        print(self.db.earning_ttm.get_data(dates=self.dates, ids=self.ids))
        print(self.db.stock_market_cap.get_data(dates=self.dates,
                                                ids=self.ids))
        print(self.db.pe_ttm.get_data(dates=self.dates, ids=self.ids))
Пример #3
0
import datetime as dt
import sys

from AShareData.AShareDataReader import AShareDataReader
from AShareData.config import set_global_config
from AShareData.FactorCompositor import FactorPortfolio, FactorPortfolioPolicy
from AShareData.utils import StockSelectionPolicy

if __name__ == '__main__':
    set_global_config(sys.argv[1])

    data_reader = AShareDataReader()
    stock_selection_policy = StockSelectionPolicy()
    stock_selection_policy.ignore_new_stock_period = 360
    stock_selection_policy.ignore_st = True
    stock_selection_policy.ignore_pause = True

    policy = FactorPortfolioPolicy()
    policy.bins = [5, 10]
    policy.stock_selection_policy = stock_selection_policy
    policy.start_date = dt.datetime(2010, 1, 1)
    policy.industry = data_reader.industry('申万', 1)
    policy.weight = data_reader.stock_free_floating_market_cap

    policy.name = data_reader.beta.factor_name
    policy.factor = data_reader.beta

    sub_port = FactorPortfolio(factor_portfolio_policy=policy)
    sub_port.update()