{ "cells": [ { "cell_type": "markdown", "id": "670316b8-460c-4009-a5da-94278f4ac9a9", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "source": [ "# Time Series" ] }, { "cell_type": "code", "execution_count": 1, "id": "52af59bb-083c-46c6-989a-bd4c65137a1a", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Import to be able to import python package from src\n", "import sys\n", "sys.path.insert(0, '../src')" ] }, { "cell_type": "code", "execution_count": 2, "id": "4aed48a7-3452-4632-b1d5-e501893c6078", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['../src', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/benjy/.cache/pypoetry/virtualenvs/ontime-2OQVvbNf-py3.10/lib/python3.10/site-packages', '/home/benjy/projects_dev/ontime/src']\n" ] } ], "source": [ "print(sys.path)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d6fc731f-3f50-4e9a-a24c-b2ab01d4fa31", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import ontime as on" ] }, { "cell_type": "markdown", "id": "831f1944-599b-4761-a071-2a682346610a", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Generation of random time series" ] }, { "cell_type": "code", "execution_count": 4, "id": "ef3e03e1-c247-4b5a-a27a-a13361e673b0", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "ts = on.generators.random_walk().generate(start=pd.Timestamp('2022-01-01'), end=pd.Timestamp('2022-12-31'))" ] }, { "cell_type": "code", "execution_count": 5, "id": "01962643-33af-4adf-8bfa-7d0163e4e41c", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<TimeSeries (DataArray) (time: 5, component: 1, sample: 1)> Size: 40B\n",
"array([[[0.18681962]],\n",
"\n",
" [[1.38205429]],\n",
"\n",
" [[1.85408518]],\n",
"\n",
" [[1.01011117]],\n",
"\n",
" [[0.37180233]]])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 40B 2022-01-01 2022-01-02 ... 2022-01-05\n",
" * component (component) object 8B 'random_walk'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None<TimeSeries (DataArray) (Month: 5, component: 1, sample: 1)> Size: 40B\n",
"array([[[112.]],\n",
"\n",
" [[118.]],\n",
"\n",
" [[132.]],\n",
"\n",
" [[129.]],\n",
"\n",
" [[121.]]])\n",
"Coordinates:\n",
" * Month (Month) datetime64[ns] 40B 1949-01-01 1949-02-01 ... 1949-05-01\n",
" * component (component) object 8B '#Passengers'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None<TimeSeries (DataArray) (Month: 5, component: 1, sample: 1)> Size: 40B\n",
"array([[[112.]],\n",
"\n",
" [[118.]],\n",
"\n",
" [[132.]],\n",
"\n",
" [[129.]],\n",
"\n",
" [[121.]]])\n",
"Coordinates:\n",
" * Month (Month) datetime64[ns] 40B 1949-01-01 1949-02-01 ... 1949-05-01\n",
" * component (component) object 8B '#Passengers'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None| \n", " | Open | \n", "High | \n", "Low | \n", "Close | \n", "Adj_Close | \n", "Volume | \n", "
|---|---|---|---|---|---|---|
| time | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 1980-03-17 | \n", "0.0 | \n", "3.302083 | \n", "3.125000 | \n", "3.145833 | \n", "3.145833 | \n", "219600 | \n", "
| 1980-03-18 | \n", "0.0 | \n", "3.125000 | \n", "2.937500 | \n", "3.031250 | \n", "3.031250 | \n", "727200 | \n", "
| 1980-03-19 | \n", "0.0 | \n", "3.083333 | \n", "3.020833 | \n", "3.041667 | \n", "3.041667 | \n", "295200 | \n", "
| 1980-03-20 | \n", "0.0 | \n", "3.062500 | \n", "3.010417 | \n", "3.010417 | \n", "3.010417 | \n", "159600 | \n", "
| 1980-03-21 | \n", "0.0 | \n", "3.020833 | \n", "2.906250 | \n", "2.916667 | \n", "2.916667 | \n", "130800 | \n", "
<TimeSeries (DataArray) (time: 5, component: 6, sample: 1)> Size: 240B\n",
"array([[[0.00000000e+00],\n",
" [3.30208302e+00],\n",
" [3.12500000e+00],\n",
" [3.14583302e+00],\n",
" [3.14583302e+00],\n",
" [2.19600000e+05]],\n",
"\n",
" [[0.00000000e+00],\n",
" [3.12500000e+00],\n",
" [2.93750000e+00],\n",
" [3.03125000e+00],\n",
" [3.03125000e+00],\n",
" [7.27200000e+05]],\n",
"\n",
" [[0.00000000e+00],\n",
" [3.08333302e+00],\n",
" [3.02083302e+00],\n",
" [3.04166698e+00],\n",
" [3.04166698e+00],\n",
" [2.95200000e+05]],\n",
"\n",
" [[0.00000000e+00],\n",
" [3.06250000e+00],\n",
" [3.01041698e+00],\n",
" [3.01041698e+00],\n",
" [3.01041698e+00],\n",
" [1.59600000e+05]],\n",
"\n",
" [[0.00000000e+00],\n",
" [3.02083302e+00],\n",
" [2.90625000e+00],\n",
" [2.91666698e+00],\n",
" [2.91666698e+00],\n",
" [1.30800000e+05]]])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 40B 1980-03-17 1980-03-18 ... 1980-03-21\n",
" * component (component) object 48B 'Open' 'High' ... 'Adj_Close' 'Volume'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None