Skip to content

Instantly share code, notes, and snippets.

@sailesh8584
Created January 26, 2021 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sailesh8584/a1c3f051d607e184d7511b885b8169ca to your computer and use it in GitHub Desktop.
Save sailesh8584/a1c3f051d607e184d7511b885b8169ca to your computer and use it in GitHub Desktop.
Quantile based approach for historical stock analysis
Display the source blob
Display the rendered blob
Raw
# Import libraries
import pandas as pd
import matplotlib as mp
import matplotlib.pyplot as plt
# Historical stock data available in Excel file
# Asking the user to enter the stock for which the quantile analysis has to be done
stock = input ("Enter Stock Name: ")
xls = pd.ExcelFile('D:\Raw Stock Data1.xlsx')
df1 = pd.read_excel(xls,stock)
# Printing the quantile data for 10th, 20th, 30th, 40th.... upto 100th percentiles (represented as 0.1, 0.2 etc.)
print(df1['Close_Price'].quantile([0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]))
print('Median Price of', stock, 'is Rs', df1['Close_Price'].median())
# Box plot for visualizing the historical stock data in a jiffy
plt.boxplot(df1.Close_Price)
plt.title(stock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment