def test_day_before_board(): start_date = "03-21-2019" stop_date = "01-01-2020" # dates in epoch timestamp of the dates: # respectively: 03-20-2019', '06-20-2019', '09-19-2019', '12-19-2019' # (mm:dd:yyyy format) ts_bm_days = np.array( [1.5530400e09, 1.5609888e09, 1.5688512e09, 1.5767136e09]) ts_gen = calc.day_before_board(start_date, stop_date) assert np.array_equal(ts_bm_days, ts_gen)
def hist_time_array_set(start_date=START_DATE): # define the variable containing all the date from start_date to yesterday. # the date are displayed as timestamp and each day refers to 12:00 am UTC reference_date_arr = date_gen(start_date) # define all the useful arrays containing the rebalance # start date, stop date, board meeting date reb_start_date = start_q(start_date) reb_stop_date = stop_q(reb_start_date) board_date = board_meeting_day() board_date_eve = day_before_board() next_reb_date = next_start() return (reference_date_arr, reb_start_date, reb_stop_date, board_date, board_date_eve, next_reb_date)
def index_daily(coll_to_use="coll_data_feed", day=None): start_q_list = next_start() board_eve_list = day_before_board() print(board_eve_list) day_TS, _ = days_variable(day) if day_TS in start_q_list: info('Index daily for quarter start starting...') mongo_daily_delete(day, "index") try: index_start_q_day(CRYPTO_ASSET, EXCHANGES, PAIR_ARRAY, coll_to_use, day=day) except Exception: error("Exception occurred", exc_info=True) elif day_TS in board_eve_list: info('Index daily for board day starting...') mongo_daily_delete(day, "index") try: index_board_day(CRYPTO_ASSET, EXCHANGES, PAIR_ARRAY, coll_to_use, day=day) except Exception: error("Exception occurred", exc_info=True) else: info('Index daily for normal day starting...') mongo_daily_delete(day, "index") try: index_normal_day(CRYPTO_ASSET, EXCHANGES, PAIR_ARRAY, coll_to_use, day=day) except Exception: error("Exception occurred", exc_info=True)
y_TS = today_TS - 86400 two_before_TS = y_TS - 86400 today_human = data_setup.timestamp_to_human([today_TS]) yesterday_human = data_setup.timestamp_to_human([y_TS]) two_before_human = data_setup.timestamp_to_human([two_before_TS]) # define the variable containing all the date from start_date to today. # the date are displayed as timestamp and each day refers to 12:00 am UTC reference_date_vector = data_setup.date_gen(start_date) # define all the useful arrays containing the rebalance start # date, stop date, board meeting date rebalance_start_date = calc.start_q("01-01-2016") rebalance_stop_date = calc.stop_q(rebalance_start_date) board_date = calc.board_meeting_day() board_date_eve = calc.day_before_board() next_rebalance_date = calc.next_start() # call the function that creates a object containing # the couple of quarterly start-stop date quarterly_date = calc.quarterly_period() # ############# MAIN PART ######################### # downloading the daily value from MongoDB and put it into a dataframe # defining the dictionary for the MongoDB query query_dict = {"Time": str(y_TS)} # retriving the needed information on MongoDB daily_mat = mongo.query_mongo(db_name, coll_data, query_dict)
from cryptoindex.calc import (next_start, next_quarterly_period, start_q, stop_q, board_meeting_day, day_before_board, next_start) from cryptoindex.index_hist import hist_time_single_date from cryptoindex.data_setup import (timestamp_to_human) from cryptoindex.index_func import days_variable day = None start_q_list = next_start() board_eve_list = day_before_board() board_day = board_meeting_day() start_q = start_q() print(start_q_list) print(board_eve_list) print(board_day) print(start_q) print(timestamp_to_human(start_q_list[1:len(start_q_list)])) day_TS, _ = days_variable(day) # day_TS = day_TS + 86400 print(day_TS) if day_TS in start_q_list: print("First day of the quarter") elif day_TS in board_eve_list: print("Board day")
today_TS = int(today.replace(tzinfo=timezone.utc).timestamp()) y_TS = today_TS - DAY_IN_SEC # # define end date as as MM-DD-YYYY # end_date = datetime.now().strftime("%m-%d-%Y") # define the variable containing all the date from start_date to yesterday. # the date are displayed as timestamp and each day refers to 12:00 am UTC reference_date_vector = date_gen(START_DATE) # define all the useful arrays containing the rebalance # start date, stop date, board meeting date rebalance_start_date = start_q(START_DATE) rebalance_stop_date = stop_q(rebalance_start_date) board_date = board_meeting_day() board_date_eve = day_before_board() next_rebalance_date = next_start() print(rebalance_start_date) print(rebalance_stop_date) print(next_rebalance_date) print(board_date_eve) # defining time variables last_reb_start = str(int(rebalance_start_date[len(rebalance_start_date) - 1])) next_reb_stop = str(int(rebalance_stop_date[len(rebalance_stop_date) - 1])) last_reb_stop = str(int(rebalance_stop_date[len(rebalance_stop_date) - 2])) curr_board_eve = str(int(board_date_eve[len(board_date_eve) - 1])) print(last_reb_start) print(next_reb_stop) print(curr_board_eve) # call the function that creates a object containing the # couple of quarterly start-stop date
def index_board_day(crypto_asset, exc_list, pair_list, coll_to_use, day=None): mongo_indexing() day_before_TS, _ = days_variable(day) # define all the useful arrays containing the rebalance start # date, stop date, board meeting date rebalance_start_date = start_q(START_DATE) rebalance_stop_date = stop_q(rebalance_start_date) board_date_eve = day_before_board() next_rebalance_date = next_start() # call the function that creates a object containing # the couple of quarterly start-stop date next_reb_start = str(int(next_rebalance_date[len(rebalance_start_date)])) curr_reb_start = str( int(rebalance_start_date[len(rebalance_start_date) - 1])) last_reb_start = str( int(rebalance_start_date[len(rebalance_start_date) - 2])) next_reb_stop = str(int(rebalance_stop_date[len(rebalance_stop_date) - 2])) curr_board_eve = str(int(board_date_eve[len(board_date_eve) - 1])) # defining the dictionary for the MongoDB query query_dict = {"Time": int(day_before_TS)} # retriving the needed information on MongoDB daily_mat = query_mongo(DB_NAME, MONGO_DICT.get(coll_to_use), query_dict) crypto_asset_price, crypto_asset_vol, exc_vol_tot, logic_one_arr = index_daily_loop( daily_mat, crypto_asset, exc_list, pair_list, day_before_TS, last_reb_start, next_reb_stop, curr_board_eve, day_type="board") (crypto_asset_price, crypto_asset_vol, price_ret, daily_ewma, daily_ewma_double_check, daily_synth, daily_rel, curr_divisor, first_logic_row, second_logic_row, weights_for_board, daily_index_1000_df, raw_index_df, _) = index_daily_operation(crypto_asset, crypto_asset_price, crypto_asset_vol, day_before_TS, curr_reb_start, next_reb_start, curr_board_eve, logic_one_arr=logic_one_arr, day_type="board", day=day) print(daily_ewma_double_check) index_daily_uploader(crypto_asset_price, crypto_asset_vol, exc_vol_tot, price_ret, daily_ewma, daily_ewma_double_check, daily_synth, daily_rel, curr_divisor, daily_index_1000_df, raw_index_df, new_logic_one=first_logic_row, new_logic_two=second_logic_row, new_weights=weights_for_board, day=day) return None