Python Forum
Stock clustering and portfolio diversification. Suitable features.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stock clustering and portfolio diversification. Suitable features.
#1
Hi. I want to conduct a research. I want to cluster stocks and then make a safe diversified portfolio. I want to work with annual data. From price data I took beta coefficient and average price change. I also want to use companies reports to take some fundamental data, especially multipliers. Aiming to build a diversified portfolio, what multipliers can I take from the company's annual reports? Maybe someone had an experience? Thanks in advance for answers!
Reply
#2
The yahoo finance package will get you the historic information you need
reference: https://pypi.org/project/yfinance/

simple code to get one years data:

import yfinance as yf
import pandas as pd
from pathlib import Path

# supply ticker symbol:
symbol = "NVDA"

ticker = yf.Ticker(symbol)

# get one years historical data data is formatted as (data will be pandas dataframe)
data = ticker.history(period="1y")

# to save as csv (change path as desired)
currentpath = Path(".")
savefilename = currentpath / f"{symbol}_History_1yr.csv"
data.to_csv(savefilename, index=False)
first few lines of file :
Output:
Open,High,Low,Close,Volume,Dividends,Stock Splits 268.28396165972663,269.91344399919114,263.5654735665401,265.2249450683594,36102600,0.0,0.0 264.3851962988121,265.0449883242188,258.4171094180526,264.01531982421875,35610400,0.0,0.0 268.1639924579148,270.6931800574298,265.88472470225616,269.75347900390625,39369400,0.0,0.0 272.20270324123067,274.90181922605285,270.9330909208125,273.7421875,36451600,0.0,0.0 271.3129559427999,278.250732726046,270.96306208621024,277.680908203125,43393300,0.0,0.0 275.00179770776697,279.91022713743365,273.272341393005,279.5603332519531,39871600,0.0,0.0
as for the clustering, see this
click on Lecture 7 for slides.

Also, this blog looks interesting
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  K Means Clustering antouanet 0 690 Jan-30-2023, 01:18 PM
Last Post: antouanet
  Parametric portfolio optimization by Brandt 2009 schnellinga 5 2,947 Jul-26-2022, 07:16 PM
Last Post: paulyan
  How to find the impact of each of the correlated features? AlekseyPython 0 1,415 Sep-28-2021, 09:05 AM
Last Post: AlekseyPython
  Suitable Data Modelling Packages JoeDainton123 3 95,430 Jun-27-2021, 01:43 PM
Last Post: Caprone
  Clustering for imbalanced data sets dervast 0 1,626 Sep-25-2019, 06:34 AM
Last Post: dervast
  text clustering evaluation ?? khalidreemy 1 2,182 May-29-2019, 03:10 AM
Last Post: heiner55
  Clustering based on a variable and on a distance matrix flucoe 2 6,242 Dec-16-2018, 09:57 PM
Last Post: flucoe
  Is Python Suitable? summerleas 3 4,131 Feb-28-2017, 12:19 PM
Last Post: merlem
  Sklearn Agglomerative Hierarchical Clustering - help with array set up pstarrett 4 5,321 Feb-21-2017, 05:05 AM
Last Post: pstarrett

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020