Last active
February 26, 2020 08:21
-
-
Save quantra-go-algo/4ed2c5ead7760327a4fbdae997e7bb55 to your computer and use it in GitHub Desktop.
This file contains 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
stock = yf.download('MRF.BO','2012-01-01', '2017-12-31') | |
# 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