yfinanceyfinance
A popular open-source Python library for downloading market data from Yahoo Finance in a few lines of code.ספריית Python פופולרית בקוד פתוח להורדת נתוני שוק מ-Yahoo Finance בכמה שורות קוד.
What is it?מה זה?
yfinance is a community-maintained Python package that fetches data from Yahoo Finance's publicly available APIs and returns it as pandas objects. It covers historical prices, dividends and splits, and other ticker information for stocks, ETFs, indices, currencies and crypto. It is not affiliated with or endorsed by Yahoo, and is intended for research and educational use.yfinance היא חבילת Python שמתוחזקת על ידי הקהילה, ששולפת נתונים מה-APIs הציבוריים של Yahoo Finance ומחזירה אותם כאובייקטים של pandas. היא מכסה מחירים היסטוריים, דיבידנדים ופיצולים, ומידע נוסף על ניירות ערך: מניות, ETFs, מדדים, מטבעות וקריפטו. היא לא קשורה ל-Yahoo ולא מאושרת על ידה, ומיועדת לשימוש מחקרי ולימודי.
Why it matters for quantsלמה זה חשוב לקוואנטים
For learning and quick prototypes, yfinance is the fastest way to get real daily prices into a notebook for free. It is perfect for testing a first moving-average strategy, computing correlations between assets or building a toy portfolio. Professionals use it for quick sanity checks, but rely on licensed, survivorship-bias-free data for serious research and production. Knowing its limits is part of learning good data hygiene.ללמידה ולאבות-טיפוס מהירים, yfinance היא הדרך המהירה ביותר להכניס מחירים יומיים אמיתיים ל-notebook בחינם. היא מושלמת לבדיקת אסטרטגיית ממוצע נע ראשונה, לחישוב קורלציות בין נכסים או לבניית תיק לדוגמה. אנשי מקצוע משתמשים בה לבדיקות שפיות מהירות, אבל במחקר רציני ובפרודקשן נשענים על נתונים ברישיון ונטולי survivorship bias. הבנת המגבלות שלה היא חלק מלימוד היגיינת נתונים טובה.
What quants look forמה קוואנטים מחפשים שם
- Ticker().history() for OHLCV price history with a chosen period and intervalTicker().history() להיסטוריית מחירי OHLCV עם תקופה ומרווח לבחירתכם
- download() for fetching many tickers at oncedownload() לשליפת הרבה טיקרים בבת אחת
- Dividends and stock splits, and whether prices are adjusted for themדיבידנדים ופיצולי מניות, והאם המחירים מותאמים אליהם
- Israeli stocks on the Tel Aviv exchange using the .TA suffix (for example TEVA.TA)מניות ישראליות בבורסת תל אביב עם הסיומת TA. (למשל TEVA.TA)
How to get startedאיך מתחילים
- Install it with: pip install yfinanceהתקינו עם: pip install yfinance
- In a notebook, import yfinance as yf and download one ticker's history, as in the example below.ב-notebook, ייבאו את yfinance as yf והורידו היסטוריה של טיקר אחד, כמו בדוגמה למטה.
- Compute returns with pandas and plot the price and a moving average.חשבו תשואות עם pandas ושרטטו את המחיר וממוצע נע.
- Save the downloaded data to a local CSV or Parquet file so you don't re-download it every run.שמרו את הנתונים שהורדתם לקובץ CSV או Parquet מקומי, כדי לא להוריד מחדש בכל הרצה.
Code exampleדוגמת קוד
import yfinance as yf
prices = yf.Ticker("SPY").history(period="1y")["Close"]
returns = prices.pct_change().dropna()
print(returns.tail())
print(f"Average daily return: {returns.mean():.4%}")
Requires an internet connection. Yahoo may change or rate-limit its API, so if it fails, update with pip install -U yfinance.דורש חיבור לאינטרנט. Yahoo עשויה לשנות את ה-API או להגביל קצב בקשות, אז אם זה נכשל עדכנו עם pip install -U yfinance.
Tips & pitfallsטיפים ומלכודות
- Yahoo's terms state its data is for personal use. Check the terms before using it in anything commercial.תנאי השימוש של Yahoo קובעים שהנתונים מיועדים לשימוש אישי. בדקו את התנאים לפני שימוש בכל דבר מסחרי.
- Free data contains errors and only lists currently traded tickers well, which creates survivorship bias in backtests over a stock universe.בנתונים חינמיים יש שגיאות, והם מכסים היטב בעיקר טיקרים שנסחרים היום, מה שיוצר survivorship bias ב-backtests על יקום מניות.
- Know whether your prices are adjusted for splits and dividends; mixing adjusted and unadjusted prices produces fake returns.דעו אם המחירים שלכם מותאמים לפיצולים ולדיבידנדים; ערבוב של מחירים מותאמים ולא מותאמים יוצר תשואות מזויפות.
- Requesting many tickers too quickly can get you rate-limited. Cache data locally and download in batches.בקשה של הרבה טיקרים מהר מדי יכולה לגרום להגבלת קצב. שמרו נתונים מקומית והורידו במנות.
Relatedקשור
Sourcesמקורות
Quant Israel is not affiliated with this service or company. Details may change — check the official site. Nothing here is investment advice.Quant Israel אינה קשורה לשירות או לחברה הזו. הפרטים עשויים להשתנות — בדקו באתר הרשמי. שום דבר כאן אינו ייעוץ השקעות.