Downloading and modifying data

Here, we will download the data from the sources mentioned in the codes variable, and we will put them into our closings data frame. We will store the original data, scaled data, and the log_return:

codes = ["WSE/OPONEO_PL", "WSE/VINDEXUS", "WSE/WAWEL", "WSE/WIELTON", "WIKI/SNPS"] 
closings = pd.DataFrame() 
for code in codes: 
    code_splits = code.split("/") 
    stock_exchange = code_splits[0] 
    index = code_splits[1] 
    stock_data = requests.get(base_url.format(stock_exchange,  
index)).json() dataset_data = stock_data['dataset_data'] data = np.array(dataset_data['data']) closings[index] = pd.Series(data[:, 1].astype(float)) closings[index + "_scaled"] = closings[index] /
max(closings[index]) closings[index + "_log_return"] = np.log(closings[index] / closings[index].shift()) closings = closings.fillna(method='ffill') # Fill the gaps in data

We scaled the data so that the stock values stay between 0 and 1; this is helpful for minimizing compared to other stock values. It will help us see trends in the stock compared to other markets and will make it visually easier to analyze.

The log returns help us get a graph of the market rising and falling compared to the previous day.

Now let's see how our data looks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.59