if (!require('devtools')) install.packages('devtools')
devtools::install_git('https://github.com/TurboPavel/PolishStock')
library(PolishStock)
stooq_download() - download historical data for indices WIG20 (Polish big-cap stocks), mWIG40 (Polish mid-cap stocks) and sWIG80 (Polish small-cap stocks) from https://stooq.pl/.
tickers <- c('wig20', 'mwig40', 'swig80')
sapply(tickers
,stooq_download
,start_date = 20190101
,end_date = 20211231
,destination = 'datasets\\')
## wig20 mwig40 swig80
## 0 0 0
df_prices() - create data frame of close prices
files <- list.files('datasets\\')
close_prices <- df_prices(files = files
,source = 'datasets\\')
head(close_prices)
## Date MWIG40 SWIG80 WIG20
## 6942 2019-01-02 3947.26 10631.64 2301.62
## 6943 2019-01-03 3906.97 10576.79 2247.22
## 6944 2019-01-04 3926.99 10625.48 2284.95
## 6947 2019-01-07 3977.00 10714.52 2331.45
## 6948 2019-01-08 3994.23 10724.72 2325.19
## 6949 2019-01-09 4018.89 10812.82 2341.84
portfolio_returns() - given assets prices and portfolio weights calculate returns of portfolio portfolio.
weights <- c(0.40, 0.40, 0.20 )
pr <- portfolio_returns(close_prices, weights)
returns_diagnostics() - given portfolio returns fit normal and t-Student distribution, check autocorrelation.
returns_diagnostics(pr)
## [1] "p-value for Ljung-Box test for NA lags is equal 0.0014 which means returns are not stationary."
## [1] "p-value for ADF test is equal 0.01 which means returns are stationary."
value_at_risk() - calculate and visualize VaR of the portfolio.
value_at_risk(pr, method = 'historical')
## $VaR
## [1] -0.01411453
##
## $ES
## [1] -0.02813612
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.