Created
February 21, 2020 06:48
-
-
Save quantra-go-algo/7966fdba0e973833db9c8cc4a0251218 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Populates the time period number in stock under head t | |
stock['t'] = range (1,len(stock)+1) | |
#Computes t squared, tXD(t) and n | |
stock['sqr t']=stock['t']**2 | |
stock['tXD']=stock['t']*stock['Adj Close'] | |
n=len(stock) | |
#Computes slope and intercept | |
slope = (n*stock['tXD'].sum() - stock['t'].sum()*stock['Adj Close'].sum())/(n*stock['sqr t'].sum() - (stock['t'].sum())**2) | |
intercept = (stock['Adj Close'].sum()*stock['sqr t'].sum() - stock['t'].sum()*stock['tXD'].sum())/(n*stock['sqr t'].sum() - (stock['t'].sum())**2) | |
print ('The slope of the linear trend (b) is: ', slope) | |
print ('The intercept (a) is: ', intercept) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment