mirror of
https://github.com/jupyter-naas/awesome-notebooks.git
synced 2024-05-28 02:00:17 +03:00
243 lines
6.1 KiB
Plaintext
243 lines
6.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "88c104cc-bf08-4242-821b-b3a40908152a",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"<img width=\"8%\" alt=\"Naas.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/Naas.png\" style=\"border-radius: 15%\">"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "compressed-wilson",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"# Tool - Action of the notebook"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "religious-programmer",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Tags:** #tool"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "1fe9f56e-561c-4f52-aef8-b861c9462107",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Author:** [Firstname Lastname](https://www.linkedin.com/)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0de144be-594d-463e-9849-696fb2f6d1a8",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Last update:** YYYY-MM-DD (Created: YYYY-MM-DD)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "31ea7cdb-e10d-43fc-b026-f69249a59736",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Description:** This notebook demonstrates how to ... -> a one-liner explaining the benefits of the notebooks for the user, as text."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d4b89388-5cd5-409a-8169-c53cc8dfab96",
|
|
"metadata": {},
|
|
"source": [
|
|
"**References:**\n",
|
|
"- [Naas Documentation](https://site.naas.ai/)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "distinguished-truth",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## Input"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "numeric-mediterranean",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Import libraries\n",
|
|
"Libraries to be used within the notebook.<br>\n",
|
|
"If these libraries are not installed on Naas, ensure they are installed during the first execution by using a `try`/`except` function to import the package."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "potential-surfing",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from naas_drivers import yahoofinance"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "aggressive-trustee",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Setup variables\n",
|
|
"Variables used in this notebook should be categorized as either mandatory or optional and should be clearly described. The aim of defining these variables in the input section is to facilitate use of the notebook by any user, allowing them to interact with it without the need to modify functions in the model section.\n",
|
|
"\n",
|
|
"\n",
|
|
"**Mandatory**\n",
|
|
"\n",
|
|
"- `stock_name`: This variable represents the stock symbol for which you want to fetch data. In this case, 'NFLX' stands for Netflix.\n",
|
|
"\n",
|
|
"\n",
|
|
"**Optional**\n",
|
|
"\n",
|
|
"- `date_from`: This variable defines the starting date from which you want to fetch the stock data. It's set to '-3600', which likely represents 3600 days before the current date.\n",
|
|
"- `date_to`: This variable defines the end date up to which you want to fetch the stock data. When set to 'today', it fetches data up to the current date.\n",
|
|
"- `moving_averages`: This is a list of integers representing the number of days for which you want to calculate the moving average of the stock price. In this case, moving averages will be calculated for the past 20 and 50 days.\n",
|
|
"- `csv_output`: This variable represents the name of the CSV file where the fetched data will be saved. In this case, the file will be named 'MY_OUTPUT.csv'."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "continuous-melbourne",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Mandatory\n",
|
|
"stock_name = 'NFLX'\n",
|
|
"\n",
|
|
"# Optional\n",
|
|
"date_from = -3600\n",
|
|
"date_to = \"today\"\n",
|
|
"moving_averages = [20, 50]\n",
|
|
"csv_output = \"MY_OUTPUT.csv\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "registered-showcase",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Model"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "tested-astrology",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Get data from yahoo finance"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "crude-louisville",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = yahoofinance.get(\n",
|
|
" stock_name,\n",
|
|
" date_from=date_from,\n",
|
|
" date_to=date_to,\n",
|
|
" moving_averages=moving_averages\n",
|
|
")\n",
|
|
"df"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "lonely-pacific",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-07-02T23:32:10.789097Z",
|
|
"iopub.status.busy": "2021-07-02T23:32:10.788829Z",
|
|
"iopub.status.idle": "2021-07-02T23:32:10.796900Z",
|
|
"shell.execute_reply": "2021-07-02T23:32:10.796358Z",
|
|
"shell.execute_reply.started": "2021-07-02T23:32:10.789033Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"## Output"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "890f7c86-b7bb-4f5d-9a1b-e492dd9580fd",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Save DataFrame to csv"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9c4e3b7b-6440-4844-8054-265f1aec65eb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df.to_csv(csv_output, index=False)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.9.6"
|
|
},
|
|
"papermill": {
|
|
"default_parameters": {},
|
|
"environment_variables": {},
|
|
"parameters": {},
|
|
"version": "2.3.3"
|
|
},
|
|
"widgets": {
|
|
"application/vnd.jupyter.widget-state+json": {
|
|
"state": {},
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|