stratascratch
  • Interview Questions
    • Interview Loops
    • Analytical
    • Algorithm
    • ML Coding
    • Stats Coding
    • Visualization
    • Concept
  • Data Labs
    • Discover
    • Your Notebooks
  • Mock Interview
  • Learn
  • Blog
  • Pricing
  • About
Log in
  • Interview Questions

    • Interview Loops
    • Analytical
    • Algorithm
    • ML Coding
    • Stats Coding
    • Visualization
    • Concept
  • Data Labs

    • Discover
    • Your Notebooks
  • Mock Interview
  • Learn
  • Blog
  • Pricing
  • About
Log inSign up
Back to Projects
  1. Assignment
  2. Your Solution
  3. Solutions from Users
  4. Discussion

Stocks Price Analysis

You must be logged in to download the datasets

Jane Street: Exploring INFY and TCS stock price and volume time series to uncover patterns, insights, and key questions.

Assignment

Part 1:

  1. Create 4,16,....,52 week moving average(closing price) for each stock. This should happen through a function.
  2. Create a rolling window of size 10 on each stock. Handle unequal time series due to stock market holidays. You should look to increase your rolling window size to 75 and see what the data looks like. Remember they will create stress on your laptop RAM load. ( Documentation you might need: http://in.mathworks.com/help/econ/rolling-window-estimation-of-state-space-models.html)
  3. Create the following dummy time series: 3.1 Volume shocks - If volume traded is 10% higher/lower than the previous day - make a 0/1 boolean time series for shock, 0/1 dummy-coded time series for the direction of shock. 3.2 Price shocks - If the closing price at T vs T+1 has a difference > 2%, then 0/1 boolean time series for shock, 0/1 dummy-coded time series for the direction of shock. 3.3 Pricing black swan - If the closing price at T vs T+1 has a difference > 2%, then 0/1 boolean time series for shock, 0/1 dummy-coded time series for the direction of shock. 3.4 Pricing shock without volume shock - based on points 3.1 & 3.2 - Make a 0/1 dummy time series.

Part 2 (data visualization ): For this section, you can use only bokeh.

  1. Create a time-series plot of close prices of stocks with the following features:
  2. Color the time series in simple blue color.
  3. Color time series between two volume shocks in a different color (Red)
  4. Gradient color in blue spectrum based on the difference of 52-week moving average.
  5. Mark closing Pricing shock without volume shock to identify volumeless price movement.
  6. Hand craft partial autocorrelation plot for each stock on up to all lookbacks on bokeh - sample reference - https://www.statsmodels.org/dev/generated/statsmodels.graphics.tsaplots.plot_pacf.html

Part 3 (data modeling) For this section, you should use sklearn.

  1. Quickly build any two models. The quick build is defined as a grid search of less than 9 permutation combinations. You can choose the two options of multiple multivariate models from those mentioned below. The goal is to predict INFY, and TCS prices for tomorrow. Models that you can choose:
    • LassoLars
    • Linear Regression
    • Ridge Regression
    • Support Vector Regression
    • Gradient Boosting Regression
  2. Write test cases for the two models you have chosen. Your testing should take at least 5-time steps except for today. your test cases must be written using pytest.
  3. Prove your model does not violate any basic assumption. To understand "model assumptions", read https://www.albert.io/blog/key-assumptions-of-ols-econometrics-review/
  4. Select the best performing model, and tune it - Demonstrate that your tuning has resulted in a clear difference between quick build and tuning.
  5. Extra credit - Nest a model to predict volume shock into your time series model - same conditions applied as above.
  6. Extra extra credit - Create a bare python file in the following fashion python stockpredictor.py ‘INFY’ should return prediction in less than 100 ms.

Data Description

You are encouraged to use the NSEPY module for loading the data.

The original assignment was based on OCLHV data for NSE stocks with symbols INFY and TCS between 2015-2016 and on a Daily level. However, you can complete this project using any stock data you select. You can also choose other time periods.

Example: loading stock data into a Pandas DataFrame using NSEPY:

!pip install nsepy
import nsepy

infy_df = nsepy.get_history(symbol='INFY',
                    start=date(2015,1,1), 
                    end=date(2015,12,31))

For convinience, we are providing you with the data on INFY and TCS stocks from 2015 in two CSV files: INFY_2015.csv and TCS_2015.csv respectively.

Practicalities

Please work on the questions in the displayed order. Define, train and evaluate predictive models that takes as the input the data provided. You may want to split the data into training, testing and validation sets, according to your discretion.

Make sure that the solution reflects your entire thought process - it is more important how the code is structured rather than the final metrics. You are expected to spend no more than 3 hours working on this project.