Thursday, December 14, 2017

Dollar Cost Averaging

Dollar cost averaging (DCA) is an investment strategy where you invest a fixed amount of money on a regular schedule over time. If you have some money, let's say $100, which of these strategies is better?

Strategy #1: invest $100 on day 1
Strategy #2: invest $1 every day for 100 days (i.e. DCA)

You convert your investment back to dollars at some future date, say after 1000 days. As expected, there is a risk vs reward trade off. Both strategies are expected to have some positive interest. Many people I talk to claim that DCA is a valid strategy: although it has a lower expected reward than strategy #1, it also has lower risk. They argue that you should choose strategy #1 or #2 based on your risk vs reward preference.

I have always had an uneasy feeling about this argument. Intuitively I feel like DCA never is a good strategy. In the past I have had various arguments with people about why, but I have never been able to make a convincing argument. Out of the people I have talked to, it also feels like I am the only one who has this opinion.

I have never done any research into this topic or taken any relevant classes. Today I had another argument with some friends, and I finally decided to just run some computer simulations comparing various strategies under different conditions. Figuring out the math is hard, but running computer simulations and looking at the statistics is easy.

One insight with strategy #1 is that you can adjust your risk vs reward trade off by just investing less money. Less investment = lower reward and lower risk. We can introduce this as a new strategy:

Strategy #3: invest $X (e.g. $75) on day 1 and keep $(100-X) in your wallet.

With DCA you can adjust the risk vs reward trade off using different investment schedules. Investing $10 every day for 10 days will have higher risk and higher reward than investing $1 every day for 100 days.

For completeness, we can compare a few other strategies:

Strategy #4: invest $100 on day 50
Strategy #5: invest $100 on day 100

My simulation adds random fluctuations to the investment, so we can measure the expected return and variance of the different strategies using millions of simulated investments. I also experimented with various parameters of the simulations (e.g. how much the investment fluctuates, the duration of the investment, the growth rate of the investment, etc).

Under normal conditions:
- Strategy #1 has the highest expected return and highest variance.
- Strategy #4 and #5 never are useful. You can get the same expected return with lower variance using DCA or strategy #3.
- Strategy #3 is better than DCA. At any level of preferred variance, strategy #3 can get higher expected return. At any level of preferred expected return, strategy #3 can get lower variance.

Surprisingly, there actually are some scenarios where the situation reverses and DCA becomes superior to strategy #3. When the size of the random fluctuations becomes large enough, DCA becomes better. The size of the fluctuations has to become pretty huge - much larger variation than I would expect from normal stock index funds. It might make sense to use DCA for investing in something like bitcoin.

Friday, July 14, 2017

Rock Paper Scissors Using LSTM

Recently I have been doing a lot of research into using LSTM for data compression (in cmix, lstm-compress, and tensorflow-compress). In 2011 I made a website about Rock Paper Scissors AI. I realized that LSTM should be good at playing RPS, so today I made a small demo to do that:

Saturday, May 20, 2017

Solar Panels

My wife and I recently bought a house in the San Francisco Bay Area. We are getting solar panels installed on the roof of the house. In this area it is a great financial investment - there is a lot of sun and the electricity rates are high. There is also a 30% federal tax credit for solar installations.

Determining the best size of the system to install depends on your electricity usage. Producing more power than you consume is less profitable.

We got quotes from three different companies. The quotes are surprisingly different:

System size: 2.7 kW
Estimated annual production: 4,036 kWh
Cost before rebate: $11,394
Cost after rebate: $6,381
Price per watt: $2.36/W

System size: 2.61 kW
Estimated annual production: 3,526 kWh
Cost before rebate: $10,559
Cost after rebate: $7,391
Price per watt: $2.83/W

System size: 2.61 kW
Estimated annual production: 5,050 kWh
Cost before rebate: $7,050
Cost after rebate: $4,950
Price per watt: $1.9/W

SunWork has by far the best price at $1.9/W. Not only that, but their system is estimated to produce far more kWh than the two other companies. Their system uses microinverters instead of a central inverter. Microinverters have a longer warranty: 25 years instead of 10 years. They are also more efficient than a central inverter. With a central inverter the system only produces as much as the least efficient panel. Microinverters allow each panel to independently perform the DC-AC conversion and also allow you to monitor the performance of each panel.

Another reason SunWork estimates a larger annual production is because they did a better job of optimizing the layout of the panels on our roof. Each company had a different layout:




SunWork managed to squeeze all nine panels onto southern facing parts of the roof. Sunrun had cool software which created a 3D model of our roof and automatically detected vents and surrounding trees (useful for modelling shadows). For all three companies the panel placement seemed to be done manually - combined with some software to estimate annual output.

Update: SunWork panels have been installed! Here is a dashboard to monitor our system output.

Update#2: The final price was lower than their initial quote: $6,565