1
$\begingroup$

this is a newbie question but it's very simple so I'm hoping it's okay to ask.

I would like to calculate the percent change from one quarter to the next using Pandas and use that as my Y-Test (training set) variable.

I am 90% sure it's right but I would like a second opinion as I'm not the most confident when it comes to math. SP is a dataframe of the daily S&P Adj Close from 1947-2021.

Here's the operation:

spq = sp.resample('Q').sum().pct_change()

I'm resampling by summing the values of each quarter. Then I'm calculating the percent change of each quarter against the last one. Did I get that right?

This is to train a neural network in order to determine the best (in terms of contribution to accuracy) features out of the ones I'm using. The objective is to predict the movement (upwards/downwards this quarter) of the S&P.

Please let me know if this is not the kind of question that's okay to ask. If you would like to test this out (please let me know how you test for this also!) here's the code for the S&P data:

import pandas as pd
import pandas_datareader.data as web
sp = web.DataReader('^GSPC', 'yahoo', start='1947-09-10', end='2021-06-30')['Adj Close']
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.