Understanding Pandas <pandas._libs.ops.scalar_compare> call

Viewed 208

I ran the PyCharm profiler on my code and go the following call graph. enter image description here

new_method (second from the left) gets called however I do not have any function called new_method in my code. I assume it comes from where I assign close_price in the code below. If so, is there a better way of sectioning data from a dataframe that does not take so long?

def base_algo(conn):
    #start_date = datetime.strptime("2000-09-22", "%Y-%m-%d")
    start_date = datetime.strptime("2020-07-02", "%Y-%m-%d")
    end_date = datetime.strptime("2020-07-23", "%Y-%m-%d")
    current_date = start_date
    while current_date < end_date:
        historical_data = select_historical_data(conn, current_date)
        buy_sell_signal = pd.DataFrame()
        for stock in historical_data["stock"].unique():
            close_price = historical_data[historical_data["stock"] == stock].close_val
            slope_50 = calculate_slope(close_price, 50)
            slope_200 = calculate_slope(close_price, 200)
            to_append = {"stock":stock, "slope_50":slope_50, "slope_200":slope_200}
            buy_sell_signal = buy_sell_signal.append(to_append, ignore_index=True)
        current_date = current_date + timedelta(days=1)
0 Answers
Related