Skip to content

Forecasting stock price based on historical price data using Python. Recommend a buy/sell action based on price features.

Notifications You must be signed in to change notification settings

yepterence/Stock-Analysis

Repository files navigation

Forecasting price time-series based on historical values and classifying a buy/sell action using supervised machine learning

Image of stock chart
Source: Getty Images

Quick start guide

In command line interface:

  • pip install -r requirements.txt
  • Download notebook Stock-data-exploration.ipynb (non-notebook interactive work coming soon-ish)
  • jupyter notebook Stock-data-exploration.ipynb
  • Run all cells

Introduction

When evaluating the price of a business/stock, there are two schools of thought: Fundamental Analysis, which measures the stock's intrinsic value by studying the economy, industry the company operates in and the company itself. And technical analysis, which evaluates trading opportunities from analyzing price movement and volume. Apart from that, we also need to take into consideration how traders will react to macroeconomic trends, financial news, market anouncements, analyst forecasts to name a few.

Problem statement

Daily stock price data is in essence a time-series, where a security’s price, over a specified period of time with data points recorded at regular intervals. We can then predict future activity based on the patterns associated to the time-series. This relates to trend analysis, cyclical fluctuation analysis, and issues of seasonality. So how does one go about predicting the price for a given security? Is it possible to leverage machine learning using price data alone to forecast tomorrow's price? How about six months from now? And can we accurately recommend entry and exit trade opportunities so that we can maximize profits and minimize losses?

We will attempt to answer those questions by:

  • Investigating various machine learning models to forecast the price of Microsoft (MSFT)
  • Recommend a buy/sell action based on predictions.

Who Cares?

This type of problem is typically encountered by Financial institutions:

  • Fund/Portfolio Managers
  • Investment Analysts
  • Retail investors

But beyond financial institutions, the method can virtually be applied to problems that involve time-series. For eg, hardware failure due to wear and tear, weather pattern prediction to name some applications that currently use similar methods to forecast trends.

Data sources

  • Yahoo Finance api
  • Quandl api

Visualization

image of candlestick chart
Fig I. Candlestick chart of MSFT over 3 years. Overlayed 50, 100 and 200 day moving average plots. image of candlestick chart
Fig II. Momentum indicators (MACD, Stochastic oscillator, RSI)

Limitations

As mentioned earlier, we're trying to forecast the price based on historical price data.

  • Biases

    • Buy/sell labels were generated based on user's understanding of investment strategies.
  • Incomplete information

    • Macro trends were not considered.
    • Financials of company not considered.
    • News not considered.

About

Forecasting stock price based on historical price data using Python. Recommend a buy/sell action based on price features.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published