Home Battery Optimization: Power Arbitrage

Storage of energy is one of the major hurdles for the electric grid. Electricity is best managed by instantaneous generation and consumption. Economic storage of energy could allow for cleaner generation and decreased peak accommodation. In this post, I investigate the optimization of storage independent from renewable generation.

The first case is trading electricity using a battery and grid connection by buying or selling electricity at hourly prices. The second case incorporates a houses’ load. In each case, the goal will be to optimize when the battery should be charging or discharging.

It is important to note that the price and load data is deterministic, as if future price and load is already known from a prediction model. In actuality, the data comes from Comed’s load and price sites. The data is hourly for the first week of January 2016. Load data is measured in kWh and price data is in dollars per kWh.


The battery is a 7 kWh Tesla Powerwall. The optimization model ensures that the battery can’t be charged above 6.4 kWh max based on Tesla’s specifications, nor below the minimum of zero. Besides the battery size, another restriction is a maximum power flow of 3.3kW based on Tesla’s website.


2 Tesla Powerwalls


The optimization is done with scipy package’s optimize. Minimize is the function that was used. This means that the function being optimized needs to return a negative dollar value because we actually are trying to solve a maximize optimization problem.

The first scenario is optimizing when power is bought or sold from the grid and stored as needed in the battery. The goal is to maximize the revenue made from buying electricity when its cheap and selling electricity when the price is high. It’s a classic financial scenario of making money by buying low and selling high. The model states that we are able to make $1.62 over the course of the week. The results come in the form of an hour by series of how much power to buy or sell. Graphed, we can see the results of the state of the battery as compared to the price of electricity.


The second scenario incorporates the residential load in kWh for a house. The previous assumptions are the same, except that now, the system also needs to provide for the electricity needs of a house. This ultimately costs -$3.57 which makes sense because you’re now using the electricity you acquire, and not able to sell it.


There are certainly many considerations that were not taken into account such as the lost efficiency of the battery. The model was a bit oversimplified as you wouldn’t be able to perfectly predict the price and load for a residence’s electricity. All in all, the main goal of using python’s optimization function was accomplished. We also learned something about what money there is to be made using Tesla’s Powerwall to arbitrage power prices. If you can make $1.62 over the course of a week, and a Powerwall costs $3,000; you can turn a profit in 1,852 weeks or 36 years. No get rich quick scheme here.

Python code on Github.





Author: Andrew Bray

My name is Andrew Bray and I'm interested in the energy needs of the future. I graduated in Industrial Engineering from the University of Wisconsin - Madison. Since, I've done data analysis work and currently work for a technology consulting firm. I'm heavily involved in helping out the Jane Addams Resource Corporation with the technology side of their job training work. I'm an avid runner, food hacker, and beer purveyor. Feel free to contact me about any and all of the above interests.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s