Hacker News new | ask | show | jobs
Show HN: CashGraphs – A securities portfolio optimizer (cashgraphs.com)
82 points by justinluther 1441 days ago
Hello,

This is a portfolio optimizer I made to help select portfolios for my clients. I'm a personal financial adviser. I generally put my clients in a mix of low-fee index funds and ETFs and I use this to set an appropriate allocation based on the client's risk tolerance.

I have been working on this as a side project to 1) improve the theoretical underpinnings of my investment recommendations and 2) improve my coding skills with frameworks like Vue and Torch. Here's the repository for the frontend: https://github.com/justinluther502/cashgraphfront.

The frontend site is Vue 2 + Vuetify, and the backend is an AWS lambda function running the Torch optimizer. I am still working out kinks in the backend, particularly cold-start issues because the Lambda function has to load the entire Torch library (~2GB). This occasionally causes the AWS API Gateway to reach max timeout before the Lambda function finishes. Any tips on addressing this would be much appreciated. My first thought is maybe to pare down the Torch library used in the Lambda function because I am only using a small subset of the full library.

The optimizer function itself is designed to overcome several classic shortcomings in Modern Portfolio Theory (MPT) (https://en.wikipedia.org/wiki/Modern_portfolio_theory). Unlike textbook implementations of MPT, this optimizer can utilize non-normal returns distributions, risk metrics besides variance, and can allow the user to specify tail behavior, such as asset correlations behaving normally most of the time but converging to 1.0 in severe downturns. Most of these "fixes" happen during the generation of custom "flavors", or asset selection universes. I have 3 flavors pre-built and there is some information on how they are constructed in the flavor selection page.

Any feedback greatly appreciated!

Justin Luther justinluther@lutherwealth.com https://www.lutherwealth.com

9 comments

Like the idea and execution a lot! Being IANAF, I like to refer people to chapters 4–7 of this lecture from Robert Shiller’s “Financial Markets” Yale course: https://youtu.be/_B_24GUWdSM?t=1269 (~40 minutes). The concept gives a solid insight into why and (broadly) how to diversify. With your work, a very minor note is that the chartjs pie chart always fully redraws for me from the 12 o’clock position on risk preference changes, which makes visual comparisons minimally more difficult. It’s purely cosmetic, because the table communicates this much better anyway, but maybe it’s an easy fix.
Thanks! I've also noticed that the pie chart re-rendering is quite busy and visually distracting. But javascript is by far my weakest layer in the whole stack so I've struggled to fiddle with it without breaking it :)
The default portfolios are weird.

The Six Asset classic (the default) includes Japanese stocks, and Emerging Market Corporate bonds, but no other international assets?

The basic stock and bond includes only high yield bonds?

The 12 asset includes international stocks and international bonds but then specifically adds additional Canadian stocks and Canadian bonds on top of that?

Yes that's definitely a struggle. There is a balancing act involved in getting a set of time series that share 1) a common methodology for calculating index levels and returns, 2) a long lookback period, 3) index levels that account for dividends, 4) freely available and relatively simple to download to csv or other useful format. St Louis FRED database was very useful in this regard. I could definitely make some nicer flavors by using a paid source for historical asset returns but I'm not willing to do that just yet.

The next flavor I make will probably use something from: http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_...

And for that one I'd like to use some non-normal distributions and other fancier characteristics.

> I am still working out kinks in the backend, particularly cold-start issues because the Lambda function has to load the entire Torch library (~2GB). This occasionally causes the AWS API Gateway to reach max timeout before the Lambda function finishes.

I could not find your backend code to confirm, but I suspect you could convert that Lambda function into a long-running app to avoid cold-start issues. This could be deployed with an app engine (e.g. Heroku, Google App Engine, AWS Elastic Beanstalk), as a Docker container (e.g. AWS EKS), or directly on a server (e.g. AWS EC2). Feel free to contact me via my profile, happy to point you in the right direction.

Thanks! In a previous iteration I used some of those solutions, both Heroku and Render. I thought this might be a good use case for Lambda because the API doesn't get called very often, and it's really just one function. Refactoring the backend code to keep the lambda handler skinny seemed to help. If I continue to have problems I will definitely look at these options.
Looks nice, but I'm confused how to read the Expected Returns y-axis. My assumption would be that's an annualized ROI, but it's displaying for instance that US Stocks return 0.7% ? Also no idea if Risk has any objective unit?

Running the 6 asset classic, it is slightly amusing that the result is essentially just a classic 70-30 stock/bond mix (risk dependent obviously), and the other 4 assets are <5% of portfolio.

Would be nice if you could include also representative ETFs of a given asset class (I assume they exist) to make the results more actionable.

Thanks for your feedback! This is on my to-do list of things to fix-- some of the flavors have been developed using monthly returns and some use annual. In both cases the x axis is variance of the periodic returns. Also in some cases the returns are log returns which is also a todo. I will fix it so that the x axis is labeled with the user's choice of risk metric used by the optimizer. Also, I should have mentioned it, but the risk choice isn't implemented in the backend yet so the risk metric choice just defaults to variance for right now.
Looks neat, but it's a bit unclear to me how to read the Pareto frontier graph. Also, would you share your references for the fixed you implemented/give recommendations for papers/books that can give useful domain knowledge to an ML person reading up on portfolio optimisation? I.e. the "actually useful" parts of the literature?
Thanks for the feedback! I'll try to label the chart a little more clearly. The y axis is expected returns, the x axis is expected riskiness. I show the generated optimal portfolios alongside the original constituent assets that comprise the portfolios. So ideally you want a portfolio up and to the left, but higher-returning securities tend to be riskier.

I found the literature on vine copulas to be helpful, particularly the following presentation: https://www.birs.ca/workshops/2013/13w5146/files/Brechmann.p...

I used that as a helpful guide for ways to create some of the more interesting returns simulations.

Great tool! Thanks for building this.

I noticed lack of below asset classes in the list:

1) US Small Cap Stocks (e.g. Russell 2000 Index) 2) International Large Cap Stocks (MSCI EAFE Index) 3) International Small Cap Stocks (MSCI EAFE Index) 4) Emerging Market Large Cap Stocks (MSCI Emerging Markets Index)

Adding these would greatly improve the optimizer.

Idea to make it more user friendly to folks like myself who don't understand how your app is supposed to work:

Provide a UI layer which contains some instructions and points out features and their uses. Looking at the app, I don't quite know what I am supposed to do, or use it to figure out. Perhaps provide some example use cases or personas, alongside the UI layer of instructions.

Thanks for the suggestion! Right now I have attempted to do what you are describing, but the user has to click OK on the initial "welcome" dialog box to get stepped through the tour. If you click outside of the box to close it, you skip the tour. Definitely something to improve.
On mobile, the instructions when first loading block the screen, making it more difficult to follow. Maybe a simple, quick video showing a few scenarios would be easier to follow?
I agree! A video could definitely help, and I will try to change the display of the instructions on small screens.
please keep working on this

i suspect it's not going to be free for very long

if it remains open source there's something no other fintech app has

Thanks very much for the kind words!
Just curious to play around ... is the Lambda function on github too?
I'm keeping it private for now but might open it up in the future. Thanks!
How does this compare to mlfinlab?
I believe the idea with mlfinlab is for users to build and test models to predict asset returns. In other words, a tool to generate alpha. I may be wrong about this as I'm not familiar with mlfinlab.

CashGraphs is more oriented towards passive asset allocaters who want to pick a portfolio that has high expected returns for a given risk-tolerance level.