Stock is trend for investment and financial management. People can make a great amount of earnings from it. Simultaneously they can also loose a great amount of money from it. Wherefore, a great stock visualize tool can boost trading efficiency. Moreover, it would be best if there's an add-on predicting tool to assist investors. This post details how to build a stock visualizing and predicting site with twelvedata and streamlit.
- How to Start (build process)
- Details of Approach
- Results
- References
To create and activate a conda environment (Python 3.7.10):
conda create -n stock python==3.7.10
To check if your environment is successfully created:
conda env list
Activate conda environment:
conda activate stock
To install the project's dependencies:
pip install -r requirements.txt
After creating your environment, visit twelvedata to obtain your API key:

To check if your API key is valid, run the example below.
from twelvedata import TDClient
# Initialize client - apikey parameter is requiered
td = TDClient(apikey="YOUR_API_KEY_HERE")
# Construct the necessary time serie
ts = td.time_series(
symbol="TSLA",
interval="1min",
outputsize=10
)
# Returns pandas.DataFrame
print(ts.as_pandas())
You are all set to build The Best stock visualizing and predicting site.
This project is divided into two parts, the workflow is display as below:

-
Generating LSTM models
In this part we generate LSTM for different stocks, by using tensorflow and keras.
- Obtain the data with twelvedata API
- Scale the data with MinMaxScaler with the range 0 to 1
- Re-organize the data, we choose to use 60 previous days of data to predict the 'close' price today
- Feed the data for training the LSTM model
- Finally, we output the model for later on usage
-
Build main site
The main site is built with different sections of information, including historical data, predicted price etc.
-
In the left pane, users can choose the stock with a certain time duration they want to visualize and predict

-
In the top right column, we display realtime data of selected stock. Users can also select the time interval they like

-
In the bottom right column, the predicted stock price is displayed. Users can choose the number of days of predictions they want to visualize

- API
- Libraries: Tensorflow, sklearn, streamlit, plotly
- Data used:APPL historic stock data, AMZN historic stock data, TSLA historic stock data

