def get_roll_data_for_instrument(instrument_code, data): """ Get roll data for an individual instrument :param instrument_code: str :param data: dataBlob :return: """ c_data = diagContracts(data) relevant_contract_dict = c_data.get_labelled_list_of_relevant_contracts( instrument_code) relevant_contracts = relevant_contract_dict['contracts'] contract_labels = relevant_contract_dict['labels'] current_contracts = relevant_contract_dict['current_contracts'] v_data = diagVolumes(data) volumes = v_data.get_normalised_smoothed_volumes_of_contract_list( instrument_code, relevant_contracts) # price curve p_data = diagPrices(data) contracts_to_match = [current_contracts[k] for k in ('PRICE', 'FORWARD')] last_matched_prices = p_data.get_last_matched_prices_for_contract_list( instrument_code, relevant_contracts, contracts_to_match=contracts_to_match) # length to expiries / length to suggested roll price_expiry = c_data.get_priced_expiry(instrument_code) carry_expiry = c_data.get_carry_expiry(instrument_code) when_to_roll = c_data.when_to_roll_priced_contract(instrument_code) now = datetime.datetime.now() price_expiry_days = (price_expiry - now).days carry_expiry_days = (carry_expiry - now).days when_to_roll_days = (when_to_roll - now).days # roll status s_data = diagPositions(data) roll_status = s_data.get_roll_state(instrument_code) # Positions positions = s_data.get_positions_for_instrument_and_contract_list( instrument_code, relevant_contracts) results_dict_code = dict(code=instrument_code, status=roll_status, roll_expiry=when_to_roll_days, price_expiry=price_expiry_days, carry_expiry=carry_expiry_days, contract_labels=contract_labels, volumes=volumes, curve=last_matched_prices, positions=positions) return results_dict_code
def relative_volume_in_forward_contract_and_price( data: dataBlob, instrument_code: str) -> list: c_data = dataContracts(data) forward_contract_id = c_data.get_forward_contract_id(instrument_code) current_contract = c_data.get_priced_contract_id(instrument_code) v_data = diagVolumes(data) volumes = v_data.get_normalised_smoothed_volumes_of_contract_list( instrument_code, [current_contract, forward_contract_id]) return volumes
def get_roll_data_for_instrument(instrument_code, data): """ Get roll data for an individual instrument :param instrument_code: str :param data: dataBlob :return: """ c_data = diagContracts(data) relevant_contract_dict = c_data.get_labelled_list_of_relevant_contracts( instrument_code) list_of_relevant_contract_date_str = relevant_contract_dict["contracts"] contract_labels = relevant_contract_dict["labels"] current_contracts = relevant_contract_dict["current_contracts"] v_data = diagVolumes(data) volumes = v_data.get_normalised_smoothed_volumes_of_contract_list( instrument_code, list_of_relevant_contract_date_str) # length to expiries / length to suggested roll price_expiry = c_data.get_priced_expiry(instrument_code) carry_expiry = c_data.get_carry_expiry(instrument_code) when_to_roll = c_data.when_to_roll_priced_contract(instrument_code) now = datetime.datetime.now() price_expiry_days = (price_expiry - now).days carry_expiry_days = (carry_expiry - now).days when_to_roll_days = (when_to_roll - now).days # roll status diag_positions = diagPositions(data) roll_status = diag_positions.get_name_of_roll_state(instrument_code) # Positions positions = diag_positions.get_positions_for_instrument_and_contract_list( instrument_code, list_of_relevant_contract_date_str) results_dict_code = dict( code=instrument_code, status=roll_status, roll_expiry=when_to_roll_days, price_expiry=price_expiry_days, carry_expiry=carry_expiry_days, contract_labels=contract_labels, volumes=volumes, positions=positions, ) return results_dict_code