Professional Documents
Culture Documents
SAI
ANVITHA
This message is shown once per session and may be disabled by setting
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
[1] "SBIN.NS"
Warning message:
SBIN.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
> View(SBIN.NS)
> summary(SBIN.NS)
Index SBIN.NS.Open SBIN.NS.High SBIN.NS.Low SBIN.NS.Close
Min. :2007-01-02 Min. : 87.26 Min. : 87.72 Min. : 84.74 Min. : 86.2
1st Qu.:2010-09-27 1st Qu.:186.80 1st Qu.:189.51 1st Qu.:183.28 1st Qu.:186.2
Median :2014-06-12 Median :233.22 Median :235.95 Median :230.10 Median :232.7
Mean :2014-06-17 Mean :238.14 Mean :241.51 Mean :234.33 Mean :237.8
3rd Qu.:2018-03-09 3rd Qu.:279.44 3rd Qu.:282.98 3rd Qu.:275.68 3rd Qu.:279.3
Max. :2021-12-03 Max. :534.45 Max. :542.30 Max. :528.05 Max. :530.5
NA's :7 NA's :7 NA's :7 NA's :7
SBIN.NS.Volume SBIN.NS.Adjusted
Min. : 0 Min. : 73.14
1st Qu.: 13812500 1st Qu.:174.52
1
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> library(PerformanceAnalytics)
> ar<-annualReturn(SBIN.NS$SBIN.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> ar
yearly.returns
2007-12-31 0.89154802
2008-12-31 -0.42393032
2009-12-31 0.76055234
2010-12-31 0.23926844
2011-12-30 -0.42421495
2012-12-31 0.47339492
2013-12-31 -0.25948442
2014-12-31 0.76535532
2015-12-31 -0.28026297
2016-12-30 0.11472488
2017-12-29 0.23860910
2018-12-31 -0.04517586
2019-12-31 0.12791486
2020-12-31 -0.17617974
2021-12-03 0.72085824
2
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> var(ar,na.rm='F')
yearly.returns
yearly.returns 0.2064887
> sd(ar,na.rm='F')
[1] 0.4544102
> range(ar,na.rm='F')
[1] -0.424215 0.891548
> quantile(ar,na.rm='F')
0% 25% 50% 75%
-0.4242150 -0.2178321 0.1279149 0.5971266
100%
0.8915480
3
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> plot(d$trend)
4
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
This message is shown once per session and may be disabled by setting
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
[1] "INFY.NS"
Warning message:
INFY.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
> dr=dailyReturn(INFY.NS$INFY.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
5
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> View(dr)
> mr=monthlyReturn(INFY.NS$INFY.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> View(mr)
> yr=annualReturn(INFY.NS$INFY.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
6
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> View(yr)
> all=allReturns(INFY.NS$INFY.NS.Close)
Warning messages:
1: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
2: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
3: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
4: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
5: In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> View(all)
7
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
8
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
This message is shown once per session and may be disabled by setting
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
[1] "TCS.NS"
Warning message:
TCS.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
> tcs=TCS.NS
> chartSeries(tcs,subset='2021-08-01/',theme='white')
9
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> chartSeries(tcs,subset='2021-08-01/',theme='white',TA='addSMA(n=40)')
> chartSeries(tcs,subset='2021-08-01/',theme='white',TA=c(addSMA(n=45),addVo()))
> chartSeries(tcs,subset='2021-08-01/',theme='white',TA="addRSI(n=20)")
10
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
11
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> chartSeries(wip,theme='white')
12
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> chartSeries(wip,theme='white',subset='2020::')
> chartSeries(wip,theme='white',subset='::2008')
> chartSeries(wip,theme='white',subset='2021-04-01/',up.col='blue',do.col='green')
13
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
Program:
> library(IntroCompFinR)
> library(PerformanceAnalytics)
> library(quantmod)
> basketsymbols=c('TCS.NS','INFY.NS','WIPRO.NS')
> getSymbols()
Warning message:
In getSymbols() : no Symbols specified
> getSymbols(basketsymbols,src='yahoo')
[1] "TCS.NS" "INFY.NS" "WIPRO.NS"
Warning messages:
1: TCS.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
2: INFY.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
3: WIPRO.NS contains missing values. Some functions will not work if objects contain
missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc
to remove or replace them.
> tcs=yearlyReturn(TCS.NS$TCS.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> inf=yearlyReturn(INFY.NS$INFY.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> wipro=yearlyReturn(WIPRO.NS$WIPRO.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
15
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
16
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
Portfolio weights:
TCS INFOSYS WIPRO
0.3333 0.3333 0.3333
17
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
Program:
>basketsymbols=c('GODREJIND.BO','WIPRO.BO','BHARTIARTL.BO')
> getSymbols(basketsymbols,src='yahoo')
‘getSymbols’ currently uses auto.assign=TRUE by default, but will
use auto.assign=FALSE in 0.5-0. You will still be able to use
‘loadSymbols’ to automatically load data. getOption("getSymbols.env")
and getOption("getSymbols.auto.assign") will still be checked for
alternate defaults.
This message is shown once per session and may be disabled by setting
options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
18
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> View(bhartiair)
> getSymbols('^BSESN',src='yahoo')
[1] "^BSESN"
Warning message:
^BSESN contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
> View(BSESN)
> bse=BSESN[,4]
> View(bse)
> #Regression for Godrej,bse
> fit1=lm(godrej~bse)
> fit1
Call:
lm(formula = godrej ~ bse)
Coefficients:
(Intercept) bse
37.0240 0.0114
> #godrej=37.0240+0.0114(bse)
> #when increases by 10
> godrejj=37.0240+0.0114*10
> godrejj
[1] 37.138
> #Regression for Wipro,bse
> fit2=lm(wipro~bse)
> fit2
19
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
Call:
lm(formula = wipro ~ bse)
Coefficients:
(Intercept) bse
-24.076887 0.008635
> #wipro=-24.076887+0.008635(wipro)
> #when increased by 10
> wiproo=-24.076887+0.008635*10
> wiproo
[1] -23.99054
> #Regression for Bhartiair,bse
> fit3=lm(bhartiair~bse)
> fit3
Call:
lm(formula = bhartiair ~ bse)
Coefficients:
(Intercept) bse
2.211e+02 5.318e-03
20
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> portfolioreturn
[1] 98.51836
> #Portfolio return consisting of Godrej, Wipro and Bhartiairtel is 98.51836
21
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
> library(quantmod)
> basketsymbols=c('SBIN.NS','TCS.NS')
> getSymbols(basketsymbols,src='yahoo')
[1] "SBIN.NS" "TCS.NS"
Warning messages:
1: SBIN.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
2: TCS.NS contains missing values. Some functions will not work if objects contain missing
values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to
remove or replace them.
ar=annualReturn(SBIN.NS$SBIN.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> ar2=annualReturn(TCS.NS$TCS.NS.Close)
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
missing values removed from data
> View(ar)
> View(ar2)
> data=as.xts(merge(ar,ar2))
> View(data)
> class(data)
[1] "xts" "zoo"
> summary(lm(data$yearly.returns~data$yearly.returns.1))
Call:
lm(formula = data$yearly.returns ~ data$yearly.returns.1)
Residuals:
22
BUSINESS ANALYTICS IN FINANCE 2001510092-V.SAI
ANVITHA
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.1172 0.1275 0.919 0.375
data$yearly.returns.1 0.2298 0.2060 1.115 0.285
> CAPM.beta(Ra=data$yearly.returns,Rb=data$yearly.returns.1)
[1] 0.2297738
> CAPM.alpha(Ra=data$yearly.returns,Rb=data$yearly.returns.1)
[1] 0.117164
23