Skip to content

Commit

Permalink
also generating merged prices when importing split frequency CSV prices
Browse files Browse the repository at this point in the history
  • Loading branch information
bug-or-feature committed Feb 22, 2024
1 parent 3a62d59 commit 374a6b5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sysinit/futures/contract_prices_from_csv_to_arctic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from syscore.constants import arg_not_supplied
from syscore.dateutils import MIXED_FREQ, HOURLY_FREQ, DAILY_PRICE_FREQ
from syscore.pandas.frequency import merge_data_with_different_freq
from sysdata.csv.csv_futures_contract_prices import csvFuturesContractPriceData
from sysproduction.data.prices import diagPrices
from sysobjects.contracts import futuresContract
Expand Down Expand Up @@ -64,6 +65,36 @@ def init_db_with_csv_futures_contract_prices_for_code(
)
print("Read back prices are \n %s" % str(written_prices))

# if we're importing hourly or daily, we need to also generate MIXED
if frequency != MIXED_FREQ:
create_merged_prices(contract)


def create_merged_prices(contract):
db_prices = diag_prices.db_futures_contract_price_data
if db_prices.has_price_data_for_contract_at_frequency(
contract, DAILY_PRICE_FREQ
) and db_prices.has_price_data_for_contract_at_frequency(contract, HOURLY_FREQ):
print(f"DB has hourly and daily prices for {contract}, creating merged prices")
list_of_data = [
diag_prices.get_prices_at_frequency_for_contract_object(
contract,
frequency=frequency,
)
for frequency in [HOURLY_FREQ, DAILY_PRICE_FREQ]
]
merged_prices = merge_data_with_different_freq(list_of_data)
print("Writing to db")
db_prices.write_prices_at_frequency_for_contract_object(
contract, merged_prices, frequency=MIXED_FREQ, ignore_duplication=True
)
print("Reading back prices from db to check")
written_merged_prices = db_prices.get_prices_at_frequency_for_contract_object(
contract, frequency=MIXED_FREQ
)

print(f"Read back prices (MIXED) are \n{str(written_merged_prices)}")


if __name__ == "__main__":
input("Will overwrite existing prices are you sure?! CTL-C to abort")
Expand Down

0 comments on commit 374a6b5

Please sign in to comment.