src/scrape_fun.py
def add_dividends(stock_of_interest, options_df, history_df, dividends_data_path, save_path):
    """
    This function appends the price contribution due to dividends for the "posting" and
    "expiration" dates of each option. This allows us to be one step closer to working
    with the "true" price of the security on those dates.

    :param stock_of_interest: ticker symbol (string)
    :param options_df: all option data for specified ticker (DataFrame)
    :param history_df: historical end of day prices for ticker (DataFrame)
    :param dividends_data_path: path where dividend data is stored (str)
    :param save_path: path to save final options data (str)
    :return: None
    """
    # Load dividend data
    try:
        my_dividends_df = pd.read_csv(os.path.abspath(os.path.join(dividends_data_path, stock_of_interest)) + "_ts.csv")
        my_dividends_df["date"] = pd.to_datetime(my_dividends_df["date"]).dt.date
    except FileNotFoundError:
        raise SystemExit("Dividend data for " + stock_of_interest + " not found in path: " +
                         os.path.abspath(os.path.join(dividends_data_path, stock_of_interest)) + "_ts.csv")

    # Initialize empty containers
    my_date_div = pd.Series()
    my_exp_date_div = pd.Series()
    my_exp_closing = pd.Series()
    # adding dividend contribution info to DataFrame
    for my_date in sorted(options_df["date"].unique()):
        temp_options_df = options_df[options_df["date"] == my_date]
        date_div_price = float(my_dividends_df[my_dividends_df["date"] == my_date]["amount"])
        my_date_div = my_date_div.append(pd.Series(np.ones(temp_options_df.shape[0]) * date_div_price)).reset_index(
            drop=True)
        for my_exp_date in sorted(temp_options_df["expiration date"].unique()):
            exp_day_length = temp_options_df[temp_options_df["expiration date"] == my_exp_date].shape[0]
            exp_day_div_price = float(my_dividends_df[my_dividends_df["date"] == my_exp_date]["amount"])
            exp_day_closing_price = float(history_df[history_df["date"] == my_exp_date]["close"])
            my_exp_date_div = my_exp_date_div.append(
                pd.Series(np.ones(exp_day_length) * exp_day_div_price)).reset_index(drop=True)
            my_exp_closing = my_exp_closing.append(
                pd.Series(np.ones(exp_day_length) * exp_day_closing_price)).reset_index(drop=True)

    # Adding additional columns
    options_df["exp date closing price"] = my_exp_closing
    options_df["date div"] = my_date_div
    options_df["exp date div"] = my_exp_date_div

    # Save adjusted options data
    Path(save_path).mkdir(exist_ok=True)
    options_df.to_csv(path_or_buf=(os.path.abspath(os.path.join(save_path, stock_of_interest)) + ".csv"),
                      index=False)
    print("All adjusted option data for " + stock_of_interest + " has been aggregated and saved to path: " +
          os.path.abspath(os.path.join(save_path, stock_of_interest)) + ".csv")
    return

    This function appends the price contribution due to dividends for the "posting" and
    "expiration" dates of each option. This allows us to be one step closer to working
    with the "true" price of the security on those dates.

    :param stock_of_interest: ticker symbol (string)
    :param options_df: all option data for specified ticker (DataFrame)
    :param history_df: historical end of day prices for ticker (DataFrame)
    :param dividends_data_path: path where dividend data is stored (str)
    :param save_path: path to save final options data (str)
    :return: None
    
This function appends the price contribution due to dividends for the "posting" and
"expiration" dates of each option. This allows us to be one step closer to working
with the "true" price of the security on those dates.
This function appends the price contribution due to dividends for the " posting " and " expiration " dates of each option . This allows us to be one step closer to working with the " true " price of the security on those dates .
def add_dividends(stock_of_interest, options_df, history_df, dividends_data_path, save_path):
    try:
        my_dividends_df = pd.read_csv(os.path.abspath(os.path.join(dividends_data_path, stock_of_interest)) + "_ts.csv")
        my_dividends_df["date"] = pd.to_datetime(my_dividends_df["date"]).dt.date
    except FileNotFoundError:
        raise SystemExit("Dividend data for " + stock_of_interest + " not found in path: " +
                         os.path.abspath(os.path.join(dividends_data_path, stock_of_interest)) + "_ts.csv")
    my_date_div = pd.Series()
    my_exp_date_div = pd.Series()
    my_exp_closing = pd.Series()
    for my_date in sorted(options_df["date"].unique()):
        temp_options_df = options_df[options_df["date"] == my_date]
        date_div_price = float(my_dividends_df[my_dividends_df["date"] == my_date]["amount"])
        my_date_div = my_date_div.append(pd.Series(np.ones(temp_options_df.shape[0]) * date_div_price)).reset_index(
            drop=True)
        for my_exp_date in sorted(temp_options_df["expiration date"].unique()):
            exp_day_length = temp_options_df[temp_options_df["expiration date"] == my_exp_date].shape[0]
            exp_day_div_price = float(my_dividends_df[my_dividends_df["date"] == my_exp_date]["amount"])
            exp_day_closing_price = float(history_df[history_df["date"] == my_exp_date]["close"])
            my_exp_date_div = my_exp_date_div.append(
                pd.Series(np.ones(exp_day_length) * exp_day_div_price)).reset_index(drop=True)
            my_exp_closing = my_exp_closing.append(
                pd.Series(np.ones(exp_day_length) * exp_day_closing_price)).reset_index(drop=True)
    options_df["exp date closing price"] = my_exp_closing
    options_df["date div"] = my_date_div
    options_df["exp date div"] = my_exp_date_div
    Path(save_path).mkdir(exist_ok=True)
    options_df.to_csv(path_or_buf=(os.path.abspath(os.path.join(save_path, stock_of_interest)) + ".csv"),
                      index=False)
    print("All adjusted option data for " + stock_of_interest + " has been aggregated and saved to path: " +
          os.path.abspath(os.path.join(save_path, stock_of_interest)) + ".csv")
    return
def add_dividends ( stock_of_interest , options_df , history_df , dividends_data_path , save_path ) : try : my_dividends_df = pd . read_csv ( os . path . abspath ( os . path . join ( dividends_data_path , stock_of_interest ) ) + "_ts.csv" ) my_dividends_df [ "date" ] = pd . to_datetime ( my_dividends_df [ "date" ] ) . dt . date except FileNotFoundError : raise SystemExit ( "Dividend data for " + stock_of_interest + " not found in path: " + os . path . abspath ( os . path . join ( dividends_data_path , stock_of_interest ) ) + "_ts.csv" ) my_date_div = pd . Series ( ) my_exp_date_div = pd . Series ( ) my_exp_closing = pd . Series ( ) for my_date in sorted ( options_df [ "date" ] . unique ( ) ) : temp_options_df = options_df [ options_df [ "date" ] == my_date ] date_div_price = float ( my_dividends_df [ my_dividends_df [ "date" ] == my_date ] [ "amount" ] ) my_date_div = my_date_div . append ( pd . Series ( np . ones ( temp_options_df . shape [ 0 ] ) * date_div_price ) ) . reset_index ( drop = True ) for my_exp_date in sorted ( temp_options_df [ "expiration date" ] . unique ( ) ) : exp_day_length = temp_options_df [ temp_options_df [ "expiration date" ] == my_exp_date ] . shape [ 0 ] exp_day_div_price = float ( my_dividends_df [ my_dividends_df [ "date" ] == my_exp_date ] [ "amount" ] ) exp_day_closing_price = float ( history_df [ history_df [ "date" ] == my_exp_date ] [ "close" ] ) my_exp_date_div = my_exp_date_div . append ( pd . Series ( np . ones ( exp_day_length ) * exp_day_div_price ) ) . reset_index ( drop = True ) my_exp_closing = my_exp_closing . append ( pd . Series ( np . ones ( exp_day_length ) * exp_day_closing_price ) ) . reset_index ( drop = True ) options_df [ "exp date closing price" ] = my_exp_closing options_df [ "date div" ] = my_date_div options_df [ "exp date div" ] = my_exp_date_div Path ( save_path ) . mkdir ( exist_ok = True ) options_df . to_csv ( path_or_buf = ( os . path . abspath ( os . path . join ( save_path , stock_of_interest ) ) + ".csv" ) , index = False ) print ( "All adjusted option data for " + stock_of_interest + " has been aggregated and saved to path: " + os . path . abspath ( os . path . join ( save_path , stock_of_interest ) ) + ".csv" ) return
This function appends the price contribution due to dividends for the "posting" and
"expiration" dates of each option.
This function appends the price contribution due to dividends for the " posting " and " expiration " dates of each option .
"""
    This function appends the price contribution due to dividends for the "posting" and
    "expiration" dates of each option. This allows us to be one step closer to working
    with the "true" price of the security on those dates.

    :param stock_of_interest: ticker symbol (string)
    :param options_df: all option data for specified ticker (DataFrame)
    :param history_df: historical end of day prices for ticker (DataFrame)
    :param dividends_data_path: path where dividend data is stored (str)
    :param save_path: path to save final options data (str)
    :return: None
    """ # Load dividend data
 # Initialize empty containers
 # adding dividend contribution info to DataFrame
 # Adding additional columns
 # Save adjusted options data

None
stock_of_interest
ticker symbol (string)
ticker symbol ( string )
options_df
all option data for specified ticker (DataFrame)
all option data for specified ticker ( DataFrame )
history_df
historical end of day prices for ticker (DataFrame)
historical end of day prices for ticker ( DataFrame )
dividends_data_path
path where dividend data is stored (str)
path where dividend data is stored ( str )
save_path
path to save final options data (str)
path to save final options data ( str )