Как исправить отсортированные годы в Python, они отсортированы неправильноPython

Программы на Python
Ответить Пред. темаСлед. тема
Гость
 Как исправить отсортированные годы в Python, они отсортированы неправильно

Сообщение Гость »


for some reason projected fcf 2023 comes after projected fcf 2028. how do i fix this error?enter image description here

def main(): file_path = 'all_stocksbeta.csv' # Update with the path to your CSV file stocks_df = pd.read_csv(file_path) symbols = stocks_df['Symbol'].tolist() wacc = 10 # WACC is 10% terminal_growth_rate = 2 # Terminal growth rate is 2% for symbol in symbols: ticker = yf.Ticker(symbol) fcf_data, fcf_growth, avg_growth, fcf_proj = download_cashflow_data(symbol) # Skip the symbol if the FCF projection is empty if not fcf_proj: continue balance_sheet = ticker.balance_sheet total_debt, cash_and_equivalents = get_financial_data(symbol) shares_outstanding = get_number_of_shares(balance_sheet) if shares_outstanding > 0: pv_fcf, pv_terminal_value, ev = calculate_pv_and_ev(fcf_proj, wacc, terminal_growth_rate) equity_value = ev - total_debt + cash_and_equivalents # Fetch the last closing price using yfinance hist = ticker.history(period="1d") last_closing_price = hist['Close'].iloc[-1] if not hist.empty else 0 intrinsic_value_per_share = equity_value / shares_outstanding # Print the required information print(f"\n{symbol}:") print("Free Cash Flow for the Last 4 Years:") for year, fcf in fcf_data.items(): print(f" {year}: {fcf}") print("FCF Year-over-Year Growth (%):") for year, growth in fcf_growth.items(): print(f" {year}: {growth}%") print(f"Average FCF Growth (%): {avg_growth}%") print("Projected FCF for the Next 5 Years:") for year, proj_fcf in fcf_proj.items(): print(f" {year}: {proj_fcf}") print(f"Present Value of Projected FCFs: {pv_fcf}") print(f"Present Value of Terminal Value: {pv_terminal_value}") print(f"Enterprise Value (EV): {ev}") print(f"Equity Value : {equity_value}") print(f"Last Closing Price: {last_closing_price}") # Determine if the stock is undervalued growth_potential = ((intrinsic_value_per_share - last_closing_price) / last_closing_price) * 100 if last_closing_price else 0 undervalued = intrinsic_value_per_share > last_closing_price print(f"Intrinsic Value per Share: {intrinsic_value_per_share}") print(f"Growth Potential (%): {growth_potential}") print(f"Undervalued?: {undervalued}") if __name__ == "__main__": main() 2023 should come first in ascending order. there seem to be some error with the sorting. i don't mind if you have a suggestion to hard code the years. though it has to be dynamically because it should continue from the most recent fcf year


Источник: https://stackoverflow.com/questions/780 ... ed-wrongly
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»