How To Calculate Stocks Support And Resistance Using Clustering
In this notebook, I will show you how to calculate Stocks Support and Resistance using different clustering techniques.
Stock Data - I have stocks data in mongo DB. You can also get this data from Yahoo Finance for free.
MongoDB Python Setup
In [1]:
import pymongo from pymongo import MongoClient client_remote = MongoClient('mongodb://localhost:27017') db_remote = client_remote['stocktdb'] collection_remote = db_remote.stock_data
Get Stock Data From MongoDB
I will do this analysis using last 60 days of Google data.
In [2]:
mobj = collection_remote.find({'ticker':'GOOGL'}).sort([('_id',pymongo.DESCENDING)]).limit(60)
Prepare the Data for Data Analysis
I will be using Pandas and Numpy for the data manipulation. Let us first get the data from Mongo Cursor object to Python list.
In [3]:
prices = [] for doc in mobj: prices.append(doc['high'])
Stocks Support and Resistance Using K-Means Clustering
In [4]:
import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.cluster import AgglomerativeClustering
For K means clustering, we need to get the data in
from Planet SciPy
read more
No comments:
Post a Comment