Thursday, November 17, 2011

Areal B-Splines: Interpolating the area under a curve with smooth B-splines in Matlab

B-splines are great for smooth interpolation between points. But what if the "points" you have are not actually points, but are the area of segments under the curve?

Say for example you have a time series with oil production in 2011, on a monthly basis. From this information, you would like to generate a smooth time series that gives you the daily oil production. This is an interpolation of sorts, but not quite a standard one - what you want is for the sum of the interpolated daily oil production to add up to the monthly production: in other words, the area under the curve of instantaneous production must be equal to the monthly production that is given.

It is also an interesting technique to use when looking at forward curves, and trying to guess how the monthly price may break down into daily spot prices. For instance, is February is traded higher than January and December is traded lower than January, you will assume that if each day in January had a price, the daily price would be higher towards the end of January and lower at the start of January. You know, instead of assuming the same price over the whole month?

Does that make sense? For a bit more details on the technique, have a look at this paper.

We use a quartic spline (fourth-degree piecewise polynomial with value, first derivative and second derivative which are equal at the knots), a maximum smoothness criterion, and boundary conditions.

The graph below is created by calling the "smartSplit" function like this:
 out_values = smartSplit([0.0 15.0 20.0 26.0 30.0 31.0], [100.0, 25.0, 50.0 14.0 5.0], 0:0.05:31)  



Isn't the graph nice? The blue line represents the input to the function, if we just pasted the average of the integral over the entire interval. The green line is our interpolated line, which has the same integral as the blue curve, but has beautiful spline properties such as continuity and continuity of derivatives. In addition, it has a maximum smoothness condition.

Here is the main function in nice and simple Matlab code:

 function [piecewise_polynomial] = arealSplineInterpolate(x_values, values)   
    %% arealSplineInterpolate   
    % Creates a spline that has given integral/area under each interval of    
    % a curve.   
    %    
    % Input:   
    % - x_values: the intervals on the x-axis of the dataset to be interpolated.   
    %    Values are in increasing order. The size should be one larger   
    %    than the "values" parameter, and each two consecutive values   
    %    x_values(i) and x_values(i+1) give the interval over which   
    %    values(i) is the integral/area under the curve.   
    %    For example: [0.0 15.0 20.0 26.0]   
    % - value: the area under the curve of each interval.   
    %   For example: [100.0, 25.0, 50.0]   
    %   
    % Output:   
    % - y_values_out: the values when the resulting interpolating function is   
    %     evaluated at x_values_out.   
    % Use shorthand names   
    t = x_values;   
    m = values;   
    n = length(t);   
    a_rows = 4*(n-1);   
    a_columns = 5*(n-1);   
    A = zeros(a_rows, a_columns);   
    b = zeros(a_rows, 1);   
    % Boundary conditions   
    A(1,1) = 0;   
    A(1,2) = 0;   
    A(1,3) = 2;   
    b(1) = 0;   
    A(2,end-4) = 12*(t(end)-t(end-1))^2;   
    A(2,end-3) = 6*(t(end)-t(end-1));   
    A(2,end-2) = 2;   
    b(2) = 0;   
    A(3,1) = 0;   
    A(3,2) = 0;   
    A(3,3) = 0;   
    A(3,4) = 1;   
    b(3) = 0;   
    initial_conditions = 3;   
    % Integrals of the resulting curve must hit the given values   
    for i=1:n-1   
      row = initial_conditions + i;   
      h = t(i+1) - t(i);   
      A(row,5*i-4) = (1/5) * (h^5);   
      A(row,5*i-3) = (1/4) * (h^4);   
      A(row,5*i-2) = (1/3) * (h^3);   
      A(row,5*i-1) = (1/2) * (h^2);   
      A(row,5*i ) = h;   
      b(row) = m(i);  
    end   
    % Curve must be continuous, i.e. segments meet at knots   
    for i=1:n-2   
      row = initial_conditions + (n-1) + i;   
      h = t(i+1) - t(i);   
      A(row,5*i-4) = h^4;   
      A(row,5*i-3) = h^3;   
      A(row,5*i-2) = h^2;   
      A(row,5*i-1) = h;   
      A(row,5*i ) = 1;   
      A(row,5*(i+1)) = -1;   
      b(row) = 0;   
    end   
    % Curve must have continuous first-derivative at knots   
    for i=1:n-2   
      row = initial_conditions + (n-1) + (n-2) + i;   
      h = t(i+1) - t(i);   
      A(row,5*i-4) = 4*h^3;   
      A(row,5*i-3) = 3*h^2;   
      A(row,5*i-2) = 2*h;   
      A(row,5*i-1) = 1;   
      A(row,5*(i+1)-1) = -1;   
      b(row) = 0;   
    end   
    % Curve must have continuous second-derivatives at knots   
    for i=1:n-2   
      row = initial_conditions + (n-1) + 2*(n-2) + i;   
      h = t(i+1) - t(i);   
      A(row,5*i-4) = 12*h^2;   
      A(row,5*i-3) = 6*h;   
      A(row,5*i-2) = 2;   
      A(row,5*(i+1)-2) = -2;   
      b(row) = 0;   
    end   
    % Maximum smoothness condition   
    h_mat = zeros(5,5);   
    big_h = zeros(5*(n-1), 5*(n-1));   
    for i=1:n-1   
      h = t(i+1) - t(i);   
      h_mat(1,1) = (144/5)*h^5;   
      h_mat(1,2) = 18*h^4;   
      h_mat(1,3) = 8*h^3;   
      h_mat(2,1) = 18*h^4;   
      h_mat(2,2) = 12*h^3;   
      h_mat(2,3) = 6*h^2;   
      h_mat(3,1) = 8*h^3;   
      h_mat(3,2) = 6*h^2;   
      h_mat(3,3) = 4*h;   
      big_h(5*(i-1)+1:5*i,5*(i-1)+1:5*i) = h_mat;   
    end   
    % Solve the resulting equation   
    A_t = transpose(A);   
    zm = zeros(size(A,1), size(A_t,2));   
    pm = [eye(5*(n-1)) zeros(5*(n-1),4*(n-1))];   
    dm = inv([2*big_h A_t; A zm]);   
    bm = [ zeros(size(pm*dm,2)-size(b,1),1); b];   
    x = pm*dm*bm;   
    % Make a matlab piecewise polynomial   
    cnt = 1;   
    x2 = zeros(n-1, 5);   
    for i=1:n-1   
      x2(i,:) = x(5*i-4:5*i)';   
    end   
    piecewise_polynomial = mkpp(t,x2);   
  end   


And a simple utility function for it, which produces the graph above:
  function [out_values] = smartSplit(x_intervals, values, x_out_intervals)   
    %% smartSplit   
    % Uses the areal spline interpolation method to subdivide a list of   
    % known intervals and values into another.   
    pp = arealSplineInterpolate(x_intervals, values);   
    flc = @(x) ppval(x,pp);  
    out_values = [];   
    for i=1:length(x_out_intervals)-1  
      out_values(i) = quad(flc,x_out_intervals(i),x_out_intervals(i+1));   
    end   
    % Show a plot  
    clf()  
    hold on;  
    b1 = values./(x_intervals(2:end)-x_intervals(1:end-1));  
    b2 = out_values./(x_out_intervals(2:end)-x_out_intervals(1:end-1));  
    stairs(x_intervals,[b1 b1(end)], 'LineWidth',2)  
    stairs(x_out_intervals,[b2 b2(end)], 'g-','LineWidth',2);  
    hold off;     
  end   

Let me know in the comment fields if you have any questions, or use this for something interesting!

Sunday, October 30, 2011

Solve Any Sudoku With 10 Lines of Python Code

Some time ago I was talking with a friend who is hooked on Sudoku puzzles. The conversation went nowhere, because my friend was busy thinking about Sudoku. So I thought to myself, if I solve all Sudoku puzzles at once, perhaps my friend can pull his head out of his arse and normal conversations can resume. And because the puzzle is such a simple one, I bet him that I could do it in only 10 lines of code in my favourite programming language: Python.

A few hours of work, here is the solution I came up with - it is not perfect, it is just brute force, and not particularly elegant. But it fits into 10 lines of Python code, and serves as an interesting case study in list comprehension in Python.

The task is to solve sudoku of all sizes and complexities, and giving all solutions if there are multiple. Input and output code do not count as part of the 10 lines, only that part that solves the puzzle counts towards the 10 lines.

Input
The easiest, but perhaps most inelegant, way to input the Sudoku board, is to put it directly into the Python code like this:
1:  input_board = [   
2:                  5,3,0,0,7,0,0,0,0,  
3:                  6,0,0,1,9,5,0,0,0,  
4:                  0,9,8,0,0,0,0,6,0,  
5:                  8,0,0,0,6,0,0,0,3,  
6:                  4,0,0,8,0,3,0,0,1,  
7:                  7,0,0,0,2,0,0,0,6,  
8:                  0,6,0,0,0,0,2,8,0,  
9:                  0,0,0,4,1,9,0,0,5,  
10:                 0,0,0,0,8,0,0,7,9  
11:                  ]  
12:    
13:  board_size = 9  
14:  subsquare_width = 3  
15:  subsquare_height = 3  
16:    

As you can see, the board is just a list/array of numbers, where 0 means a field is blank, and whatever other number means whatever other number is pre-filled in as part of the puzzle. I also have three variables giving the size of the board, the width and height of the subsquare.

Output
Simple command line output sounded the easiest to me, but rather than simply print the board as an array/list of numbers - which would be very difficult to interpret, I created a pretty-print function:
1:  def prettyprint(board, board_size):  
2:      print  
3:      for i in range(board_size):  
4:          print board[i*board_size:i*board_size+board_size]  
5:    

Which creates an output that resembles the playing board. Of course, it would be possible to make the output nicer and more readable, but this should be good enough for now.

Solution
And now to the meat of the problem: solving the board. My solution is a recursive function, which finds the first available blank, creates a list of legal entries for that position based on the current board configuration, fills in each one in turn and calls itself. If there are no blanks on the board, the program has reached a solution.

In pseudo-code, something like:
1:  def solve(board):  
2:    if no more blanks:  
3:      print solution  
4:    find first blank  
5:    find a list of possible values for the blank  
6:    for each possible value:  
7:      insert possible value into board  
8:      solve(board)  

Firstly, how to identify the first known blank? Well, since blanks are represented by 0, and the board is a straightforward Python list, we can just call the index function: i = board.index(0). If no entry with 0 exists, this call will throw an exception, which is perfect, because if there are no blanks, then we know we have arrived at a solution, so we can just print it:
1:  def solve(board):  
2:      try: i = board.index(0)  
3:      except: prettyprint(board, board_size); return  
4:    

Secondly, when we have found a blank, we must find out which numbers we could possibly fill in. And this is the most intriguing part of the solution. In the global space, we first create three boards with the same label for each column, row and subsquare, like this:
1:  col_labels = [i%board_size for i in range(len(input_board))]  
2:  row_labels = [i/board_size for i in range(len(input_board))]  
3:  sqr_labels = [(board_size/subsquare_width)*(row_labels[i]/subsquare_height)+col_labels[i]/subsquare_width for i in range(len(input_board))]  
4:    

The reason for this will be obvious in a moment, just bear with me. To get a better idea, let's see what these three codes create. In our 9x9 example with 3x3 subsquares, the three lines of code directly above create three dummy-boards that look like this:
1:  col_labels = [   
2:                  0,1,2,3,4,5,6,7,8,  
3:                  0,1,2,3,4,5,6,7,8,  
4:                  0,1,2,3,4,5,6,7,8,  
5:                  0,1,2,3,4,5,6,7,8,  
6:                  0,1,2,3,4,5,6,7,8,  
7:                  0,1,2,3,4,5,6,7,8,  
8:                  0,1,2,3,4,5,6,7,8,  
9:                  0,1,2,3,4,5,6,7,8,  
10:                 0,1,2,3,4,5,6,7,8  
11:                  ]  
12:    
13:  row_labels = [   
14:                  0,0,0,0,0,0,0,0,0,  
15:                  1,1,1,1,1,1,1,1,1,  
16:                  2,2,2,2,2,2,2,2,2,  
17:                  3,3,3,3,3,3,3,3,3,  
18:                  4,4,4,4,4,4,4,4,4,  
19:                  5,5,5,5,5,5,5,5,5,  
20:                  6,6,6,6,6,6,6,6,6,  
21:                  7,7,7,7,7,7,7,7,7,  
22:                  8,8,8,8,8,8,8,8,8  
23:                  ]  
24:    
25:  sqr_labels = [   
26:                  0,0,0,1,1,1,2,2,2,  
27:                  0,0,0,1,1,1,2,2,2,  
28:                  0,0,0,1,1,1,2,2,2,  
29:                  3,3,3,4,4,4,5,5,5,  
30:                  3,3,3,4,4,4,5,5,5,  
31:                  3,3,3,4,4,4,5,5,5,  
32:                  6,6,6,7,7,7,8,8,8,  
33:                  6,6,6,7,7,7,8,8,8,  
34:                  6,6,6,7,7,7,8,8,8  
35:                  ]     
36:    

These three dummy-boards enables us to quickly generate a list of numbers that are illegal to insert in a blank space like so:
1:      bag = [board[j] for j in filter(lambda x: (col_labels[i]==col_labels[x]) or (row_labels[i]==row_labels[x]) or (sqr_labels[i]==sqr_labels[x]),range(len(board)))]  
2:    

The filter method creates a list of board positions that have the same column, the same row and the same subsquare as the blank space we are currently considering filling in. Then, with a for-loop in list-comprehension-style, we pick out the entries in those positions. This could be split into several lines to make it more readable, but this is one of the shortcuts I used to fit it into 10 lines. I apologise for the ugliness of it.

Now that we have a list of numbers that are not permitted in the current blank space, we simply need to run through each of the possibilities except those, try inserting the possibility into the board and move on to the next blank and do the same thing:
1:      for j in filter(lambda x: x not in bag, range(1,board_size+1)):  
2:          board[i] = j; solve(board); board[i] = 0  
3:    

And that simple procedure, ladies and gentlemen, can create all the solutions to all Sudoku ever created.

Complete Solution
For those who want to experiment, pin back your lug'oles, drop the following code into a file, mess with it, and then run it through your Python interpreter:
1:  input_board = [   
2:                  7,0,0,4,0,9,0,0,6,  
3:                  5,0,9,0,8,6,1,2,0,  
4:                  1,4,0,0,0,0,0,0,0,  
5:                  6,5,0,8,0,0,0,0,0,  
6:                  0,2,4,9,0,1,5,6,0,  
7:                  0,0,0,0,0,2,0,1,8,  
8:                  0,0,0,0,0,0,0,8,7,  
9:                  0,7,5,2,4,0,6,0,1,  
10:                  2,0,0,3,0,7,0,0,5  
11:                  ]  
12:    
13:  board_size = 9  
14:  subsquare_width = 3  
15:  subsquare_height = 3  
16:    
17:  def prettyprint(board, board_size):  
18:      print  
19:      for i in range(board_size):  
20:          print board[i*board_size:i*board_size+board_size]  
21:    
22:  col_labels = [i%board_size for i in range(len(input_board))]  
23:  row_labels = [i/board_size for i in range(len(input_board))]  
24:  sqr_labels = [(board_size/subsquare_width)*(row_labels[i]/subsquare_height)+col_labels[i]/subsquare_width for i in range(len(input_board))]  
25:    
26:  def solve(board):  
27:      try: i = board.index(0)  
28:      except: prettyprint(board, board_size); return  
29:      bag = [board[j] for j in filter(lambda x: (col_labels[i]==col_labels[x]) or (row_labels[i]==row_labels[x]) or (sqr_labels[i]==sqr_labels[x]),range(len(board)))]  
30:      for j in filter(lambda x: x not in bag, range(1,board_size+1)):  
31:          board[i] = j; solve(board); board[i] = 0  
32:        
33:  solve(input_board)  
34:    

Unless the number of solutions is very large, this will only take a fraction of a second to run on any computer. Enjoy!

Please feel free to use this code as you wish. If you use this solution for anything fun/interesting/at-all, please provide a link to this page from yours, and drop me a comment!

Thursday, October 27, 2011

Investors take 50% loss on Greek bonds, bank shares rally

The stock market is a strange place. As it became clear that Greek bond holders need to accept a 50% loss, the banks with great exposure to sovereign debt mysteriously rally: Deutsche Bank and Morgan Stanley are up over 17% today, whereas UBS, Citigroup, GS, JP Morgan and BOA are all up around 10%.

How does a 50% loss in Greek bonds translate into a 17% rally?

Well, quite simple: either the market was wrong yesterday about the economic prospects of Europe, or they are wrong today about the economic prospects of Europe. Or both. In fact, probably both.

Disregarding today's stock market rally, you can only imagine the jealousy that is building up in the other struggling European economies at the gift packet given to Greece. Portugal, Italy, Ireland and Italy must be green with envy, and by now have probably laid great plans for forcing their sovereign debt holders to accept a loss.

Nobody seems to be concerned with "moral hazard" any more, a term whose usage peaked in 2008, and quickly fell into disuse.

It should be just a matter of time before the other countries line up to get their debt forgiven. But I do not expect the market to rally when the subsequent debt forgivings happen.

Google Labels Bitcoin "Unacceptable Content"

Google is apparently not a particularly fond of Bitcoin. When trying to enable Adsense for this blog, they denied the application on account of "Unacceptable site content".

Google appears to think that there is something dishonest or immoral with Bitcoin. Granted that Bitcoin can be used for several illegal, illegitimate or morally questionable activities, but all currency can.

But I wanted to make it clear: this blog is about things I find fascinating at any one time. At the moment, Bitcoin intrigues me. Another day, it will be something else. I'm just a regular nobody writing stuff on a scale between "meh" and "EPIC".

For the record, Mr. Google, I do not advocate, condone or support any illegal, illegitimate or immoral activity - whether it is paid in Bitcoin, US dollars, Japanese Yen, Russian Rubles or monopoly money. And I do not care much for the insinuation.

Bitcoin: Natural Gas Equivalence Price, Coal Equivalence Price and Oil Equivalence Price

The previous post established that the energy to generate a Bitcoin is currently around 19 kWh/BTC. Although it may not be obvious to all, this gives a straight-forward way to calculate possible anchor points for the Bitcoin exchange rates by looking at electricity, natural gas, coal and oil prices - both regionally and globally.


If Bitcoin be considered an energy-dependent product, much like fertilizer, the price should theoretically follow developments in energy markets very closely - just like fertilizer prices.


Note that the following anchor points are estimated using the current difficulty level and energy prices.

Electricity
The current US wholesale market for electricity gives a marignal cost of $0.83/BTC, as shown in our previous post. Residential prices are different from the wholesale market, however, and the current EIA short term market outlook report cites a US residential average of around 12 cents per kWh, giving a marginal cost of roughly $2.30/BTC.

Maybe somebody with more insight can tell me if residential/commercial US consumers easily can gain access to electricity close to wholesale prices?

European wholesale markets are around €60-€70/MWh, giving a marginal cost of around €1.24/BTC. Several places in Europe, it is fairly easy to get access to electricity at wholesale prices (plus a small margin), so a clever miner may have a marginal cost quite close to this.

Natural Gas
Natural gas can be used as a power generation fuel, and anchor points for natural gas could theoretically become anchor points for Bitcoin. So what is the natural gas equivalence price?

Natural gas is also a regional commodity, with large variations throughout the world. Current US prices are around $3.7/MMBtu, which translates into a marginal cost of  $0.53/BTC, assuming 45% power plant efficiency.

European natural gas is around €25/MWh, equivalent to a marginal cost of €1.06/BTC.

Coal
Coal is particularly interesting in this respect, because it is a power generation fuel that is priced globally (more or less). Current coal price (CIF ARA, API#2) is around $117/tonne, which gives a marginal cost of $1.12/BTC.

Oil
Since oil is priced globally, it is interesting to try the same exercise with oil. A current price of $109/bl gives a marginal price of around $3.50/BTC - which is quite high, mostly owing to the inefficiency of burning oil for power generation.

Conclusion
Someone with access to an efficient gas-fired power plant in the US and wholesale gas markets, miners could get a marginal cost of $0.53/BTC. With access to wholesale electricity markets miners could achieve a marginal cost of $0.83USD/BTC or €1.24/BTC. And at current exchange rates, that is a very lucrative proposition. Even at US consumer electricity prices, the value of mining currently appears positive, although much more costly at $2.30/BTC.

The main conclusion, however, is that Bitcoin could in theory follow energy prices. Natural gas, oil and coal often move in parallel - and since Bitcoin can be considered an energy-dependent product, much like fertilizer which tracks developments in energy markets very closely, it should in principle also track energy markets.

As the commodity best reflecting global energy prices, will oil be the commotidy to track for Bitcoin traders?

Wednesday, October 26, 2011

Bitcoin Price Drivers

The value of a Bitcoin seems hard to peg, with the exchange rate to USD reaching above 30 USD/BTC earlier this year, and dropping to below 3 USD/BTC a few months later.

The main question discussed in this post is: what determines the value of a Bitcoin? And how significant are the different factors? Yes, we are searching for the Bitcoin price drivers, and we intend to analyse Bitcoins relationship to wholesale energy prices.


Around every 10 minutes 50 BTC are mined, which is the collective target rate of the Bitcoin network. That means 7200 BTC are created per day, and at the current rate, that translates to around $20,000 USD/day. And with approximately $100,000 worth of Bitcoins exchanged on the exchanges each day, miners cashing in could account for up to one fifth of the current daily traded volume. This then stands to be a large portion of daily volume, and has the power to be the main price determinant. It should be considered more closely.

Mining also has costs denominated in conventional currencies, and therefore also helps tie the Bitcoin value to conventional currencies. The hardware and energy used for Bitcoin mining must both be purchased with conventional currency. The hardware constitutes a fixed cost, and the energy is the variable cost. Considering that the hardware is a sunk cost for current miners, it will be profitable for them to mine when energy costs are below the value of the resulting Bitcoins, and it will be unprofitable to mine when energy costs are above the value of the resulting Bitcoins.

The behaviour of the miners is therefore determined by the difference between energy cost and Bitcoin value. This is well-known amongst miners. But the aggregate market dynamics it creates is not well investigated, so this is an interesting topic for Bitcoin traders.

Electricity is the commodity consumed by miners, and the wholesale price of electricity is generally determined by a combination of the price of coal, the price of gas, the price of oil/gasoil or the weather. Electricity, energy commodities and weather all have heavily traded futures markets, so discovering a relationship would have great implications for Bitcoins.

So let us try to relate Bitcoin to energy numerically.

Expected payout for a miner is (h*B) / (D * 2^32), where h is the number of hashes computed, B is the number of Bitcoins received per block and D is the difficulty. A block pays out 50 BTC and the difficulty is currently 1468195 - which means a miner would currently have to compute around 1.26*10^14 hashes per Bitcoin. A Radeon HD 6990 is estimated to manage about 1.84*10^6 Hashes per Joule, meaning a 6,8541,843 Joules are spent per Bitcoin mined, or just above 19 kWh.

In an ideal world, the miner would have access to a wholesale electricity market, say the PJM, where a futures contract for Nov 11 is trading a little below $44 USD/MWh. With this price, you would get a marginal cost of generating 1 BTC at 0.836 USD.

That means, for those with access to wholesale, or near-wholesale, electricity prices, mining is worthwhile at this difficulty level. A sophisticated miner could have access to lock in electricity rates on the spot market, and would continuously monitor the spot electricity price, the network difficulty, and the exchange rate between Bitcoin and the local currency.

Although this could very well be a profitable strategy, it would probably be a mistake, with all due respect, to assume that miners are running such a sophisticated setup.

Using the EIA residential sector electricity prices, around 12 cents per kWh for US average throughout 2011, we get an estimated cost of around $2.30 per Bitcoin, which seems much less lucrative, but is still below the current exchange rate.

Electricity prices vary from region to region, so it would be difficult to find a single one that acts as a price driver for Bitcoin - but many energy and power markets move in parallel, and such moves could theoretically influence the Bitcoin exchange rate by influencing the marginal cost of mining.
But Bitcoins are currently traded way above this marginal cost of wholesale mining, which means there is either a limiting factor in play here, or the demand rate for Bitcoins simply exceeds 50 BTC/10 minutes.

We will go more into detail on this in a later post - stay tuned!

Tuesday, October 25, 2011

Bitcoins: More Than A Geek's Wet Dream?

Bitcoin is an economic internet experiment that has become quite famous. By now, everyone and their grandmother's kitchen sink has heard about Bitcoin - but in case you haven't, let me summarise: Bitcoins are a new form of "currency" that is well-suited for use on the internet.


It is a brilliant marriage of technologies that will make any true geek slobber. It's like the computers and economics had a baby, who then married cryptography and math, and had an affair with finance and politics. Moreover, it appeals to the geek's secret belief that most of the world's problems can be solved with technology.


But what are the characteristics and consequences of Bitcoins? Can it ever be more than a geek's wet dream?

A Bitcoin Primer
First, let's take a quick glance of how it works. Bitcoin runs on a decentralised peer-to-peer network. Everybody connecting to the network receives a copy of the "ledger", which is a file containing a record of all the transactions made with Bitcoin. Each person has one or more "wallets" that show how many Bitcoins have been transferred to you. To transfer Bitcoins you create a message with the number of Bitcoins to transfer, an address for the receiving wallet, sign the transaction with a private cryptographic key from your wallet and broadcast it to the network so that it can be included in the public ledger. New Bitcoins are handed out as rewards for verifying and underwriting the ledger - called "mining" - and happens according to predetermined rules.

Since it is enscribed in a ledger, everybody can check the ownership of the Bitcoins. But it still retains some anonymity, because one seldom knows who an address key belongs to.

Instead of giving the details of how it works and how to use it (you can read more about it here, if you want), I would like to focus on what the implications are and whether it is in a position to grow beyond the niche market it serves.

Bitcoin Strengths
So far, it is hard to see what all the fuss is about: payment over the internet is not exactly a something new. But Bitcoin has a few compelling advantages over the established methods, such as:
  • Easy transactions over the internet
  • Enables anyone to send and receive payments over the internet
  • No transaction fees
  • Nobody can block a transaction
  • No chargebacks
  • No private information needs to change hands
  • Predictable coin generation rate
Where's does money come from?
Money is a representation of value. It is popular to say that it has two purposes: to facilitate trade, and as a storage of value. But those are not really distinct: storing value simply means facilitating trade across different time periods, and facilitating trade means simply serving as an abstract representation of other valued objects.

In traditional currency systems, money is issued by some authority. Usually, the central authority is following some kind of charter and is dedicated to keeping the system stable and predictable. Sometimes they mess up, intentionally or unintentionally, and cause hyperinflation or deflation. The results of these missteps have been depression, revolution and war, and the examples throughout history are abundant.

The issuing of Bitcoins, on the other hand, does not rely on a central authority. Bitcoins come into existence at a predetermined rate, about 50 per 10 minutes or so at the moment, and the total amount of Bitcoins is limited to 21 million. The Bitcoins are given as rewards to those verifying and underwriting the transactions that are being broadcast on the network, and can in principle be any one of the connected nodes.

A lot of ink has been spent on the limit of 21 million Bitcoins. In general, central banks issue currency with the aim of causing a modest amount of inflation - it is believed that this inflation can be beneficial for economic growth since it gives people an incentive to spend their money sooner rather than later, and it reduces the burden of debt through time - which is also an incentive to spend more money quicker because you will receive less goods and services in exchange for your money if you postpone the spending.

With an upper limit of 21 million Bitcoins, deflation will be the inevitable result as ever more goods and services need to be represented with the same pool of Bitcoins (assuming that Bitcoin survives). Deflation is believed to incentivize hoarding and discourage borrowing and investment. After all, why buy something today, when I can buy more for the same amount tomorrow?

On a personal level, it could seem like deflation is a good thing - your savings increase in value over time. And looking at modern consumption-based society, perhaps it would even be a good thing for the planet to get some saving going on? Besides, those with savings are often seeing the growth of their savings outstrip inflation already, so they are experiencing a kind deflation. Furthermore, people with debt are normally paying interest which is higher than the inflation, so it seems they don't see any bottom-line benefits at the end of the day anyway.

I am trying to make the point that deflation already exists, all things considered. Increasing savings and slowing down consumption could be good things for the planet, but good for the planet may not be good for the economy - at least not short term. A deflationary spiral can apparently lead to depressions, mass unemployment and economic stagnation, such as the Japanese "lost decade".

Let's take a look at it from yet a different perspective: if you provide a good or a service in exchange for any kind of money, then that money must eventually be spent on something - otherwise you have, in a very real sense, provided your good or service for The longer you can postpone your spending in a deflationary environment, the more you can receive in return. But this possibility already exists for most people, as an interest-bearing bank account will normally give you an interest higher than the inflation rate. Has that stopped people from spending? Of course, this argument assumes the deflation rate is moderate. Investment may also continue, as many holders would probably prefer chasing higher returns than passively growing their real value by waiting for deflation. Modest deflation seems more likely to cause a shift in interest rates, rather than spark hoarding, panic and depression.

That may not have been the thoughts of the creators of Bitcoin, and tomorrow they may not even be my thoughts anymore either, but at the moment it makes some sense. And it hardly seems likely that Bitcoin will have any such influence on the economy anyway. I'm not trying to make any particular point for or against inflation or deflation, or even Bitcoin - I simply intend to share my thoughts on the characteristics and consequences.

What will determine the success or failure of Bitcoin?
Bitcoin has many, many challenges ahead if it is to expand outside of the current niche.

Currently, it appears to be most popular for unlicensed gambling, unlicensed trading and drugs. The appeal for these players is obviously that there is no central authority to deny your payments, and that payments are largely untraceable.  This shady business puts the whole technology in a bad light, and makes legitimate users wary. So Bitcoin has a serious image problem, and desperately needs legitimacy any way it can get it.

Bitcoins are surrounded by an aura of mystique and geekiness. That may be appealing to some of us, but is probably repelling many others and making their heads spin with the explanations found on the web. The message of Bitcoin needs to be seriously simplified for the mainstream.

Currently, the exchange rate to traditional currencies is prohibitively volatile. If you could buy bread and milk with Bitcoin, that might not be such a big concern. But in general you can't, and you need to exchange it for a more widely used currency for it to be useful. So this is a combined challenge, since the lack of goods and services priced in Bitcoin forces all the users to use an exchange - and then suddenly volatility is a huge issue.  Also merchants who price their goods in Bitcoin need to eat, and often change the prices in response to changes in the exchange rate.

An objection that is often raised is the disproportionate amount of Bitcoins hoarded by the early adopters, and it is easy to see why somebody would distrust such a system. What can be done about it? Can someone press the great big reset button? Would we want that to happen? Important as it may be now, this issue is likely to decrease with time as the early adopters cash in and set their Bitcoins free. But this still represents a serious challenge for the legitimacy of the currency.

More than a geek's wet dream?
Bitcoin is already a success. It serves a niche market quite well, and is so far an interesting experiment that is fun to follow and tinker with. Lucrative for some, waste of effort for many, but it offers a fascinating exploration of technology and economy for the open-minded geek.

Despite the serious impediments to going mainstream, it seems to be reaching a wider audience every day. Press coverage has been generous, and every mention of Bitcoin in the right context lends it a little more legitimacy.

The greatest potential for Bitcoin at the moment, is as an in-game currency in online games. If games would standardise on using Bitcoin in their games, Bitcoin would immediately gain access to a large amount of technology-friendly users that would boost the legitimacy and the usage of the currency. The currency would spread like wildfire. However, very few game creators would be interested in connecting the in-game economy to the outside world, even though this could give both the release and Bitcoin a great boost.

Bitcoin is without a doubt a promising and exciting technology, but will I ever be able to buy milk and bread for Bitcoin? Not anytime soon. At least not until Bitcoin sheds the "underground" image, simplifies the message and finds a solution for the high exchange rate volatility.

---

Accepting donations at: 1NAa9tS81ucAezVztMDDcLc2ffZE1AV7KS