Пример #1
0
def init_arctic_with_csv_futures_contract_prices_for_code(
    instrument_code: str, datapath: str, csv_config=arg_not_supplied
):
    print(instrument_code)
    csv_prices = csvFuturesContractPriceData(datapath, config=csv_config)
    arctic_prices = arcticFuturesContractPriceData()

    print("Getting .csv prices may take some time")
    csv_price_dict = csv_prices.get_all_prices_for_instrument(instrument_code)

    print("Have .csv prices for the following contracts:")
    print(str(csv_price_dict.keys()))

    for contract_date_str, prices_for_contract in csv_price_dict.items():
        print("Processing %s" % contract_date_str)
        print(".csv prices are \n %s" % str(prices_for_contract))
        contract = futuresContract(instrument_code, contract_date_str)
        print("Contract object is %s" % str(contract))
        print("Writing to arctic")
        arctic_prices.write_prices_for_contract_object(
            contract, prices_for_contract, ignore_duplication=True
        )
        print("Reading back prices from arctic to check")
        written_prices = arctic_prices.get_prices_for_contract_object(contract)
        print("Read back prices are \n %s" % str(written_prices))
    def test_check_saved_roll_calendar(self):
        """
        Tests the function that checks a roll calendar generated from individual contract prices
        """
        sample_prices = csvFuturesContractPriceData(
            datapath="sysinit.futures.tests.price", config=self.csv_config)

        check_saved_roll_calendar(
            "AUD",
            input_datapath="sysinit.futures.tests.roll_cal",
            input_prices=sample_prices,
        )
Пример #3
0
def init_arctic_with_csv_futures_contract_prices(datapath: str):
    csv_prices = csvFuturesContractPriceData(datapath)
    input(
        "WARNING THIS WILL ERASE ANY EXISTING ARCTIC PRICES WITH DATA FROM %s ARE YOU SURE?! (CTRL-C TO STOP)"
        % csv_prices.datapath)

    instrument_codes = csv_prices.get_list_of_instrument_codes_with_price_data(
    )
    instrument_codes.sort()
    for instrument_code in instrument_codes:
        init_arctic_with_csv_futures_contract_prices_for_code(
            instrument_code, datapath)
Пример #4
0
    def test_check_saved_roll_calendar(self):
        """
        Tests the function that checks a roll calendar generated from individual contract prices

        *** FAILING TEST: once the function is working the annotation can be removed ***
        """
        sample_prices = csvFuturesContractPriceData(
            datapath='sysinit.futures.tests.price', config=self.csv_config)

        check_saved_roll_calendar(
            'AUD',
            input_datapath='sysinit.futures.tests.roll_cal',
            input_prices=sample_prices)
Пример #5
0
def init_arctic_with_csv_futures_contract_prices_for_code(
        instrument_code: str, datapath: str, csv_config=arg_not_supplied):
    print(instrument_code)
    csv_prices = csvFuturesContractPriceData(datapath, config=csv_config)
    arctic_prices = arcticFuturesContractPriceData()

    print("Getting .csv prices may take some time")
    csv_price_dict = csv_prices.get_all_prices_for_instrument(instrument_code)

    for contract_date_str, prices_for_contract in csv_price_dict.items():
        print(contract_date_str)
        contract = futuresContract(instrument_code, contract_date_str)
        arctic_prices.write_prices_for_contract_object(contract,
                                                       prices_for_contract,
                                                       ignore_duplication=True)
Пример #6
0
    def test_build_roll_calendar(self, tmp_path, monkeypatch):
        """
        Tests the function that builds roll calendars from individual contract prices. Mocks user input
        and writes output to temp file
        """

        monkeypatch.setattr('builtins.input', lambda _: "AUD")

        sample_prices = csvFuturesContractPriceData(
            datapath='sysinit.futures.tests.price', config=self.csv_config)
        output_dir = tmp_path / 'output'

        build_and_write_roll_calendar('AUD',
                                      output_datapath=output_dir,
                                      input_prices=sample_prices,
                                      input_config=csvRollParametersData())
    def test_build_roll_calendar(self, tmp_path, monkeypatch):
        """
        Tests the function that builds roll calendars from individual contract prices. Mocks user input
        and writes output to temp file
        """

        monkeypatch.setattr("builtins.input", lambda _: "AUD")

        sample_prices = csvFuturesContractPriceData(
            datapath="sysinit.futures.tests.price", config=self.csv_config)
        output_dir = str(tmp_path)

        build_and_write_roll_calendar(
            "AUD",
            output_datapath=output_dir,
            input_prices=sample_prices,
            input_config=csvRollParametersData(),
            check_before_writing=False,
        )