FR2215: L4 (Regression Model)

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:12 AM on 3/26/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

27 Terms

1
New cards

statsmodel library

library for estimating statistical models

2
New cards

importing statsmodel

import statsmodel

import statsmodel.formula.api as smf (specifying models from pandas df)

from statsmodels.tsa.ar_model import AutoReg

3
New cards

scikit-learn library

library for machine learning tools

4
New cards

importing scikit-learn

import sklearn

from sklearn.linear_model import LinearRegression

5
New cards

declaring data as time-series

df[‘x’] = pd.to_datetime(df[‘x’])

  • do this prior to setting date as the index bc python will no longer recognize it as a column

6
New cards

mean reverting

deviations from the avg are expected to reverse, return to avg over time

7
New cards

what do to if time series variable is non mean reverting

work w/ the variable's differences

8
New cards

2 mean reversion tests

  1. ADF

  2. KPSS

9
New cards

ADF test

  • not robust

  • suboptimal test

  • good in periods of calm markets

  • Ho: has a unit root, Ha: has no unit root

    • rejecting null provides evidence supporting non-stationarity

10
New cards

robust

produces reliable results even w/ outliers and violated assumptions

11
New cards

KPSS test

  • robust

  • optimal

  • Ho: trend stationary, Ha: has a unit root (not trend stationary)

12
New cards

generating variable differences

∆GT = GT - GT-1

13
New cards

generating variable differences in python

df2 = df.set_index(‘Date’).diff().reset_index()

  • 1st element becomes unavailable bc no differences

  • df.dropna() for NaNs

14
New cards

descriptive stats on python

  • df.describe()

  • df.corr()

15
New cards

correlation

measure of linear dependence

  • most financial variables are non-linearly dependent

16
New cards

correlation threshold to run a regression

0.5

17
New cards

skew

measure of asymmetry around the mean

  • x = df[‘x’].skew() (n/a for time series)

18
New cards

kurtosis

measure of tail fatmess

  • x = df[‘x’].kurt()

19
New cards

testing for mean reversion steps

  1. mean reversion test (KPSS then ADF)

  2. transform variable if needed

  3. check skew/kurtosis

20
New cards

jarque bera testing

  • import scipy.stats as stats

  • x = stats.jarque_bera(df[‘x’])

    • Ho: normally distributed

21
New cards

running OLS in python

x = df[[‘x1’, ‘x2’]]

y = df[‘y’]

x = sm.add_constant(x)

model = sm.OLS(x,y).fit()

print(model.summary())

22
New cards

unit root

a feature of non-stationary time series data

23
New cards

key library for ADF test

from statsmodels.tsa.stattools import adfuller

24
New cards

key library for KPSS test

from statsmodels.tsa.stattools import kpss

25
New cards

key conclusion of ADF and KPSS tests

  • reject Ho in ADF + fail to reject Ho in KPSS = likely stationary

  • fail to reject Ho in ADF + reject Ho in KPSS = likely not stationary

26
New cards

ADF test in python (all variable loop)

print(‘ADF Test Results’)

for column in df.columnsL

  • print(‘\nColumn: ‘ + column)

  • adftest = adfuller(df[column], autolag=’AIC’)

  • print(‘ADF Stat: ‘ + str(adftest[0]))

  • print(‘P-Value : ‘ + str(adftest[1]))

  • if adftest[1] <= 0.05:

    • print(‘Reject Ho, the series is stationary)

  • else:

    • print(Fail to reject Ho, the series isn’t stationary)

27
New cards

KPSS test in python (all variable loop)

print(‘KPSS Test Results’)

for column in df.columnsL

  • print(‘\nColumn: ‘ + column)

  • kpsstest = kpss(df[column], regression=’c’, nlags=’auto’)

  • print(‘KPSS Stat: ‘ + str(kpsstest[0]))

  • print(‘P-Value : ‘ + str(kpsstest[1]))

  • if kpsstest[1] <= 0.05:

    • print(‘Reject Ho, the series isn’t stationary)

  • else:

    • print(Fail to reject Ho, the series is stationary)

Explore top notes

note
Unit 6: Period 6: 1865–1898
Updated 78d ago
0.0(0)
note
Chapter 12: Colons and Dashes
Updated 1017d ago
0.0(0)
note
Chapter 15: Writing Systems
Updated 1280d ago
0.0(0)
note
Physics by Holt- Chapter 1 notes
Updated 1291d ago
0.0(0)
note
What is Theatre?
Updated 1364d ago
0.0(0)
note
Biology 1 - Mod 3 Cell Discovery
Updated 1210d ago
0.0(0)
note
history test 1 summary
Updated 1037d ago
0.0(0)
note
Chapter 13 - The Reform Impulse
Updated 1280d ago
0.0(0)
note
Unit 6: Period 6: 1865–1898
Updated 78d ago
0.0(0)
note
Chapter 12: Colons and Dashes
Updated 1017d ago
0.0(0)
note
Chapter 15: Writing Systems
Updated 1280d ago
0.0(0)
note
Physics by Holt- Chapter 1 notes
Updated 1291d ago
0.0(0)
note
What is Theatre?
Updated 1364d ago
0.0(0)
note
Biology 1 - Mod 3 Cell Discovery
Updated 1210d ago
0.0(0)
note
history test 1 summary
Updated 1037d ago
0.0(0)
note
Chapter 13 - The Reform Impulse
Updated 1280d ago
0.0(0)

Explore top flashcards

flashcards
GenOmgevingssamenspel
37
Updated 1060d ago
0.0(0)
flashcards
WIP 117
20
Updated 1164d ago
0.0(0)
flashcards
spanish foods
60
Updated 1079d ago
0.0(0)
flashcards
Hist 106 Exam 1 Study Guide
70
Updated 189d ago
0.0(0)
flashcards
Brain Bee
177
Updated 1185d ago
0.0(0)
flashcards
GenOmgevingssamenspel
37
Updated 1060d ago
0.0(0)
flashcards
WIP 117
20
Updated 1164d ago
0.0(0)
flashcards
spanish foods
60
Updated 1079d ago
0.0(0)
flashcards
Hist 106 Exam 1 Study Guide
70
Updated 189d ago
0.0(0)
flashcards
Brain Bee
177
Updated 1185d ago
0.0(0)