Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am working on my new year resolutions and learn to invest in individual stocks. I am slightly biased towards tech companies.

Why I am doing this:

- Improve my business (learn about different business models) - Improve my product sense - Hearing good CEOs talking at their investors is a great lesson.

What I am building:

- Use Azure to automate stuff and set up notifications for events I am interested in.

- Use python to backtest strategies.

I wrote this thing last week https://medium.com/@davinci260/why-only-buy-when-you-can-als...



I believe there's an error in your cagr function: I didn't look at how it's used too closely, but whenever you see 365 in financial code it's usually an error. It would be more appropriate to use 252, the average number of trading days for US equity exchanges, instead of 365.

I have some questions regarding the article: How are you hedging? What instrument are you hedging with? Also, how much leverage are you taking on? If you're not selling out any original shares and shorting an equal amount of some other shares (see my first question), you're taking on 2x leverage. As such, you're not really comparing apples to apples.

Moreover, Puru Saxena is not really doing what your blog is describing. What he's doing (at least according to some Twitter posts I read), is holding a market neutral portfolio where the long side consists of specific stocks he likes and the short side an ETF to hedge the geography exposure. Because he's investing in high beta tech stocks, he can lower his beta and his geography exposure through shorting the appropriate ETF. This is a smart strategy, but is only going to work on high beta companies.

Anyways, in general, we do not want to look at returns when analyzing an investment strategy. Instead, we should look at the Sharpe ratio. While I don't have enough information to say whether your results are correct, honestly, they don't pass the smell test. I feel like the EMA window is overfit, your CAGR is being boosted by the use of 365 instead of 252, and I suspect that you are taking on leverage, which might be also boosting your returns.

Also looking at the code, it's needlessly complex because you're dealing with actual shares and such. A better method is to just deal with returns directly and represent your portfolio as a vector of weights, the sum of the absolute values should add up to zero with no leverage.

The type of hedging you describe in your example is equivalent to just selling the shares, but a little worse. You're paying interest on your shorts, so you're losing 2% annually from holding shares and shorting some other shares. There's literally no reason why you would want to hold both a long and short position on a stock.

I recommend you check out Quantopian (https://www.quantopian.com/). It makes your life so much easier and they have all the data, plus great risk models and alpha factor generation tools.

Also as a fellow software engineer interested in finance, you might like my financial blog, https://cryptm.org/.


Awesome thanks a lot for the constructive feedback! There are a lot of things to unpack. Let me answer the question.

> Also, how much leverage are you taking on? Equal to the value of the portfolio since this how much you need to have 1-1 hedge. The hedging instrument is just short selling the stock.

> Puru Saxena has a different portfolio.

I am inspired by the hedging mechanism that he uses and I started with the same technical triggers.

> The type of hedging you describe in your example is equivalent to just selling the shares, but a little worse.

I see what you are saying and I agree with it.

I am not sure if it is actually worse. Avoiding a tax event on your long position (which in the long run is the most profitable) is actually really important as you more capital to compound.

I know of Quantopian but I have never used and the calculation seemed simple enough to do with vanilla python/pandas. I did not think of using vector of weights, that would be a better approach and much more scalable.

360 would probably be a better number. https://www.investopedia.com/terms/c/commercial-year.asp for CAGR calculation. I did that for the interest but forgot about it in the CAGR.


Yeah, and nay.

365 makes sense talking interest. But so does 360. And then there's +1/+2. And more fancy stuff. It all depends on currency. So, 365 makes sense from a mentality of opportunity cost and accrual, given an ACT365 currency.

And I wouldn't go with 252 because of OTC.

I also would strongly advise against Sharpe ratios. From the title of the post - which I have my own problems with the post, but - "Why only buy when you can also sell?" really highlights why not to go with Sharpe, or Sortino, ratios: non-normal returns are the normal. Better with Omega, which is a concept already 20 years old but finance oddly sticks to the 80s.


The Omega ratio doesn't solve the problem of non-normal returns. In fact, it makes it worse: The Omega ratio requires a cumulative distribution function of the returns!


I would love to know your problems with the post :) If you got spare time feel free to reach out either here or via email or via Twitter, whichever is more convenient




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: