This commit is contained in:
baschno
2025-10-18 15:06:52 +02:00
commit 53db5cff6d
4 changed files with 47 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.venv
.idea

6
kurse.csv Normal file
View File

@@ -0,0 +1,6 @@
Symbol,Letzter_Kurs
AAPL,252.2899932861328
MSFT,513.5800170898438
VWCE.DE,140.10000610351562
SPY,664.3900146484375
SAP,272.8999938964844
1 Symbol Letzter_Kurs
2 AAPL 252.2899932861328
3 MSFT 513.5800170898438
4 VWCE.DE 140.10000610351562
5 SPY 664.3900146484375
6 SAP 272.8999938964844

33
kurse.py Normal file
View File

@@ -0,0 +1,33 @@
import pandas as pd
import yfinance as yf
def lade_kurse(csv_datei: str, ausgabe_datei: str = "kurse.csv"):
# CSV lesen, erwartet Spalte 'Symbol'
daten = pd.read_csv(csv_datei)
if 'Symbol' not in daten.columns:
raise ValueError("CSV-Datei benötigt eine Spalte mit dem Namen 'Symbol'.")
symbole = daten['Symbol'].dropna().unique()
# Kursdaten von Yahoo Finance abrufen
kurs_liste = []
for symbol in symbole:
try:
ticker = yf.Ticker(symbol)
info = ticker.history(period='1d')
if not info.empty:
letzter_kurs = info['Close'].iloc[-1]
kurs_liste.append({"Symbol": symbol, "Letzter_Kurs": letzter_kurs})
else:
kurs_liste.append({"Symbol": symbol, "Letzter_Kurs": None})
except Exception as e:
kurs_liste.append({"Symbol": symbol, "Letzter_Kurs": None, "Fehler": str(e)})
# Ergebnisse speichern
df_kurse = pd.DataFrame(kurs_liste)
df_kurse.to_csv(ausgabe_datei, index=False)
print(f"Kurse wurden erfolgreich in {ausgabe_datei} gespeichert.")
# Beispielaufruf (entferne Kommentar zur Nutzung)
lade_kurse('meine_aktien.csv')

6
meine_aktien.csv Normal file
View File

@@ -0,0 +1,6 @@
Symbol
AAPL
MSFT
VWCE.DE
SPY
SAP
1 Symbol
2 AAPL
3 MSFT
4 VWCE.DE
5 SPY
6 SAP