def _get_multiple_prices_without_checking( self, instrument_code: str) -> futuresMultiplePrices: instr_all_price_data = self._read_instrument_prices(instrument_code) for contract_col_name in list_of_contract_column_names: instr_all_price_data[contract_col_name] = instr_all_price_data[ contract_col_name].apply(str_of_int) return futuresMultiplePrices(instr_all_price_data)
def update_multiple_prices_on_roll( data: dataBlob, current_multiple_prices: futuresMultiplePrices, instrument_code: str, allow_forward_fill: bool = False) -> futuresMultiplePrices: """ Roll multiple prices Adds rows to multiple prices First row: (optionally) Inferred price and forward prices If there is no (old) forward contract price, one needs to be inferred If there is no (old) price contract price, one needs to be inferred Time index = Last time index + 1 second Second row: Time index: Last time index + 1 second PRICE = last price of the forward contract PRICE_CONTRACT = previous forward contract FORWARD_CONTRACT = the new forward contract FORWARD_PRICE = the new forward price, this can be Nan; it will get filled in CARRY_CONTRACT = the new carry contract CARRY_PRICE = the new carry price: if possible infer from price, this can be Nan :param data: dataBlob :param current_multiple_prices: futuresMultiplePrices :return: new futuresMultiplePrices """ new_multiple_prices = futuresMultiplePrices(copy(current_multiple_prices)) if allow_forward_fill: new_multiple_prices = new_multiple_prices.ffill() # If the last row is all Nans, we can't do this new_multiple_prices = new_multiple_prices.sort_index() new_multiple_prices = new_multiple_prices.drop_trailing_nan() price_column = price_column_names["PRICE"] fwd_column = price_column_names["FORWARD"] current_contract_dict = new_multiple_prices.current_contract_dict() old_forward_contract = current_contract_dict.forward old_priced_contract_last_price, price_inferred = get_or_infer_latest_price( new_multiple_prices, price_col=price_column) old_forward_contract_last_price, forward_inferred = get_or_infer_latest_price( new_multiple_prices, price_col=fwd_column) diag_contracts = dataContracts(data) instrument_object = futuresInstrument(instrument_code) # Old forward contract -> New price contract new_price_contract_date_object = ( diag_contracts.get_contract_date_object_with_roll_parameters( instrument_code, old_forward_contract)) new_forward_contract_date = new_price_contract_date_object.next_held_contract( ) new_carry_contract_date = new_price_contract_date_object.carry_contract() new_price_contract_object = futuresContract( instrument_object, new_price_contract_date_object.contract_date) new_forward_contract_object = futuresContract( instrument_object, new_forward_contract_date.contract_date) new_carry_contract_object = futuresContract( instrument_object, new_carry_contract_date.contract_date) new_price_price = old_forward_contract_last_price new_forward_price = get_final_matched_price_from_contract_object( data, new_forward_contract_object, new_multiple_prices) new_carry_price = get_final_matched_price_from_contract_object( data, new_carry_contract_object, new_multiple_prices) new_price_contractid = new_price_contract_object.date_str new_forward_contractid = new_forward_contract_object.date_str new_carry_contractid = new_carry_contract_object.date_str # If any prices had to be inferred, then add row with both current priced and forward prices # Otherwise adjusted prices will break if price_inferred or forward_inferred: new_single_row = singleRowMultiplePrices( price=old_priced_contract_last_price, forward=old_forward_contract_last_price, ) new_multiple_prices = new_multiple_prices.add_one_row_with_time_delta( new_single_row) # SOME KIND OF WARNING HERE...? # Now we add a row with the new rolled contracts newer_single_row = singleRowMultiplePrices( price=new_price_price, forward=new_forward_price, carry=new_carry_price, price_contract=new_price_contractid, forward_contract=new_forward_contractid, carry_contract=new_carry_contractid, ) newer_multiple_prices = new_multiple_prices.add_one_row_with_time_delta( newer_single_row) return newer_multiple_prices
def _get_multiple_prices_without_checking(self, instrument_code: str) ->futuresMultiplePrices: data =self.arctic.read(instrument_code) return futuresMultiplePrices(data)