Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[heavy_data] Retrieve data from yahoo finance #578

Open
wants to merge 3 commits into
base: wasm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
shell: bash -l {0}
run: pip list
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v8
uses: dawidd6/action-download-artifact@v9
with:
workflow: cache.yml
branch: main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/collab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
shell: bash -l {0}
run: pip list
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v8
uses: dawidd6/action-download-artifact@v9
with:
workflow: cache.yml
branch: main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
environment-file: environment.yml
activate-environment: quantecon
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v8
uses: dawidd6/action-download-artifact@v9
with:
workflow: cache.yml
branch: main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
shell: bash -l {0}
run: pip list
- name: Download "build" folder (cache)
uses: dawidd6/action-download-artifact@v8
uses: dawidd6/action-download-artifact@v9
with:
workflow: cache.yml
branch: main
Expand Down
60 changes: 60 additions & 0 deletions RetrieveData.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5a8b8795-232a-4839-aced-5dbdc7965fc4",
"metadata": {},
"source": [
"The Following retrieves data needed for [heavy_tails]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2822e5f8-d817-4e7b-8568-080571fcdb08",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n"
]
}
],
"source": [
"# Might need to run `pip install --upgrade yfinance` first\n",
"import yfinance as yf\n",
"\n",
"# Download the data for AMZN\n",
"Amazon_data = yf.download('AMZN', start='2015-01-01', end='2022-07-01')\n",
"Bitcoin_data = yf.download('BTC-USD', '2015-1-1', '2022-7-1')\n",
"\n",
"Amazon_data.to_csv('lectures/datasets/Amazon_data.csv')\n",
"Bitcoin_data.to_csv('lectures/datasets/Bitcoin_data.csv')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1,890 changes: 1,890 additions & 0 deletions lectures/datasets/Amazon_data.csv

Large diffs are not rendered by default.

2,741 changes: 2,741 additions & 0 deletions lectures/datasets/Bitcoin_data.csv

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions lectures/heavy_tails.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ kernelspec:
(heavy_tail)=
# Heavy-Tailed Distributions

In addition to what's in Anaconda, this lecture will need the following libraries:

```{code-cell} ipython3
:tags: [hide-output]

!pip install --upgrade yfinance pandas_datareader
```

We use the following imports.
This lecture will use the following imports

```{code-cell} ipython3
import matplotlib.pyplot as plt
import numpy as np
import yfinance as yf
import pandas as pd
import statsmodels.api as sm

Expand Down Expand Up @@ -182,12 +173,13 @@ the period from 1st January 2015 to 1st July 2022.

This equates to daily returns if we set dividends aside.

The code below produces the desired plot using Yahoo financial data via the `yfinance` library.

```{code-cell} ipython3
:tags: [hide-output]

data = yf.download('AMZN', '2015-1-1', '2022-7-1')
Amazon_data = pd.read_csv("datasets/Amazon_data.csv")
# Convert columns to numeric
for col in ['Price', 'Close', 'High', 'Low', 'Open', 'Volume']:
Amazon_data[col] = pd.to_numeric(Amazon_data[col], errors='coerce')
```

```{code-cell} ipython3
Expand All @@ -197,7 +189,7 @@ mystnb:
caption: Daily Amazon returns
name: dailyreturns-amzn
---
s = data['Close']
s = Amazon_data['Close']
r = s.pct_change()

fig, ax = plt.subplots()
Expand All @@ -219,7 +211,10 @@ We get a similar picture if we look at other assets, such as Bitcoin
```{code-cell} ipython3
:tags: [hide-output]

data = yf.download('BTC-USD', '2015-1-1', '2022-7-1')
Bitcoin_data = pd.read_csv("datasets/Bitcoin_data.csv")
# Convert columns to numeric
for col in ['Price', 'Close', 'High', 'Low', 'Open', 'Volume']:
Bitcoin_data[col] = pd.to_numeric(Amazon_data[col], errors='coerce')
```

```{code-cell} ipython3
Expand All @@ -229,8 +224,8 @@ mystnb:
caption: Daily Bitcoin returns
name: dailyreturns-btc
---
s = data['Close']
r = s.pct_change()
s = Bitcoin_data['Close']
r = s.pct_change(fill_method=None)

fig, ax = plt.subplots()

Expand Down