Enrico Schumann
  • Member for 8 years
  • Last seen this week
List of packages in R for options pricing?
Accepted answer
8 votes

You may want to browse the Task View for empirical finance, which lists many options-related packages. As for concrete suggestions: I have worked a lot with RQuantLib in the past, and I have found it ...

View answer
Interactive Brokers: Automating collection of client account position without TWS/IB Gateway
8 votes

IB has something called "Flex Web Service", which allows you to download flex queries without being logged in; see Using the Flex Web Service. The R package IButils, which I maintain, has a function ...

View answer
How to minimize Nelson-Siegel parametric form
5 votes

When we worked with that model several years go, we used Differential Evolution and it worked very well. See Calibrating the Nelson-Siegel-Svensson Model. At least in the standard version, a best-of-...

View answer
CVAR alternatives for optimization
Accepted answer
5 votes

Following the comments and the edits to the question, I'll try to show how conditional Value-at-Risk (aka Expected Tail Loss) can be minimised for a portfolio. We start with the implementation ...

View answer
Estimating a Yield Curve in a country without Bond Stripping
5 votes

You do not need zero rates to estimate a parametric model of the yield curve, such as Nelson-Siegel. Suppose for instance that you have a cross-section of bond prices. Then: For given parameters for ...

View answer
How to set a fixed return for mean-CVaR portfolio optimization?
4 votes

I don't use fPortfolio but when I run your code example, I first get an error: ## Error in add.constraint() : could not find function "add.constraint" Nevertheless, after that, I can ...

View answer
Find k of n assets that "minimize" the correlation matrix
4 votes

(I take it that 5 out of 10 assets is just an example, because in this case all combinations could easily be checked.) Here would be an example how to do it in R with an algorithm called Threshold ...

View answer
Do the minimum VaR and minimum ES portfolios lie on the mean-variance efficient frontier?
4 votes

When returns follow an elliptical distribution (e.g. the Gaussian distribution), then minimising VaR and ES is equivalent to minimising variance. See https://people.math.ethz.ch/~embrecht/ftp/pitfalls....

View answer
After hours data - Interactive Brokers
Accepted answer
4 votes

The function reqHistoricalData has an argument useRTH ("use regular trading hours"). Set useRTH = "0" to get data outside those hours. This can only work for the futures, not for the index, which is ...

View answer
Total Returns From Adjusted Close Prices
Accepted answer
4 votes

It is indeed no rounding error, but follows from the way Yahoo computes the adjusted price: it does not reflect the actual returns of the investor. Just look at August 17 and 20. The actual close ...

View answer
What is the delta of a portfolio invested in different stocks?
4 votes

Strictly speaking, you cannot aggregate (i.e. sum) deltas. However, equity traders often provide their net exposure in currency units, which is a useful number. The same reasoning is possible with ...

View answer
Calculate day-to-day change in value of open position
Accepted answer
4 votes

Perhaps the PMwR package does some of the things you want. Disclosure: I am the package author. PMwR is not on CRAN (yet), but is on GitHub (https://github.com/enricoschumann/PMwR) and can also be ...

View answer
Setting up arbitrage strategy in R
Accepted answer
3 votes

A test for arbitrage opportunities with an LP is to minimize the cost of setting up the portfolio, subject to the restriction that the portfolio loses money in no state of the world. (Note that in ...

View answer
Compound the monthly returns to make them quarterly
Accepted answer
3 votes

You add 1 to every monthly return of a given quarter, take the product of those returns, and then subtract 1. In R (without any package): Suppose r are the monthly returns, and dt are the timestamps. ...

View answer
How to orthogonalize Fama French factors?
Accepted answer
3 votes

The Fama-French factors follow from simple sorting procedures, so they do not explicitly control correlation. But if you have access to the underlying stocks, you could replace this sorting procedure ...

View answer
Why is it better to use evolutionary algorithms than OLS for solving index tracking problem?
Accepted answer
3 votes

It would have been helpful had you provided links to those papers. But in general, you need to distinguish between the optimisation model, and the numerical technique used to solve the model. ...

View answer
Rolling seasonal and seasonal reversal patterns factor investing
3 votes

As Chris already wrote in his comments: your description is not complete. But I would suggest to write a simple loop over your data matrix. There is no need for working with zoo/xts while doing these ...

View answer
Getting sets of random correlated variables
3 votes

Here is one recipe, in case you can live with Spearman rank correlation. (Which you should: linear correlation is often not appropriate in the non-normal case. And in the normal case, there is almost ...

View answer
R: Calculating cumulative return of a portfolio
3 votes

Have you checked the performance of the particular stocks? library("quantmod") library("PMwR") cmp <- "AAPL" aapl <- getSymbols(Symbols = cmp, auto.assign = FALSE)$AAPL.Adjusted cmp <- "FB"...

View answer
Calculating the efficient frontier from expected returns and SD
Accepted answer
3 votes

As indicated in my comment, the function mvFrontier in the development version of the NMOF package may help you. (Disclosure: I am the package maintainer.) You may get the latest version from GitHub. ...

View answer
R: optimize timeseries to minimize "integral"
3 votes

A simple, though somewhat inflexible, way would be to regress $\bar{P}$ on the $I$ series only (no constant). This will minimise squared differences instead of absolute ones, though. R example; I ...

View answer
Creating a portfolio in R : good practices
Accepted answer
3 votes

As commented by Alex C, the R package PMwR, which I maintain, may offer some useful functionality. A small example: I create a journal of three trades. (Note that a journal here is simply a collection ...

View answer
Calculating intraday returns from imperfect data in R
Accepted answer
3 votes

Create a new price series that has a value for every minute, e.g. by carrying the last observation forward. Then compute returns from this new price series. (There are simpler approaches for this ...

View answer
Generating a random covariance matrix with variances in range
3 votes

A useful decomposition is, in R's matrix notation, V = S %*% C %*% S, in which S is a matrix with the standard deviations on the main diagonal and zeros elsewhere, and C is the correlation matrix. (...

View answer
how to choose top n assets?
3 votes

For such a problem ("selecting n out of m") you can use optimisation heuristics. These algorithms work well even for large n and m, and they are flexible: you may as well select a portfolio that ...

View answer
Backtesting a portfolio strategy with several assets
2 votes

If using R is an option: With package PMwR, which I maintain, you could compute a time-series of returns for such a portfolio in one line of code: ## P -- a matrix of prices: each column holds the ...

View answer
Downside deviation (semivariance) in m.v. portfolio optimization
2 votes

The third approach is the correct one. In general, one cannot aggregate partial moments of single assets into partial moments of the portfolio, as discussed for instance in this paper: @ARTICLE{...

View answer
Is there a good backtesting package in R?
2 votes

To add another possibility: Here is how such a model could be run in the PMwR package (which I maintain). It seems that sig holds the desired position. Suppose we have a time series of prices P. sig &...

View answer
Is there a packages to estimate Diebold-Li Parameters in R?
Accepted answer
2 votes

Diebold/Li is not a separate yield-curve model: for a given cross-section of yields, they fix the shape parameter in Nelson-Siegel and then estimate the remaining parameters via linear regression. See ...

View answer
R: Book with extensive examples for either portfolio optimization or volatility forecasting?
2 votes

There are many R code examples for portfolio selection and some for GARCH models in this book: @BOOK{Gilli2019, title = {Numerical Methods and Optimization in Finance}, publisher = {...

View answer