I have analyzed regression equation for WSP share price. I am of the opinion that Regression analysis won’t help us in arriving the weights as the co-efficient of independent variables can be negative at times. For example in the following regression equation, we can see co-efficient for financial sentiment is -0.057 and Sector sentiment is -0.019. I have tried different multi-regression equations by slicing and dicing the variables and ended-up with negative co-efficient. I spoke to Patrick on this, we are of the opinion that we can hold-on to multi-regression to save students time and effort.
We can proceed with simple average/sum of sentiment score for the project. Please help me pass-on the message.
I have given Python code and excel spreadsheet. Students can run the code using the above spread sheet if they want to take a look into it. Let me know if you have any thoughts on this.
Regression equation for WSP share price
Share Price = 2.2869 + (0.3070) * Macro sentiment + (-0.0576) * Financial sentiment + (-0.0109) * Sector sentimentPython Code:import pandas as pd
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
# Function to load data, perform regression, plot the results, and return the equation
def regress_and_plot(file_path):
# Load the data
data = pd.read_excel(file_path, index_col=0).T # Transpose to have features as columns
# Calculate percentage changes
data_pct_change = data.pct_change().dropna() * 100 # convert to percentage
# Independent variables (sentiment scores)
X = data_pct_change.iloc[:, :-1] # Assuming the last column is the share price
# Dependent variable (share price percentage change)
y = data_pct_change.iloc[:, -1] # Assuming the last column is the share price
# Initialize and fit the model
model = LinearRegression()
model.fit(X, y)
# Generate predictions
predictions = model.predict(X)
# Plotting the actual versus predicted values
plt.figure(figsize=(10, 6))
plt.scatter(range(len(y)), y, color='blue', label='Actual Percentage Change')
plt.plot(range(len(y)), predictions, color='red', linestyle='--', label='Predicted Percentage Change')
# Add titles and labels
plt.title('Regression Line for Share Price Percentage Change')
plt.xlabel('Time')
plt.ylabel('Percentage Change in Share Price')
plt.legend()
plt.grid(True)
plt.show()
# Construct the regression equation
equation = f"Share Price = {model.intercept_:.4f}"
for coef, name in zip(model.coef_, X.columns):
equation += f" + ({coef:.4f}) * {name}"
return equation
# Path to the uploaded Excel file
file_path = 'C:/WSP sentimentV2.xlsx' #two months lag in share price from respective quarter to account for earnings call date
# Call the function to perform regression, plot the graph, and get the equation
regression_equation = regress_and_plot(file_path)
print(regression_equation)
No comments:
Post a Comment