def create_points_dataframe(market_name, delay_days,
                            volume_percent_filter=0, ascend_or_descend='ascend',
                            column_name='Percent-Change', sign_or_value='value', number_of_iterations=1):

    daily_files_paths_list = path_finding_functions.get_all_daily_files_paths_in_specific_market(market_name)
    advanced_utils.check_for_daily_gaps(daily_files_paths_list)

    sample_daily_dataframe = stocks_analysis.all_companies_data_frame(daily_files_paths_list[-1])

    initial_volume_filtered_dataframe = \
        advanced_utils.volume_filtered_market_dataframe(sample_daily_dataframe, volume_percent_filter)

    symbols_list = initial_volume_filtered_dataframe['Symbol'].tolist()

    # split the symbols list, so each thread takes a sub-list to work on.
    splitted_list_of_symbols = advanced_utils.splitted_symbols_list(symbols_list, NUMBER_OF_SUBLISTS)

    companies_squared_dataframe = \
        build_companies_squared_dataframe(symbols_list, splitted_list_of_symbols,
                                          column_name, market_name, delay_days,
                                          volume_percent_filter, ascend_or_descend,
                                          sign_or_value, number_of_iterations)

    sort_by_companies = ['TOPS', 'CSCO', 'SRNE']  # just to make sure i see all companies that were-
                                                  # included in the count, and not spreaded all over the sheet.
    companies_squared_dataframe.sort_values(by=sort_by_companies, ascending=False, inplace=True)

    file_path = path_finding_functions.\
        set_points_file_path(market_name + "_" + ascend_or_descend + "_"
                             + sign_or_value + "_" + "delay" + str(delay_days))
    writer = pd.ExcelWriter(file_path, engine='xlsxwriter')
    companies_squared_dataframe.to_excel(writer)
    writer.save()
Ejemplo n.º 2
0
def get_last_daily_dataframe(market_name):
    last_daily_path = path_finding_functions.get_last_daily_data_file_path(
        market_name)
    print("Last daily file's path: ", last_daily_path)
    last_daily_dataframe = stocks_analysis.all_companies_data_frame(
        last_daily_path)
    return last_daily_dataframe
    def __init__(self):
        self.daily_data_file_path_currencies = scrape_API.EoddataExchange(
            'currencies').set_daily_data_file_name()

        if os.path.isfile(self.daily_data_file_path_currencies) is False:
            try:
                scrape_API.EoddataExchange('currencies').create_daily_data()
            except:
                print(
                    "no currency symbols data file found.\n initiating symbols data file creation."
                )
                scrape_API.EoddataExchange('currencies').create_symbols_file()

        self.all_currencies_dataframe = stocks_analysis.all_companies_data_frame(
            self.daily_data_file_path_currencies)
    def __init__(self, exchange_name):
        self.daily_data_file_path = scrape_API.EoddataExchange(
            exchange_name).set_daily_data_file_name()
        self.viable_data_column_names = VIABLE_DATA_COLUMN_NAMES

        try:
            if os.path.isfile(self.daily_data_file_path) is False:
                scrape_API.EoddataExchange(exchange_name).create_daily_data()
                print("Created daily data file of market: ", exchange_name)
        except IndexError:
            print(
                "no " + exchange_name +
                " symbols data file found.\n initiating symbols data file creation."
            )
            scrape_API.EoddataExchange(exchange_name).create_symbols_file()
            print("Symbols data file created. Initializing daily data scrape.")
            scrape_API.EoddataExchange(exchange_name).create_daily_data()

        self.all_daily_dataframe = stocks_analysis.all_companies_data_frame(
            self.daily_data_file_path)
def all_currencies_data_frame(data_file_path):
    all_currencies_dataframe = stocks_analysis.all_companies_data_frame(
        data_file_path)
    return all_currencies_dataframe
def build_count_dict_from_daily_files(number_of_counted_days, daily_files_paths_list,
                                      company_symbol, col_name, delay_days, updated_daily_dict_counter,
                                      ascend_or_descend, volume_percent_filter_to_remove=0, sign_or_value='sign'):
    ascend_count = 0
    descend_count = 0
    company_value_sign = 0
    previous_company_values = 0

    print(company_symbol, ascend_or_descend, sign_or_value)

    # run over each daily file, focusing on a specific company (company_symbol):
    for i in range(number_of_counted_days):

        # focused_day_dataframe
        today_dataframe = stocks_analysis.all_companies_data_frame(daily_files_paths_list[i])
        # today_dataframe = advanced_utils.remove_companies_black_list_from_dataframe(today_dataframe)

        volume_filtered_dataframe = advanced_utils.\
            volume_filtered_market_dataframe(today_dataframe, volume_percent_filter_to_remove)

        if sign_or_value == 'sign':     # take its percent-change sign (+ or -)
            company_value_sign = advanced_utils.\
                get_company_value_sign_from_daily_dataframe(volume_filtered_dataframe,
                                                            company_symbol, col_name)
        elif sign_or_value == 'value':  # take its percent-change value.
            try:
                company_value_sign = \
                    volume_filtered_dataframe[volume_filtered_dataframe['Symbol'] ==
                                              company_symbol]['Percent-Change'].tolist()[0]
            except IndexError:
                print("Index out of range. Company is not in volume_filtered_dataframe: ", company_symbol)
                company_value_sign = 0

        delayed_daily_dataframe = \
            stocks_analysis.all_companies_data_frame(daily_files_paths_list[i + delay_days])
        # delayed_daily_dataframe = advanced_utils.remove_companies_black_list_from_dataframe(delayed_daily_dataframe)

        next_company_values = volume_filtered_dataframe[volume_filtered_dataframe['Symbol'] == company_symbol]

        check_equals = check_equal_days_values(today_dataframe, delayed_daily_dataframe,
                                               col_name, next_company_values, previous_company_values)

        previous_company_values = next_company_values
        if check_equals is True:
            continue

        if company_value_sign > 0:
            ascend_count += 1
            if ascend_or_descend == 'descend':
                continue
        elif company_value_sign < 0:
            descend_count += 1
            if ascend_or_descend == 'ascend':
                continue
        else:
            continue

        volume_filtered_delayed_dataframe = \
            advanced_utils.volume_filtered_market_dataframe(delayed_daily_dataframe, volume_percent_filter_to_remove)

        updated_daily_dict_counter = \
            advanced_utils.add_day_to_counter_dict(volume_filtered_delayed_dataframe,
                                                   company_value_sign, col_name,
                                                   updated_daily_dict_counter, ascend_or_descend, sign_or_value)

    return updated_daily_dict_counter, ascend_count, descend_count