initial
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.venv
|
||||||
|
.idea
|
||||||
6
kurse.csv
Normal file
6
kurse.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Symbol,Letzter_Kurs
|
||||||
|
AAPL,252.2899932861328
|
||||||
|
MSFT,513.5800170898438
|
||||||
|
VWCE.DE,140.10000610351562
|
||||||
|
SPY,664.3900146484375
|
||||||
|
SAP,272.8999938964844
|
||||||
|
33
kurse.py
Normal file
33
kurse.py
Normal 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
6
meine_aktien.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Symbol
|
||||||
|
AAPL
|
||||||
|
MSFT
|
||||||
|
VWCE.DE
|
||||||
|
SPY
|
||||||
|
SAP
|
||||||
|
Reference in New Issue
Block a user