Moozzart / Meyer-Packard-Genetic-Algorithm-for-Prediction-of-Stock-Prices-and-Performances

Stock Market predictions are one of the most difficult problems to solve, and during the looming days of recession it’s extremely difficult and next to impossible to do. This is because there are numerous patterns in the stock prices trend throughout the day and every variation from the normal trend could mean something new, since stocks is ever expanding and hence new problems and pattern in the trends are visible which needs to be studied but these new trends are usually generated each and every day possible of the trade and to keep up with the change is a very lofty task to do especially for an individual who has a large or even semi large portfolio to maintain over a period of time. Stocks and bonds are immensely important for a country’s economy to boom and it’s collapse means the collapse of country’s economy and since these markets are linked with every possible sector that contribute to the economy, mostly organised sectors, it’s collapse would be seen on every sector linked in those markets by what the economists call as “Ripple effect” and this goes other way around as well that if a particular sector’s firm performs poorly, then that would be reflected in the other firms of that sector.
15 stars 2 forks source link

Yahoo finance url is not getting fetched #1

Open Sainath26 opened 2 years ago

Sainath26 commented 2 years ago

When I run the .py file, this error pops up.

urllib.error.HTTPError: HTTP Error 404: Not Found

the Yahoo finance url is not getting fetched for some reason. Do you know why is that happening?

Also, can you please share what gets stored in the stock data file

chrislazar25 commented 1 year ago

use y finance instead so the generate function would look something like this,

in the import section : !pip install yfinance import yfinance

and GenerateData section:

def generateData(self): global DataSize

Download the data from yahoo finance for last 365 days

    data = []
    stock_data = yf.download(Stock_name, start='2022-03-01', end='2023-03-01')
    #url = "https://finance.yahoo.com/quote/" + Stock_name + "/history/"
    #rows = bs(urllib2.urlopen(url).read(), "lxml").findAll('table')[0].tbody.findAll('tr')
    #for each_row in rows:
     #   divs = each_row.findAll('td')
      #  if divs[1].span.text  != 'Dividend': #Ignore this row in the table
            #I'm only interested in 'Open' price; For other values, play with divs[1 - 5]
       #     data.append({'open': divs[1].span.text, 'Adj close': float(divs[5].span.text.replace(',',''))})
    #data[:NumberOfDay]
    #print(data)
    file = open('stock_data', 'w')
    #closes = [c['Adj close'] for c in data]
    #opens = [o['open'] for o in data]
    oArray = stock_data['Open'].tolist()[::-1]
    cArray = stock_data['Adj Close'].tolist()[::-1]