Skip to content

Commit

Permalink
Financial datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Nov 16, 2024
1 parent e51c17f commit f84a2d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
18 changes: 3 additions & 15 deletions docs/notes/financial-data-sources/pandas-datareader.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,9 @@ We can access [FRED datasets](https://fred.stlouisfed.org/) directly in Python u
```{python}
from pandas_datareader import get_data_fred
dataset_id = "GDP"
df = get_data_fred(dataset_id)
df.head()
```


Specifying start and end dates, as desired:

```{python}
from datetime import datetime
from pandas_datareader import get_data_fred
start = datetime(1900, 1, 1)
end = datetime(2023, 1, 1)
dataset_id = "GDP" # quarterly
df = get_data_fred(dataset_id, start, end)
#df = get_data_fred(dataset_id)
df = get_data_fred(dataset_id, start="2001-01-01", end="2023-01-01")
df.head()
```
27 changes: 14 additions & 13 deletions docs/notes/financial-data-sources/yahooquery.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,50 @@ execute:
#| echo: false
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
#warnings.filterwarnings("ignore")
```

## Single Company

```{python}
from yahooquery import Ticker
symbol = "NFLX"
ticker = Ticker(symbol)
ticker
ticker = Ticker("NFLX")
```

Company information:

```{python}
ticker.summary_profile
```

Historical prices:


```{python}
df = ticker.history(start="2024-01-01", end="2024-01-31", adj_ohlc=True)
#print(df.index)
df.head()
```


## Multiple Companies

```{python}
from yahooquery import Ticker
symbols = ["MSFT", "AAPL", "GOOGL"]
tickers = Ticker( ["MSFT", "AAPL", "GOOGL"])
```

Company information:

tickers = Ticker(symbols)
tickers
```{python}
tickers.summary_profile
```

Historical prices:

```{python}
df = tickers.history()
#print(df.index)
df.head()
```

Expand All @@ -63,13 +67,10 @@ Simplifying the multi-index:
```{python}
from pandas import to_datetime
df = tickers.history()
#print(df.index)
df["symbol"] = df.index.get_level_values(0)
df["date"] = to_datetime(df.index.get_level_values(1)).date
df.reset_index(drop=True, inplace=True)
df[["date", "symbol", "adjclose"]].head()
```

Expand Down
6 changes: 3 additions & 3 deletions docs/notes/financial-data-sources/yfinance.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Fetching data from Yahoo Finance:
```{python}
import yfinance as yf
ticker = "NVDA"
df = yf.download(ticker, start="2014-01-01", end="2024-01-01")
df
symbol = "NVDA"
df = yf.download(symbol, start="2014-01-01", end="2024-01-31")
df.head()
```

0 comments on commit f84a2d1

Please sign in to comment.