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 test_stop_q(): # dates in epoch timestamp of the dates: # respectively: 01-01-2019', '04-01-2019', '07-01-2019', '10-01-2019' # (mm:dd:yyyy format) ts_dates = np.array( [1.5463008e09, 1.5540768e09, 1.5619392e09, 1.5698880e09]) # dates in epoch timestamp of the dates: # respectively: 03-31-2019', '06-30-2019', '09-30-2019', '12-31-2019' # (mm:dd:yyyy format) ts_stopdates = np.array( [1.5539904e09, 1.5618528e09, 1.5698016e09, 1577750400]) stop_date = calc.stop_q(ts_dates) assert np.array_equal(ts_stopdates, stop_date)
today = datetime.strptime(today_str, "%Y-%m-%d") today_TS = int(today.replace(tzinfo=timezone.utc).timestamp()) 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)}
today_str = datetime.now().strftime("%Y-%m-%d") today = datetime.strptime(today_str, "%Y-%m-%d") 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)
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