Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mikamyrseth committed Oct 6, 2022
1 parent 665d6a7 commit 1f6af75
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
17 changes: 9 additions & 8 deletions input/custom_dataseries/ellen_custom.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[
{
"name": "CUSTOM-ELLEN-INTEREST-DIFFERENCE",
"page": "3",
"weights": {
"NO-MONEY-MARKET-12": 1,
"FOREIGN-MONEY-MARKET-12": -1
}
{
"name": "CUSTOM-ELLEN-INTEREST-DIFFERENCE",
"page": "3",
"type": "ADD",
"weights": {
"NO-MONEY-MARKET-12": 1,
"FOREIGN-MONEY-MARKET-12": -1
}
]
}
]
55 changes: 27 additions & 28 deletions input/models/ellen_asymmetric.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "Ellen asymmetric",
"authors": "Saskia Ter Ellen",
"publish_year": 2016,
"page": "5",
"model_start_date": "2001-01-01",
"model_end_date": "2015-08-01",
"dependent_variable": "DELTA-LOG-NB-I44",
"frequency": "MONTHLY",
"coeffs": {
"ALPHA": 0.0018,
"DELTA_LOG_ICE_BRENT_POSITIVE": -0.0776,
"DELTA_LOG_ICE_BRENT_NEGATIVE": -0.0562,
"LAGGED_INTEREST_DIFFERENTIAL": -0.0015,
"CHANGE_INTEREST_DIFFERENTIAL": -0.0275,
"CRISIS_CONTROL_DUMMY": -0.0219
},
"stds": {
"CONSTANT": 1.3992,
"DELTA_LOG_ICE_BRENT_POSITIVE": -3.1713,
"DELTA_LOG_ICE_BRENT_NEGATIVE": -2.2304,
"LAGGED_INTEREST_DIFFERENTIAL": -1.9094,
"CHANGE_INTEREST_DIFFERENTIAL": -6.3554,
"CRISIS_CONTROL_DUMMY": -0.0219
},
"stats": {
"adjustedR2":0.3339
}
"name": "Ellen asymmetric",
"authors": "Saskia Ter Ellen",
"publish_year": 2016,
"page": "5",
"model_start_date": "2001-01-01",
"model_end_date": "2015-08-01",
"dependent_variable": "DELTA-LOG-NB-I44",
"frequency": "MONTHLY",
"coeffs": {
"ALPHA": 0.0018,
"DELTA_LOG_ICE_BRENT_POSITIVE": -0.0776,
"DELTA_LOG_ICE_BRENT_NEGATIVE": -0.0562,
"LAGGED_INTEREST_DIFFERENTIAL": -0.0015,
"CHANGE_INTEREST_DIFFERENTIAL": -0.0275,
"CRISIS_CONTROL_DUMMY": -0.0219
},
"stds": {
"CONSTANT": 1.3992,
"DELTA_LOG_ICE_BRENT_POSITIVE": -3.1713,
"DELTA_LOG_ICE_BRENT_NEGATIVE": -2.2304,
"LAGGED_INTEREST_DIFFERENTIAL": -1.9094,
"CHANGE_INTEREST_DIFFERENTIAL": -6.3554,
"CRISIS_CONTROL_DUMMY": -0.0219
},
"stats": {
"adjustedR2": 0.3339
}
}
28 changes: 15 additions & 13 deletions linreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split


class Columns(Enum):
DATE = "Date"
USDNOK = "TWI NKSP Index (R1)"
Expand All @@ -14,29 +15,30 @@ class Columns(Enum):


def regression(df: pd.DataFrame):


X = df[[Columns.OIL.value, Columns.STOCKS.value]]
Y = df[Columns.USDNOK.value]
X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size=0.01,random_state=101)
X_train, X_test, Y_train, Y_test = train_test_split(
X, Y, test_size=0.01, random_state=101)

lm = LinearRegression()
lm.fit(X_train,Y_train)
lm.fit(X_train, Y_train)

print("STD", X_train.std(axis=0))
print("coef.", lm.coef_)
print("norm. coef ", lm.coef_* X_train.std(axis=0))
return lm.coef_* X_train.std(axis=0)
print("norm. coef ", lm.coef_ * X_train.std(axis=0))
return lm.coef_ * X_train.std(axis=0)

print(lm.coef_)

prediction = lm.predict(X_test)
plt.scatter(Y_test,prediction)
plt.scatter(Y_test, prediction)
plt.show()


if __name__ == "__main__":
# Load data from excel
df = pd.read_excel ("regression data.xlsx", sheet_name="2000-2022")
df = pd.read_excel("regression data.xlsx", sheet_name="2000-2022")

# date_column = df[Columns.DATE.value]

Expand All @@ -60,19 +62,19 @@ def regression(df: pd.DataFrame):
coefs = regression(df)
print("coeffs full data: ", coefs)

# set to 1 means two year intervals, 2 is 3 etc.
# set to 1 means two year intervals, 2 is 3 etc.
interval = 5

#split data into years
# split data into years
for i in range(2000, 2023, interval):
# year_df = df[f"{i}-01-01":f"{i}-12-31"]
year_df = df.sort_index().loc[f"{i}-01-01":f"{i+(interval-1)}-12-31", :]
year_df = df.sort_index(
).loc[f"{i}-01-01":f"{i+(interval-1)}-12-31", :]
coefs = regression(year_df)
print(f"{i}-{i+(interval-1)}, {coefs[0]}, {coefs[1]}")
oil.append(coefs[0])
stocks.append(coefs[1])
break

#print(oil)
#print(stocks)

# print(oil)
# print(stocks)

0 comments on commit 1f6af75

Please sign in to comment.