Exemplo n.º 1
0
class Summary():

    def __init__(self, filename='stocks.txt', **kwargs):
        self.c_dir = os.path.dirname(os.path.abspath(__file__))
        self.base_dir = os.path.join(self.c_dir, '..')
        self.data_dir = os.path.join(self.base_dir, 'data')
        self.stock_list = os.path.join(self.data_dir,
                                       filename)
        self.aggregator = Aggregator(self.stock_list, self.data_dir)

    def aggregate(self,
                  filename="stocks.txt",
                  range=1,
                  sortkey='Ratio',
                  screening_key=None,
                  ascending=False,
                  history=False):
        result = self.aggregator.summarize(range=range,
                                           screening_key=screening_key,
                                           sortkey=sortkey,
                                           ascending=ascending)
        p = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), '..', 'data',
            filename)
        result.to_csv(p, sep="\t", index_label="Code")

        if history:
            today = datetime.datetime.now().strftime('%Y%m%d')
            p = os.path.join(
                os.path.dirname(os.path.abspath(__file__)), '..', 'data',
                'history', "".join([filename, '.', today, '.csv']))
            result.to_csv(p, sep="\t", index_label="Code")
Exemplo n.º 2
0
class Summary():
    def __init__(self, filename='stocks.txt', **kwargs):
        self.c_dir = os.path.dirname(os.path.abspath(__file__))
        self.base_dir = os.path.join(self.c_dir, '..')
        self.data_dir = os.path.join(self.base_dir, 'data')
        self.stock_list = os.path.join(self.data_dir, filename)
        self.aggregator = Aggregator(self.stock_list, self.data_dir)

    def aggregate(self,
                  filename="stocks.txt",
                  range=1,
                  sortkey='Ratio',
                  screening_key=None,
                  ascending=False,
                  history=False):
        result = self.aggregator.summarize(range=range,
                                           screening_key=screening_key,
                                           sortkey=sortkey,
                                           ascending=ascending)
        p = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                         'data', filename)
        result.to_csv(p, sep="\t", index_label="Code")

        if history:
            today = datetime.datetime.now().strftime('%Y%m%d')
            p = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                             'data', 'history',
                             "".join([filename, '.', today, '.csv']))
            result.to_csv(p, sep="\t", index_label="Code")
Exemplo n.º 3
0
def test_summarize():
    c_dir = os.path.dirname(os.path.abspath(__file__))
    base_dir = os.path.join(c_dir, '..')
    stock_list = os.path.join(base_dir, 'data', 'stocks.txt')
    data_dir = os.path.join(base_dir, 'test')
    aggregator = Aggregator(stock_list, data_dir)
    result = aggregator.summarize()

    eq_('stocks.txt', os.path.basename(aggregator.stock_list))
    eq_('test', os.path.basename(aggregator.data_dir))

    eq_(True, result.empty)
    return result
Exemplo n.º 4
0
def test_summarize():
    c_dir = os.path.dirname(os.path.abspath(__file__))
    base_dir = os.path.join(c_dir, '..')
    stock_list = os.path.join(base_dir, 'data',
                              'stocks.txt')
    data_dir = os.path.join(base_dir, 'test')
    aggregator = Aggregator(stock_list, data_dir)
    result = aggregator.summarize()

    eq_('stocks.txt', os.path.basename(aggregator.stock_list))
    eq_('test', os.path.basename(aggregator.data_dir))

    eq_(True, result.empty)
    return result