Ejemplo n.º 1
0
 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]
Ejemplo n.º 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))

    def test_weighted_ret(self):
        print(self.db.weighted_return(date=self.end_date, ids=self.ids))
        print(self.db.weighted_return(date=self.end_date, ids=self.ids, pre_date=self.start_date))
        print(self.db.weighted_return(date=self.end_date, ids=self.ids, weight_base=self.db.free_floating_share))
Ejemplo n.º 3
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'))
Ejemplo n.º 4
0
 def setUp(self) -> None:
     config_loc = 'config.json'
     engine = prepare_engine(config_loc)
     self.db = AShareDataReader(MySQLInterface(engine))
Ejemplo n.º 5
0
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        config_loc = 'config.json'
        engine = prepare_engine(config_loc)
        self.db = AShareDataReader(MySQLInterface(engine))

    def test_warned_stocks(self):
        start_date = dt.date(2010, 1, 8)
        end_date = dt.date(2019, 12, 27)
        self.db.risk_warned_stocks(start_date=start_date, end_date=end_date)

    def test_pause_stocks(self):
        start_date = dt.date(2010, 1, 8)
        end_date = dt.date(2019, 12, 27)
        self.db.paused_stocks(start_date=start_date, end_date=end_date)

    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(start_date=start_date,
                               end_date=end_date,
                               ids=ids))
        print(self.db.adj_factor(start_date=start_date, ids=ids))
        print(self.db.adj_factor(end_date=end_date, ids=ids))
        print(self.db.adj_factor(dates=dates, ids=ids))

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

    def test_get_factor(self):
        factor_name = '证券名称'
        table_name = '股票曾用名'
        print(self.db.get_factor(table_name, factor_name).tail())

    def test_get_financial_factor(self):
        self.fail()

    def test_industry(self):
        print(self.db.get_industry('中信', 3).tail())
        print(self.db.get_industry('中证', 3).tail())

    def test_snapshot(self):
        factor_name = '证券名称'
        table_name = '股票曾用名'
        print(self.db.get_snapshot(table_name, factor_name))

    def test_industry_snapshot(self):
        print(self.db.get_industry_snapshot('中信', 3))
        print(self.db.get_industry_snapshot('中证', 3))

    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('000300.SH', '20201130'))
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
 def setUp(self) -> None:
     set_global_config('config.json')
     self.db = AShareDataReader()