Showing posts with label R uses. Show all posts
Showing posts with label R uses. Show all posts

## R uses It uses the symbols for addition, subtraction, multiplication, division, and exponents nonsense percentage can be used to specify the order of operation.

1. Arithmetic
>pi
3.141.......
2. Variables
It can be letters numbers and dot,-.
>x<- 200
>x
[1] 100
good programming practice is to use informative name for your variables to improve readability.
3. Functions
Function text 1 and more inputs and produces one and more outputs.
>seq(from=1, to= 8,by=2)
[1] 1 3 5 7 9
4.
Vectors
> (x <-s (1,15, by =3)
[1] 1 3 5 7 9 11 13
5. Matrices
It is created from a vector using the function matrix

[1] "AAPL" "CSCO"
>
> aapl = as.matrix (AAPL[ , 6 ] )
>
> csco = as.matrix(CSCO[,6])
> stkdata = cbind ( aapl , csco )
>
2007-01-03      10.39169      21.46619
2007-01-04      10.62234      22.03129
2007-01-05      10.54669      22.03904
2007-01-08      10.59878      22.16290
2007-01-09      11.47922      22.03904
2007-01-10      12.02857      22.20160
> tail(stkdata)
2020-02-11        319.61         49.13
2020-02-12        327.20         49.93
2020-02-13        324.87         47.32
2020-02-14        324.95         46.97
2020-02-18        319.00         46.59
2020-02-19        323.62         46.29
> dim( stkdata )
[1] 3305    2
> Now, compute daily returns. This time, we do log returns in continuoustime. The mean returns are:
Error: unexpected ',' in "Now,"
> n = length ( stkdata [ , 1 ] )
> n
[1] 3305
> rets = log ( stkdata [ 2:n , ] / stkdata[ 1 :( n−1 ),] )
> colMeans ( rets )
0.0010407275  0.0002325807
> we  can find covariance matrix and correlation matrix:
Error: unexpected symbol in "we  can"
>
> cv = cov ( rets )
> cv
> print ( cv , 2 )