Exemplo n.º 1
0
def construct_binary_frame(data_sets, method, token, start, end, years_per_block, isamples):
    """
    This method is used to construct a BinaryFrame object from a meta-data file which specifies what data sets we want
    to download and what columns we are interested in from that data.
    :param data_sets: the file containing the data sets we want
    :param method: the method of conversion to binary
    :param token: a Quandl authentication token
    :param start: the start date
    :param end: the end date
    :param years_per_block: the time frame / dimension we want to look at
    :return: a BinaryFrame object which can work with the RandomnessTester class
    """
    downloader = QuandlInterface(token)
    data_file = pandas.read_csv(data_sets)
    data_sets = list(data_file["ID"])
    drop_columns = list(data_file["DROP"])
    data_prefix = ""
    transform = "rdiff"
    start_date = str(start) + "-01-01"
    end_date = str(end) + "-01-01"
    my_arguments = []
    for i in range(len(data_sets)):
        drop = drop_columns[i].split("#")
        if drop == "":
            drop = []
        my_arguments.append(Argument(data_sets[i], start_date, end_date, data_prefix, drop, transform))
    data_frame_full = downloader.get_data_sets(my_arguments)
    binary_frame = BinaryFrame(data_frame_full, start, end, years_per_block)
    binary_frame.convert(method, independent_samples=isamples)
    return binary_frame
Exemplo n.º 2
0
def construct_binary_frame(data_sets, method, token, start, end,
                           years_per_block, isamples):
    """
    This method is used to construct a BinaryFrame object from a meta-data file which specifies what data sets we want
    to download and what columns we are interested in from that data.
    :param data_sets: the file containing the data sets we want
    :param method: the method of conversion to binary
    :param token: a Quandl authentication token
    :param start: the start date
    :param end: the end date
    :param years_per_block: the time frame / dimension we want to look at
    :return: a BinaryFrame object which can work with the RandomnessTester class
    """
    downloader = QuandlInterface(token)
    data_file = pandas.read_csv(data_sets)
    data_sets = list(data_file["ID"])
    drop_columns = list(data_file["DROP"])
    data_prefix = ""
    transform = "rdiff"
    start_date = str(start) + "-01-01"
    end_date = str(end) + "-01-01"
    my_arguments = []
    for i in range(len(data_sets)):
        drop = drop_columns[i].split('#')
        if drop == "":
            drop = []
        my_arguments.append(
            Argument(data_sets[i], start_date, end_date, data_prefix, drop,
                     transform))
    data_frame_full = downloader.get_data_sets(my_arguments)
    binary_frame = BinaryFrame(data_frame_full, start, end, years_per_block)
    binary_frame.convert(method, independent_samples=isamples)
    return binary_frame
Exemplo n.º 3
0
def construct_binary_frame(data_sets, method, start, end, years_per_block, isamples):
    """
     此函数用于将原始价格数据转化为 BinaryFrame 对象
    :param data_sets: 数据文件
    :param method: 转二元向量的方法
    :param start: 起始日期
    :param end: 终止日期
    :param years_per_block: 使用的时间窗口
    :return: 可用于 RandomnessTester 类的BinaryFrame对象
    """
    data_frame_full = pandas.read_excel(io=data_sets)
    data_frame_full['date'] = pandas.to_datetime(data_frame_full['date'])
    data_frame_full.set_index("date", inplace=True)   
    binary_frame = BinaryFrame(data_frame_full, start, end, years_per_block)
    binary_frame.convert(method, independent_samples=isamples)
    return binary_frame
Exemplo n.º 4
0
def run_experiments(data_sets, block_sizes, q_sizes, method, start, end, years_per_block, isamples=False):
    """
    :param data_sets: 数据文件
    :param block_sizes: 块大小
    :param q_sizes: 矩阵大小
    :param start: 起始日期
    :param end: 终止日期
    :param methods: 转二元向量的方法
    :param years_per_block: 使用的时间窗口
    :return: 无
    """
    print("\n")
    print("METHOD =", method.upper())

    length = 256 * (end - start)
    gen = Generators(length)
    prng = gen.numpy_integer()

    all_passed = []
    prng_data = pandas.DataFrame(numpy.array(prng))
    prng_data.columns = ["Mersenne"]
    prng_binary_frame = BinaryFrame(prng_data, start, end, years_per_block)
    prng_binary_frame.convert(method, convert=False, independent_samples=isamples)
    rng_tester = RandomnessTester(prng_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    nrand = numpy.empty(length)
    for i in range(length):
        nrand[i] = (i % 10) / 10
    nrand -= numpy.mean(nrand)
    nrand_data = pandas.DataFrame(numpy.array(nrand))
    nrand_data.columns = ["Deterministic"]
    nrand_binary_frame = BinaryFrame(nrand_data, start, end, years_per_block)
    nrand_binary_frame.convert(method, convert=True, independent_samples=isamples)
    rng_tester = RandomnessTester(nrand_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)
    my_binary_frame = construct_binary_frame(data_sets, method, start, end, years_per_block, isamples)
    rng_tester = RandomnessTester(my_binary_frame, True, start, end)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    print("\n")
    return all_passed
Exemplo n.º 5
0
def run_experiments(data_sets, block_sizes, q_sizes, method, start, end, years_per_block, isamples=False):
    """
    This method just runs the experiments which were used to write the blog post
    :param data_sets: the file containing a list of data sets we want
    :param block_sizes: a list of block sizes
    :param q_sizes: a list of matrix sizes
    :param start: the start date
    :param end: the end date
    :param methods: the methods of conversion to binary we want to test
    :param years_per_block: the time frame / dimension we want to look at
    :return: nothing just prints out stuff
    """
    print("\n")
    print("METHOD =", method.upper())

    length = 256 * (end - start)
    gen = Generators(length)
    prng = gen.numpy_integer()

    all_passed = []
    prng_data = pandas.DataFrame(numpy.array(prng))
    prng_data.columns = ["Mersenne"]
    prng_binary_frame = BinaryFrame(prng_data, start, end, years_per_block)
    prng_binary_frame.convert(method, convert=False, independent_samples=isamples)
    # method, real_data, start_year, end_year, block_size
    rng_tester = RandomnessTester(prng_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    nrand = numpy.empty(length)
    for i in range(length):
        nrand[i] = (i % 10) / 10
    nrand -= numpy.mean(nrand)
    nrand_data = pandas.DataFrame(numpy.array(nrand))
    nrand_data.columns = ["Deterministic"]
    nrand_binary_frame = BinaryFrame(nrand_data, start, end, years_per_block)
    nrand_binary_frame.convert(method, convert=True, independent_samples=isamples)
    rng_tester = RandomnessTester(nrand_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    t = setup_environment()
    my_binary_frame = construct_binary_frame(data_sets, method, t, start, end, years_per_block, isamples)
    rng_tester = RandomnessTester(my_binary_frame, True, start, end)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    print("\n")
    return all_passed
Exemplo n.º 6
0
def run_experiments(data_sets,
                    block_sizes,
                    q_sizes,
                    method,
                    start,
                    end,
                    years_per_block,
                    isamples=False):
    """
    This method just runs the experiments which were used to write the blog post
    :param data_sets: the file containing a list of data sets we want
    :param block_sizes: a list of block sizes
    :param q_sizes: a list of matrix sizes
    :param start: the start date
    :param end: the end date
    :param methods: the methods of conversion to binary we want to test
    :param years_per_block: the time frame / dimension we want to look at
    :return: nothing just prints out stuff
    """
    print("\n")
    print("METHOD =", method.upper())

    length = 256 * (end - start)
    gen = Generators(length)
    prng = gen.numpy_integer()

    all_passed = []
    prng_data = pandas.DataFrame(numpy.array(prng))
    prng_data.columns = ["Mersenne"]
    prng_binary_frame = BinaryFrame(prng_data, start, end, years_per_block)
    prng_binary_frame.convert(method,
                              convert=False,
                              independent_samples=isamples)
    # method, real_data, start_year, end_year, block_size
    rng_tester = RandomnessTester(prng_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    nrand = numpy.empty(length)
    for i in range(length):
        nrand[i] = (i % 10) / 10
    nrand -= numpy.mean(nrand)
    nrand_data = pandas.DataFrame(numpy.array(nrand))
    nrand_data.columns = ["Deterministic"]
    nrand_binary_frame = BinaryFrame(nrand_data, start, end, years_per_block)
    nrand_binary_frame.convert(method,
                               convert=True,
                               independent_samples=isamples)
    rng_tester = RandomnessTester(nrand_binary_frame, False, 00, 00)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    t = setup_environment()
    my_binary_frame = construct_binary_frame(data_sets, method, t, start, end,
                                             years_per_block, isamples)
    rng_tester = RandomnessTester(my_binary_frame, True, start, end)
    passed = rng_tester.run_test_suite(block_sizes, q_sizes)
    for x in passed:
        all_passed.append(x)

    print("\n")
    return all_passed