Title: | Manage Data from Stock Exchange Markets |
---|---|
Description: | Tools to perform some descriptive data analysis for assets. Manage the portfolio and capital of assets. It also downloads and organizes data from the Tehran Stock Exchange (TSE). |
Authors: | Ali Saeb |
Maintainer: | Ali Saeb <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 0.2.2 |
Built: | 2025-02-09 02:43:50 UTC |
Source: | https://github.com/cran/TSEtools |
Compute the capital assets pricing model including a risk-free asset.
capm(x, Rf = 0.2/270, sh = FALSE, eRtn = NULL)
capm(x, Rf = 0.2/270, sh = FALSE, eRtn = NULL)
x |
a numeric matrix of random returns per unit of price within some holding period. |
Rf |
the return of the risk free, i.e. has variance 0. |
sh |
a logical indicating whether shortsales on the risky securities are allowed. Default is FALSE. |
eRtn |
a value of expected returen of portofilo. The mean of whole data defualt. |
Let be random asset returns and
the portfolio weights. The expected returns are
In addition
to these risky investments, there is a risk-free asset (a bond or bank account)
available, which has return
. Denoting the weights of
for the risk-free
asset. The return of portfolio given by
where, .
Risk is measure by a deviation functional . It is a variance-covariance of asset returns. The risk-free component
ignore in the objective. So, the standard deviation of portfolio is given by
To obtain the optimum value of we solve the following model:
Note that, the portfolio weights may be negative (selling short is allowed). Market portfolio is named MP
where, the risk free weight w_0
is zero (see, the function of prtf()
).
For any portfolio ,
where, is return of market portfolio and
is the beta coefficient of the portfolio
. It is given by
wCAPM |
weight of CAPM assets |
wrF |
weight of risk free assets |
sd.capm |
volatility of CAPM portfolio |
rtn.capm |
return of CAPM portfolio |
beta |
beta coefficient of portfolio |
Pflug and Romisch (2007, ISBN: 9789812707406)
## Not run: x <- rnorm(500,0.05,0.02) y <- rnorm(500,0.01,0.03) z<-cbind(x, y) colnames(z) <- c("prt1","prt2") capm( z, sh = FALSE, Rf= 0.2/270, eRtn=0.02 ) ## End(Not run)
## Not run: x <- rnorm(500,0.05,0.02) y <- rnorm(500,0.01,0.03) z<-cbind(x, y) colnames(z) <- c("prt1","prt2") capm( z, sh = FALSE, Rf= 0.2/270, eRtn=0.02 ) ## End(Not run)
getTSE function is an easy way to download and organize the historical dataset from websites of TSE and www.tsetmc.com. Since, the raw data are not recorded in a standard format, we provide the function for organize the data in user friendly way. Daily data updated after 13:30 UTC. The market is closed on Friday and Wensday and national holidays.
getTSE(file, symbols=NA)
getTSE(file, symbols=NA)
file |
the path and name of external file which include the name of symbol and company and a specific code. |
symbols |
a vector of character given the name of assets to download. The name of assets has to be included in the first column of |
The list of symbols or assets can be named, and the list names will be used as names for the variables. Component data is an array with xts time series object. The name for dimensions are: Open, High, Low, Close, Volume, Last. The value of symbols are appear in Global Environment
.
The output is an object of the “assets” name which get all the name of assets list to download.
## Not run: fpath<-system.file("extdata", "sample.dat", package="TSEtools") getTSE(fpath) ## End(Not run)
## Not run: fpath<-system.file("extdata", "sample.dat", package="TSEtools") getTSE(fpath) ## End(Not run)
mcPrt function compound the vector of assets in matrix form to using the multivariate data analysis. The assets must be included the items of Open
, Close
, High
, Low
and Volumn
. The function also calculate the rate of return and Sharpe ratio for portfolio selection.
mcPrt(asset, sub = "::", pstvRtn = FALSE, pr = "daily", Rf = 0.0)
mcPrt(asset, sub = "::", pstvRtn = FALSE, pr = "daily", Rf = 0.0)
asset |
a character vector of symbols. |
sub |
The character string in the form of "start date :: end date". The date format is "%Y-%M-%D". Since, the data is time series format, the rules of xts satisfied. |
pstvRtn |
logical flag to determine, if the symbols with mean of return (see, details) should be positive/negative. Missing value is taken as false. By setting |
pr |
a character specifying the desired period time of return. Default value is daily. The values get "daily", "weekly" and "monthly". |
Rf |
an integer value to give risk free. |
The values of function contain Sharpe ratio and rate of return. Sharpe ratio is defined as:
where is the mean asset return,
is the risk free rate of return and
is the standard deviation (volatility) of the asset.
Let is the closing price of the asset at time
and its value after a period of length
, say
. The return over that period is defined as:
Note that the return equation is equivalent to log return asset when the ratio value of the asset is close to 1 (see, Carmona 2003). To check the goodness of fit test on return value, maximum and minimum of prices, suggested to use the package of gnFit.
The values of function involve close
, return
, max
and min
as a matrix and xts format. The columns are a value of assets which is ordered by date. The mean return, volatility and Sharpe ratio are assigned in the out
. The plot of return vs volatility and also the graph of Sharpe ratio are outputs of function.
Carmona (2003, ISBN:0387202862)
## Not run: fpath<-system.file("extdata", "sample.dat", package="TSEtools") getTSE(fpath) rtn<-mcPrt(asset0, sub="2016::", pstvRtn=TRUE, pr="weekly")$return ## End(Not run)
## Not run: fpath<-system.file("extdata", "sample.dat", package="TSEtools") getTSE(fpath) rtn<-mcPrt(asset0, sub="2016::", pstvRtn=TRUE, pr="weekly")$return ## End(Not run)
Compute the efficient frontier function for some selected risk functionals in a portfolio optimization setting.
prtf (x, Rf = 0.0, sh = FALSE ,eRtn = NULL)
prtf (x, Rf = 0.0, sh = FALSE ,eRtn = NULL)
x |
a numeric matrix of random returns per unit of price within some holding period. |
sh |
a logical indicating whether shortsales on the risky securities are allowed. Default is FALSE. |
Rf |
the return of the risk free, i.e. has variance 0. |
eRtn |
a value of expected returen of portofilo. The mean of whole data defualt. |
Let be random asset returns and
the portfolio
weights. The expected returns are
In addition
to these risky investments, there is a risk-free asset (a bond or bank account)
available, which has return
. Denoting the weights of
for the risk-free
asset. The return of portfolio given by
where, .
Risk is measure by a deviation functional . It is a variance-covariance of asset returns. The risk-free component
ignore in the objective. So, the standard deviation of portfolio is given by
To obtain the optimum value of we solve the following model:
where, is a constant value.
Note that, the portfolio weights may be negative (selling short is allowed).
The minimum weights show with MIN
which is the portfolio with the minimum volatility. Market portfolio is given by MP
where, the risk free weight w_0
is zero. MP
is the tangency point between the market line and efficient frountier curve. A list containing the following components:
prt |
list the name of assests in the portfolio |
obs.p |
return and volatiliy of overall portfolio |
vol |
volatility of portfolio |
rtn |
return of portfolio |
w |
weigths of portfolio |
Pflug and Romisch (2007, ISBN: 9789812707406)
portfolio.optimization, portfolio.optim
## Not run: x <- rnorm(500,0.05,0.02) y <- rnorm(500,0.01,0.03) z<-cbind(x, y) colnames(z) <- c("prt1","prt2") prtf (z, sh = FALSE) ## End(Not run)
## Not run: x <- rnorm(500,0.05,0.02) y <- rnorm(500,0.01,0.03) z<-cbind(x, y) colnames(z) <- c("prt1","prt2") prtf (z, sh = FALSE) ## End(Not run)