Statistics functions (Linear Regression, Slope, R², ...)

Hi All,


I’m looking for several Statistics functions like Linear Regression, Slope, R² from the QLib but I only found this wiki page https://wiki.alphien.com/ALwiki/User_custom_algos and perhaps the function dlmMLE to calculate the slope but without any more details about it :frowning:


Can you please help me to retrieve/import/implement these functions ?


Thyanks

Regards

Greg

Dear Yousky,

Thanks for your question!

You can use the R Sats package:


lm function | R Documentation


Thanks!




Thanks Khalil.

As an example, this is a short script to show how to run some basic linear models. You can run it after loading the Qlib with .sourceQlib() as this also loads a number of native and essential R packages for data manipulation and analysis.


#request all prices for Lyxor Building Blocks

prices = getLyxorBBs(, asPrice = T)


#ticker for the stoxx 600 ETF (benchmark) is MEUDa

bench = prices[,which(colnames(prices)==‘MEUDa’)]

#exclude benchmark

prices = prices[,-which(colnames(prices)==‘MEUDa’)]


#run single linear regression per ETF against the benchmark. Use daily return series

reg = lm(ROC(prices, 1, type=‘discrete’) ~ ROC(bench, 1, type=‘discrete’)


#check results of each single regression

reg


#extract beta

beta = reg$coefficients[2,]


#extract beta for DAXa

daxBeta = beta[which(names(beta)==‘DAXa’)]


#check r-squared for DAX

summary(reg)[[which(names(beta)==‘DAXa’)]]$r.square



There are some packages that are available to you but that are not loaded in your environment when you call .sourceQlib(). To see what is available, check the “Packages” tab in the bottom right AlphienStudio panel. Ticking the box loads the package in your workspace.

Thanks Hervé.

It was good to see you today at Lyxor during this training session.