First we should clear the environment and download financial data from Yahoo Finance
We star clearing our R environment
I will load the quantmod package
## Warning: package 'quantmod' was built under R version 4.0.3
## Loading required package: xts
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.0.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## '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.
## [1] "^MXX" "^GSPC"
I would integrate both datasets into one:
Now i will be able to see how the S&P500 is behaving over time
To check the class of my R objects
## [1] "xts" "zoo"
“xts”= extensible time series “zoo”= is time series , to easy manipulate the data.
WHAT YOU CAN SAY ABOUT THE TREND OF BOTH MARKET INDEXES? IS IT CONSTANTLY GROWING, OR DECLINING, OR THERE IS NO CLEAR TREND? BRIEFLY EXPLAIN
WE CAN SEE THAT IN A GENERAL VIEW, THE S&P500 IS CONSTANTLY GROWING, ALTHOUGH THERE IS A SMALL FALL IN 2020, I AM ALMOST SURE THAT THIS WAS CAUSED BY THE PANDEMIC, ON THE OTHER SIDE, THE MEXICAN MARKET IS REALLY VOLATILE IT PRESENTS UP AND DOWNS BY THE PASS OF THE YEARS, ALSO WE CAN SEE THE FALL IN 2020 CAUSED BY THE PANDEMIC, IN CONCLUSION THE AMERICAN INDEX IS MORE CONSTANT AND I CAN SAY MORE RELIABLE.
DO YOU SEE ANY DIFFERENCE BETWEEN THIS PLOT OF THE LOG OF MXX INDEX COMPARED TO THE PLOT OF THE MXX INDEX
NO, THE GRAPH IS BASICALLY THE SAME AS THE MXX INDEX.
A financial simple return for a stock (Rt) is calculated as a percentage change of price from the previous period (t-1) to the present period (t):
Rt=((Adjpricet−Adjpricet−1))/Adjpricet−1=(Adjpricet/Adjpricet−1)−1 For example, if the adjusted price of a stock at the end of January 2021 was $100.00, and its previous (December 2020) adjusted price was $80.00, then the monthly simple return of the stock in January 2021 will be:
RJan2021=(AdpriceJan2021/AdpriceDec2020)−1=100/80−1=0.25
We can use returns in decimal or in percentage (multiplying by 100). We will keep using decimals.
In Finance it is very recommended to calculate continuously compounded returns (cc returns) and using cc returns instead of simple returns for data analysis, statistics and econometric models. cc returns are also called log returns.
One way to calculate cc returns is by subtracting the log of the current adjusted price (at t) minus the log of the previous adjusted price (at t-1):
rt=log(Adjpricet)−log(Adjprice(t−1))
This is also called as the difference of the log of the price.
We can also calculate cc returns as the log of the current adjusted price (at t) divided by the previous adjusted price (at t-1):
rt=log(Adjpricet/(Adjpricet−1))
cc returns are usually represented by small r, while simple returns are represented by capital R.
Do a graph for the continously compounded returns of the Mexican Index
### Question 3 DOES THIS SERIES HAVE ABOUT THE SAME MEAN FOR ALL TIME PERIODS?
YES, IT DOES, ONLY IN JANUARY 2020 THERE WAS A FALL UP TO -0.12 APROXIMATELY AND AN UP IN APRIL UP TO 0.12.
DOES IT HAVE THE SAME STANDARD DEVIATION (VOLATILITY) FOR ALL TIME PERIODS?
IT CAN VARIATE BUT ITS ALMOST THE SAME.
WHAT IS A STATIONARY SERIES
-R= IS A SERIES IN WHICH THE AVERAGE OR THE EXPECTED VALUE OF THE SERIES IS CONSTANT OVER TIME. E(Yt) = E(Yt−h) = µ
WHICH ARE THE CONDITIONS OF A SERIES TO BE CONSIDERED AS A STATIONARY SERIES?
-R= THE MEAN, VARIANCE AND STANDARD DEVIATION HAS TO BE CONSTANT OVER THE TIME; THERE IS NO SEASONALITY; THE COVARIANCE(CORRELATION) BETWEEN ONE VALUE OF THE SERIES AND ONE IN THE PAST/FUTURE IS THE SAME.