Time Series Data Plot ===================== Introduction ------------ In this example, we are introducing our plot engine for the time series data and stock data. We are able to create a general plot like scatter plot, bar chart, line chart and more graphs based on the input. To be more specific, this package is also able to create the candle plot in one line of code. .. code:: ipython3 import numpy as np import pandas as pd from time_series_transform.stock_transform import * from time_series_transform.plot import * from time_series_transform.io import * from time_series_transform import (Time_Series_Transformer,Stock_Transformer) To extract the stock data, we can use the **from_stock_engine_period** and **from_stock_engine_date** from the **Stock_Transformer** class. 1. symbols: **string** of the symbol or a **list** of the symbols 2. start_date/end_date: **string** of the date in the format of %Y-%m-%d, eg. “2020-02-20” (used in from_stock_engine_date) 3. period: **string** of the period, eg. “1y” (used in from_stock_engine_period) 4. engine: **string** of the engine, valid input: *yahoo*, *investing* In this example, we will create 3 types of data for demonstration. **ts_data**: Time_Series_Data, which is a general time series data **stock_data**: Stock data which contains data of a single stock **port_data**: Portfolio data which contains a list of Stock data .. code:: ipython3 data = pd.DataFrame({'time':[1,2,3,4,5,6,7,8,9,10],'x1':[1,2,3,4,5,6,7,8,9,10],'x2':[6,7,8,9,10,16,27,38,49,50]}) ts_data = Time_Series_Transformer(data, 'time') stock_data = Stock_Transformer.from_stock_engine_date("aapl", "2020-02-01", "2020-12-10", "yahoo") port_data = Stock_Transformer.from_stock_engine_period(["aapl", "msft", "amzn"], "1y" , "yahoo") print("ts_data: ") print(to_pandas(ts_data.time_series_data,None,False,None).head()) print("===============================") print("stock_data: ") print(to_pandas(stock_data.time_series_data, None, False, None).head()) print("===============================") print("port_data (amzn data): ") print(to_pandas(port_data.time_series_data['amzn'], None, False, None).head()) print("===============================") .. parsed-literal:: ts_data: time x1 x2 0 1 1 6 1 2 2 7 2 3 3 8 3 4 4 9 4 5 5 10 =============================== stock_data: Date Open High Low Close Volume \ 0 2020-01-31 79.545540 79.979294 76.412600 76.714989 199588400 1 2020-02-03 75.423639 77.701469 74.908095 76.504311 173985600 2 2020-02-04 78.152574 79.225810 77.736172 79.029999 136616400 3 2020-02-05 80.187502 80.494853 79.054790 79.674438 118826800 4 2020-02-06 79.952039 80.608865 79.379484 80.606384 105425600 Dividends Stock Splits 0 0.0 0.0 1 0.0 0.0 2 0.0 0.0 3 0.0 0.0 4 0.0 0.0 =============================== port_data (amzn data): Date Open High Low Close Volume \ 0 2020-01-06 1860.000000 1903.689941 1860.000000 1902.880005 4061800 1 2020-01-07 1904.500000 1913.890015 1892.040039 1906.859985 4044900 2 2020-01-08 1898.040039 1911.000000 1886.439941 1891.969971 3508000 3 2020-01-09 1909.890015 1917.819946 1895.800049 1901.050049 3167300 4 2020-01-10 1905.369995 1906.939941 1880.000000 1883.160034 2853700 Dividends Stock Splits 0 0 0 1 0 0 2 0 0 3 0 0 4 0 0 =============================== Time_Series_Plot ---------------- This package provides the plot function for the time series data. We can simply create the plot using the **create_plot** function, or simply call the **.plot** from the transformer, or just use **.plot.line**. Functions ~~~~~~~~~ The Plot module has several functions to support figure with more details. Trace data '''''''''' 1. add_line 2. remove_line 3. add_marker Layout '''''' 1. update_layout 2. remove_subplot *User is able to add new subplot by changing the value of subplot in the add_line function* .. code:: ipython3 tsp = ts_data.plot(cols=['x1','x2'], title = 'sample title', type = 'scatter') tsp .. raw:: html .. raw:: html