Code
import pytimetk as tk
import pandas as pd
import numpy as np
tk.augment_rolling_apply()
Timetk is designed to work with any time series domain. Arguably the most important is Finance. This tutorial showcases how you can perform Financial Investment and Stock Analysis at scale with pytimetk
. This applied tutorial covers financial analysis with:
tk.plot_timeseries()
: Visualizing financial datatk.augment_rolling()
: Moving averagestk.augment_rolling_apply()
: Rolling correlations and rolling regressionsLoad the following packages before proceeding with this tutorial.
Financial data from sources like openbb
or yfinance
come in OHLCV format and typically include an βadjustedβ price (adjusted for stock splits). This data has the 3 core properties of time series:
Letβs take a look with the tk.glimpse()
function.
<class 'pandas.core.frame.DataFrame'>: 16194 rows of 8 columns
symbol: object ['META', 'META', 'META', 'META', 'META', 'M ...
date: datetime64[ns] [Timestamp('2013-01-02 00:00:00'), Timestam ...
open: float64 [27.440000534057617, 27.8799991607666, 28.0 ...
high: float64 [28.18000030517578, 28.46999931335449, 28.9 ...
low: float64 [27.420000076293945, 27.59000015258789, 27. ...
close: float64 [28.0, 27.770000457763672, 28.7600002288818 ...
volume: int64 [69846400, 63140600, 72715400, 83781800, 45 ...
adjusted: float64 [28.0, 27.770000457763672, 28.7600002288818 ...
Visualizing financial data is critical for:
We can visualize financial data over time with tk.plot_timeseries()
:
plotly
plot is returned by default. A static plot can be returned by setting engine = "plotnine"
.smooth = False
.tk.plot_timeseries()
help(tk.plot_timeseries)
to review additional helpful documentation.An interactive plotly
plot is returned by default. Interactive is useful for fast data exploration and for use in web apps (e.g. streamlit
, shiny
, dash
), Click to expand code template.