Marigold / universal-portfolios

Collection of algorithms for online portfolio selection
Other
766 stars 211 forks source link

Transaction cost optimization for online portfolio selection #9

Closed akaniklaus closed 6 years ago

akaniklaus commented 6 years ago

Implementation of the following recent strategy ("Transaction cost optimization for online portfolio selection") is missing from the framework, I would be glad if someone can implement this as well: http://ink.library.smu.edu.sg/cgi/viewcontent.cgi?article=4761&context=sis_research

akaniklaus commented 6 years ago

"Passive Aggressive Algorithm for Online Portfolio Selection with Piecewise Loss Function" In this paper, they also claim to improve over PAMR, maybe this technique can be utilized to improve PAMR and WMAMR algorithms that are implemented in the current framework. Please, check.

akaniklaus commented 6 years ago

"Online Learning of Commission Avoidant Portfolio Ensembles" This paper also seems to propose a notable method for using an ensemble of OLPS algorithms, in a commission avoidant manner. https://arxiv.org/pdf/1605.00788.pdf

akaniklaus commented 6 years ago

If anybody is interested to implement TOC method also Universal Portfolios, please contact me so that I can send MATLAB implementation of the technique, which its authors kindly shared with me.

Marigold commented 6 years ago

Hey @akaniklaus, sorry but I'm a bit busy these days and don't really have time for implementing all new research. There haven't been any major ideas recently anyway.

akaniklaus commented 6 years ago

@Marigold Hello, not problem at all. I should first thank you for providing this great library. If you still want to receive TOC method's MATLAB codes, please let me know (kamer@livabout.com). P.S. TOC paper is from the team (Bin Li & Steven Hoi) who developed OLPS toolbox.

akaniklaus commented 6 years ago

@Marigold Do you know any interesting work that is using an ensemble of these algorithms btw?

Marigold commented 6 years ago

Can't remember any right now, but I've seen plenty doing this using OLMR(OLMR(OLMR)) and so on. Haven't found much use in it, it's just pure overfitting.

The problem with these papers is that they have survivorship bias (which is a huge deal if your strategy is mean-reverting) and they tune it to specific datasets (NYSE, TSE, ...). To be honest, I'm not using any of these OLMAR-type strategies, but I use for instance MPT (Markowitz) for managing my personal portfolio.

akaniklaus commented 6 years ago

Thank you for your feedback! I also started experimenting with them after your notice but it is hard to decide for a training and waiting period (by the way, I am trying to work with cryptocurrencies).

As I am a bit skeptical about the behaviour of simplex projection that often bets into only one asset (especially in such a volatile space as crypto-currencies), I rather used following transformation:

weight = np.log(1.0 + np.exp(weight)) weight = weight / weight.sum()

However, surprisingly (at least for me), it resulted in a worse performance. Any ideas about this?

Marigold commented 6 years ago

I guess it could work on cryptocurrencies, but only if they are mean reverting. As for your transformation to simplex, if it works or not depends highly on the nature of your data. One problem from theoretical standpoint is that your formula is not idempotent and also gives positive weights to assets that would have weight zero otherwise.

On Wed, 8 Nov 2017, 09:18 akaniklaus, notifications@github.com wrote:

Thank you for your feedback! I also started experimenting with them after your notice but it is hard to decide for a training and waiting period (by the way, I am trying to work with cryptocurrencies).

As I am a bit skeptical about the behaviour of simplex projection that often bets into only one asset (especially in such a volatile space as crypto-currencies), I rather used following transformation:

weight = np.log(1.0 + np.exp(weight)) weight = weight / weight.sum()

However, surprisingly (at least for me), it resulted in a worse performance. Any ideas about this?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Marigold/universal-portfolios/issues/9#issuecomment-342743201, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeqKEJsbH_6FJ6BW9iumGtNksve33EQks5s0WO_gaJpZM4QEm49 .

akaniklaus commented 6 years ago
rmr- with simplex projection

I guess that they are as I was able to obtain good results with RMR during backtesting, at least for some periods. I am now running it for live-trading with couple of improvements that I have made, such as intra-day trading with a sliding window, etc. It would also match better my case, as I am trading in smaller and more easily executable orders, to not just buy but also sell according to the weights. I am also using a weighted average price that is calculated from orders, rather than close prices. I also converted Matlab codes of TCO1 in the paper to Python as follows, but they didn't work well (I might have made a mistake while converting them into Python). Note: lda is commission 0.0025 multiplied with a variable that is found 10 as optimal in the paper, along with eta variable.

def tcp_trunc(x, eta_lambda): return np.sign(x) * np.max(abs(x)-eta_lambda, 0)

def tco1Step(X, last_b, eta=10, lda=0.025): mr_x = 1 / X trunc_x = eta (mr_x - np.mean(mr_x)) / np.dot(last_b, mr_x) weight = last_b + tcp_trunc(trunc_x, ldaeta) return simplex_proj(weight)

I have also applied Markowitz portfolio as per your suggestion but didn't perform a backtesting yet as I was unsure what would be the best length for a past window using which MPT is calculated. What disturbs me about Simplex projection as that for example there is an asset with weight 19 and another with 20, the algorithm sometimes sells the one with 19 to buy the one with 20 (as simplex often bets into one). I am planning to change the algorithm so that it also considers calculated weights (from RMR) while selling assets, rather than threatening all of the ones to be sold equally.

Marigold commented 6 years ago

I have also applied Markowitz portfolio as per your suggestion but didn't perform a backtesting yet

Markowitz is for passive investing (basically how to best diversify your portfolio). If you look for trading algorithms, then RMR and others are more suited for that.

akaniklaus commented 6 years ago

FYI, I've read a thesis that suggests three weeks of back window and two weeks of holding time for a Markowitz portfolio in cryptocurrency domain. I guess that I might try something like that as well.

Marigold commented 6 years ago

Would you mind providing a link? Sounds like overfitting at its best :).

akaniklaus commented 6 years ago

It doesn't seem the best thesis but :) https://thesis.eur.nl/pub/39587/Stoffels-J-450577-MA-thesis.pdf

akaniklaus commented 6 years ago

Here it says that they're using FTSE Russel’s capping methodology: https://static.crypto20.com/pdf/c20-whitepaper.pdf

akaniklaus commented 6 years ago

These are also some other interesting ensemble OLPS applications: https://akraichand.github.io/KSE966.pdf https://ciir-publications.cs.umass.edu/pub/web/getpdf.php?id=1257

Marigold commented 6 years ago

Maybe, but it's still just overfitting on these standard datasets.

On Sun, Nov 19, 2017 at 5:34 PM akaniklaus notifications@github.com wrote:

This thesis (Bayesian ensembled Mean-Median Reversion) is also interesting: https://akraichand.github.io/KSE966.pdf

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Marigold/universal-portfolios/issues/9#issuecomment-345529941, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeqKKmQvSeU7fG3yMBtle2YSRayVV4lks5s4FiHgaJpZM4QEm49 .

akaniklaus commented 6 years ago

Well, that's how generally Academia is :) Still, worth to take a look and try improving. The biggest problem that I am facing at the moment with RMR on crypto currency space is that it takes serious damages by buying recently pumped assets that are being dumped, apart from that it seems to be making profits. Overall, I can say that it managed so far to not lose any significant portfolio value.

akaniklaus commented 6 years ago

I would also like to let you know that, high-interest lending is also possible in cryptocurrency field. Since that you're interested with longer-term portfolio rebalancing methods such as Markowitz, I believe that a lending bot could make a great sense to use in conjunction with such methods: https://github.com/BitBotFactory/poloniexlendingbot

Marigold commented 6 years ago

Didn't know about it, thanks. I checked it out though and it looks like annualized interest rate is <1%. Or am I wrong?

On Sun, Nov 26, 2017 at 10:32 AM akaniklaus notifications@github.com wrote:

I would also like to let you know that, high-interest lending is also possible in cryptocurrency field. Since that you're interested with longer-term portfolio rebalancing methods such as Markowitz, I believe that a lending bot could make a great sense to use in conjunction with such methods: https://github.com/BitBotFactory/poloniexlendingbot

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Marigold/universal-portfolios/issues/9#issuecomment-346995284, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeqKJPAPQi9Hm0Mtg1GodWL1iJq8iCvks5s6TBFgaJpZM4QEm49 .

akaniklaus commented 6 years ago

Annualized compound interest rate is much higher. Please, check here for historical lending rates: https://www.coinlend.org/#!History

akaniklaus commented 6 years ago

Wouldn't be better to use Markowitz Portfolio with "Sortino Ratio" or "Calmar Ratio with Expected Maximum Drawdown" as in the following paper? http://alumnus.caltech.edu/~amir/mdd-risk.pdf

Did you ever check this implementation that is also nice? https://github.com/czielinski/portfolioopt

Marigold commented 6 years ago

The interest rates are interesting indeed. I'll have to do some research on my own.

As for using Sortino ratio or expected drawdown - I haven't tried these in particular, but I've tried optimizing other metrics than mu - q * sigma like historical sharpe or drawdown. It didn't work that well, but maybe the theoretical results from that paper could be better than optimizing purely on historical data. Thanks for sharing it, I'll read it over the weekend.

On Tue, Nov 28, 2017 at 2:31 PM akaniklaus notifications@github.com wrote:

Wouldn't be better to use Markowitz Portfolio with Sortino Ratio or Expected Maximum Drawdown? http://alumnus.caltech.edu/~amir/mdd-risk.pdf

Did you ever check this implementation that is also nice? https://github.com/czielinski/portfolioopt

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Marigold/universal-portfolios/issues/9#issuecomment-347523808, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeqKBtyTvaHwPxf8Z1M2EeTJ-j9_Qb6ks5s7AsOgaJpZM4QEm49 .

akaniklaus commented 6 years ago

About Sortino Ratio: https://www.sunrisecapital.com/wp-content/uploads/2013/02/Futures_Mag_Sortino_0213.pdf They also mention about Omega Ratio at the end of the document.

akaniklaus commented 6 years ago

@Marigold This paper is very interesting: "Algorithmic trading in limit order books for online portfolio selection" https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2952371

akaniklaus commented 6 years ago

@Marigold Do you have any idea on how to preselect a limited set of best assets for mean-reversion algos? I don't prefer using Markowitz to do that because in crypto market correlations shouldn't be as important as in stocks.

Marigold commented 6 years ago

Hm, from top of my head I can think of these metrics to quantify mean-reversion behavior:

  1. fit ARCH-like model to time series and look at its coefficients
  2. calculate Hurst exponent
  3. backtest mean-reversion strategy on assets and pick these that performed well (you can do some kind of bootstrap to reduce variance of the estimate)

Probably not the answer you were looking for :) I'd recommend you to check out some papers on mean-reversion, there's plenty of papers around

akaniklaus commented 6 years ago

@Marigold Plenty of papers but unfortunately not when it comes to real problems and their solutions.

Auxiliumdesign commented 6 years ago

@akaniklaus I and a friend of mine has been working on similar algos for cryptotrading for about a year now. It is a very interesting field! Would be nice to have a chat if you are interested in some cryptotalk.

akaniklaus commented 6 years ago

@Auxiliumdesign You can reach me via Skype ID 'akaniklaus'

Auxiliumdesign commented 6 years ago

I've sent you a message!