The Python implementation of an stock analysis and visualization tool.
Project description
StockInsider
This is a Python tool to collect Chinese stock price information, calculate the trading indicators for analysis and visualize stock price and indicator lines.
How to use the tool
Installation
You can choose to either download it from PyPI through:
pip install StockInsider
or fork and clone the repo to your local device, and install the dependencies through:
git clone git@github.com:charlesdong1991/StockInsider.git
cd StockInsider
pip install -r requirements.txt
Tool Overview
The main tool is called StockInsider
, and it takes in two parameters:
code
which is mandatory and an optional ktype
argument. Once
the tool is initiated, the data is being stored under the hood.
First, you need to explicitly type the full code of the stock you
would like to analyze, e.g. sz002156
or sh603019
. Be aware that
only stocks traded in Shanghai and Shenzhen Stock Exchange can be
collected, thus the code to put has to start with either sh
or sz
.
ktype
is the frequency of the aggregated stock price, default is D
which refers to daily stock price, and other allowed values are W
(weekly) and M
(monthly).
from insider import StockInsider
si = StockInsider("sz002516")
Stock Price Visualization
Once initiation, you could use the tool to plot stock price and the corresponding indicators over time.
In order to plot the stock price, you could simply do:
si.plot()
And there are other options for you:
- You could to select only certain number of recent trading days
to plot by changing the
head
parameters, default is 90. - You could choose a start/end date of stock prices to plot by defining
start_date
andend_date
. - If you would like to only have the k-lines hidden in the plot, you
can set
verbose
toFalse
.
Stock Trading Indicator Visualization
Currently, there are many commonly used indicators supported in this tool:
- MA (Moving Average):
si.plot_ma()
- MD (Moving Deviation):
si.plot_md()
- EMA (Exponential Moving Average):
si.plot_ema()
- MACD (Moving Average Convergence/Divergence):
si.plot_macd()
- KDJ:
si.plot_kdj
- RSI (Relative Strength Index):
si.plot_rsi()
- VRSI (Volumn Relative Strength Index):
si.plot_vrsi()
- Volumn change:
si.plot_volumn()
- VMA (Volumn Moving Average):
si.plot_vma()
- VSTD:
si.plot_vstd()
- VMACD (Volumn Moving Average Convergence/Divergence):
si.plot_vmacd()
And there are several options to tune with:
- Choose to plot with the stock price by defining
verbose
toTrue
- Choose the number of recent trading days of stock information to
plot via setting
head
. - Choose which indicators are included in the plot, e.g. only plot
5-day
and60-day
line of MA indicator by settingns
to[5, 60]
.
And some other more for specific indicators, please check out the docstrings.
Get the stock data in Pandas DataFrame
If you would love to play with the data and do some other more fancy stuff,
you could also use the tool as a scrapper. Simply use si.show_data()
could return the data in Pandas DataFrame.
Gallery
- Example1
si = StockInsider("sh603019")
si.plot(head=120, verbose=True)
- Example2
si = StockInsider("sz002156")
si.plot_ma(head=90, verbose=False)
- Example3
si = StockInsider("sz002156")
si.plot_ema(ns=[5, 20, 60], verbose=True)
- Example4
si = StockInsider("sz002156")
si.plot_macd()
- Example5
si = StockInsider("sh603019")
si.plot_kdj(head=90, smooth_type="sma", n=7)
- Example6
si = StockInsider("sh603019")
si.plot_rsi(head=80, ns=[6, 12])
- Example7
si = StockInsider("sh603019")
si.plot_vma(verbose=True)
- Example8
si = StockInsider("sh603019")
si.plot_vmacd(head=60)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.