Skip to main content

A tool for stock price visulization and forecasting

Project description

Python Package using Conda

StockTool

A Tool for visualizing, analyzing, forecasting, and evaluating the stock price, and give user investment strategy suggestions.

Overview

One investor might want to predict the trend for a specific stock, and to know which stock is better to invest in based on the past stock price. As stock market changing so rapidly, it might be hard to make the right investment strategy by analyzing the data manually. Thus, we built a tool for users to visualize, analyze, forecast and evaluate stocks.

Requirements

StockTool requires a Python environment higher than Python 3.6.

Installation

  • Method 1: Install from the Pipit

    pip install stocktool

    If this does not work, run this command first:

    pip install datetime pandas_datareader plotly sktime tbats requests_cache pandas_market_calendars

  • Method 2: Install from the GitHub repo

    pip install git+https://github.com/Ko2259/StockTool.git

  • Method 3: Clone this repository and set up a virtual environment(suggested method due to the dependencies)

    1. Open the terminal
    2. Clone the repository using git clone git@github.com:Ko2259/StockTool.git
    3. Change the directory to StockPrice using cd StockTool
    4. Set up a new virtual environment using conda env create -f environment.yml
    5. Activate the virtual environment using conda activate stocktool
    6. After finish analyzing, deactivate the virtual environment using conda deactivate

Usage

Repository Structure

.
├── LICENSE
├── README.md
├── docs
│   ├── Functional_Specification.md
│   ├── milestone.md
├── environment.yml
├── example
│   ├── evaluation.ipynb
│   ├── model.ipynb
│   └── visualization.ipynb
└── stocktool
    ├── evaluation
    ├── model
    ├── tests
    └── visualization

The stocktool directory includes visualization module for visualize stocks, model module for analyze and forecast future stock price, evaluation module for evaluate invest profit, and unit tests in tests module. The example directory provides examples which help new users learn how to use this tool.

Data access

  • After you installing this tool on your local machine or on a virtual environment, and importing this tool using import stocktool, you can access stock data with built-in function below, where we read stock data through Yahoo Finance API.

    data = stocktool.StockData(stocks, start, end, period)

  • In the function StockData:

    1. you can specify one stock, or many stocks with their Dow Jones Index;
    2. you can specify the start date and the end date, or you can only specify the start date along with a specified period.
  • Then you'll get a data structure containing the pandas dataframes, start date, end date and open days.

    1. data.df: a dictionary contains pandas dataframe for each stock
    2. data.start: adjust input start date to a stock market open day
    3. data.end: adjust input end date to a stock market open day
    4. data.open_days: stock market open days

Example please refer to StockTool/examples/visualization.ipynb.

Visualization

  • After you accessing the data, you can visualize it with our built-in functions, or you can make some other plots on your own.

  • Below are the visualization functions in our tool:

    1. data.box_plot(): to see the fluctuation for each stock during this period
    2. data.price_plot(): to see the stock price for each stock on every market open day
    3. data.candle_plot(): to see the candlestick chart for each stock on every market open day

Example please refer to StockTool/examples/visualization.ipynb.

Forecasting

  • After you accessing the data, you can train the data as below:

    model = stocktool.StockPrediction(data, val), where val="Close" or val="Open"

    Or you can construct the model without accessing the data first:

    model = stocktool.StockPrediction(val, stocks, start, end, period)

  • After you training the model, you can forecast the stock price in next few days.

    model.predict(days, level): a dictionary contains the prediction for each stock, along with the confidence interval

  • You may also want to update the model with new data points, so you can update it with stock data till a new end date.

    1. first update model: model.update(date)
    2. then forecast using updated model: model.predict()

Example please refer to StockTool/examples/model.ipynb.

Evaluation

  • After training data in model, we build a method to evaluate our two investment strategies.

    1. With specified asset, the first strategy is to invest in the stock with highest predicted profit every day.
    2. The second strategy is to split asset to invest in all stocks with positive predicted profit every day.
  • Here, we evaluate as below:

    1. first get the evaluation structure: eva = stocktoll.StockEvaluation(model, asset)
    2. after getting the evaluation structure, evaluate the strategy: eva.evaluate(days, weighted, graph)
    3. after evaluation, draw the graph of real stock price and predicted price: eva.graph(stocks, days)

Example please refer to StockTool/examples/evaluation.ipynb.

But Report

If you have any issue or bug when running this tool, please submit a New issue in Issues.

Acknowledgements

Thanks Prof. David Beck and Erin Wilson from University of Washington for their support, help and feedback in developing this tool.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stocktool-1.1.1.tar.gz (7.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stocktool-1.1.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file stocktool-1.1.1.tar.gz.

File metadata

  • Download URL: stocktool-1.1.1.tar.gz
  • Upload date:
  • Size: 7.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.13

File hashes

Hashes for stocktool-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ac8b9f4c6483b791d953fe291fb9f5eb7fd2fde5c6bc27e78cd907f361215a4c
MD5 79fb982f77a0e660ee306e25aab6c360
BLAKE2b-256 f5320549cb7d2ca6272a07e44926ae51ad4d0af005c1b4bceb87618c1a63fe4c

See more details on using hashes here.

File details

Details for the file stocktool-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: stocktool-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.13

File hashes

Hashes for stocktool-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f272cb6302273ecfc9e65a19bc8a1cd93adfd9511f4d331a6f21cd84219c3127
MD5 e722a55c295fbd1422f6ea3f98db7d98
BLAKE2b-256 25699db158e5a2715b257f861af027596a51398a77051bcc09ad859c87ed3e7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page