Skip to content

Jinruizhang01/StockInsider

 
 

Repository files navigation

StockInsider

Package Version Contributions welcome License build

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 to install the latest version:

pip install -U git+https://github.com/charlesdong1991/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 and end_date.
  • If you would like to only have the k-lines hidden in the plot, you can set verbose to False.

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()
  • ENV: si.plot_env()
  • VOSC (Volumn Oscillator): si.plot_vosc()
  • MI (Momentum Indicator): si.plot_mi()
  • MIKE: si.plot_mike()
  • ADTM: si.plot_adtm()
  • OBV (On Balance Volumn): si.plot_obv()

And there are several options to tune with:

  • Choose to plot with the stock price by defining verbose to True
  • 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 and 60-day line of MA indicator by setting ns 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.

Get the calculated indicator data in Pandas DataFrame

If you do not like the plot, and want to do other fancy analysis or visualization, it is certainly okay! And you just need to call the indicator name, e.g. si.vosc(), or si.macd(), then it will return the subset with those indicators in it.

Gallery

  • Example1
si = StockInsider("sh603019")
si.plot(head=120, verbose=True)

Example 1

  • Example2
si = StockInsider("sz002156")
si.plot_ma(head=90, verbose=False)

Example 2

  • Example3
si = StockInsider("sz002156")
si.plot_ema(ns=[5, 20, 60], verbose=True)

Example 3

  • Example4
si = StockInsider("sz002156")
si.plot_macd()

Example 4

  • Example5
si = StockInsider("sh603019")
si.plot_kdj(head=90, smooth_type="sma", n=7)

Example 5

  • Example6
si = StockInsider("sh603019")
si.plot_rsi(head=80, ns=[6, 12])

Example 6

  • Example7
si = StockInsider("sh603019")
si.plot_vma(verbose=True)

Example 7

  • Example8
si = StockInsider("sh603019")
si.plot_vmacd(head=60)

Example 8

  • Example9
si = StockInsider("sh603019")
si.plot_env(verbose=True, head=60)

Example 9

  • Example10
si = StockInsider("sh603019")
si.plot_mike(head=60, ns=["ws", "wr"], verbose=True)

Example 10

  • Example11
si = StockInsider("sh603019")
si.plot_adtm(head=120)

Example 11

Donation (打赏)

It takes time and efforts to make the tool, and if you like it, you could also support the author by donation via Wechat Pay :)

About

A Python tool to collect, analyze and visualize trading indicators for stocks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%