Why having a bike beats the stock market

About 4 years ago, I wasn’t fully convinced whether I should buy a good but more expensive bike. Now, I can back that decision with data on why it was a good investment and how it beats the stock market. I will break it down in parts: how I use it, how much it costs, and collateral benefits. I may follow up this post with some basic maintenance tips.

You can skip the background story, if you only care about the essence of this post. I have listed the important “lessons learnt” in following sections . The background story only mentions my path towards buying a good bike. The reasons why someone else may do it, will differ. The only reason I list them here, is that this is a personal blog and I would like to have my story written so I can read it again after some years, before I forget the details.


How I use the bike

I go almost everywhere by bike (unless I walk). Specifically:

  • Commuting. Going to work is ~5 km. I make it in about 15 – 18 minutes each way. Going by public transport is about 30 minutes each way. That means that, each month, I cover about 200 km and save about 8 – 10 hours of commuting.
  • Excursions. This was applicable in spring/summer which adds about 1000 km per year due to a couple of trips.
  • Other. I may have to run some errands, go somewhere due to a hobby (mostly chess)/visit friends/go out/etc. They usually add up to another 100 km per month.

I use a bike no matter the weather. I always wear helmet and always have a backpack with waterproof clothes in case it rains. Then:

  • Warm weather without rain. Fingerless gloves.
  • Rain. I am covered everywhere by something waterpoof: jacket, pants, overshoes, helmet cap, gloves, cover for the backpack. In the backpack, I also put a spare set of clothes in case I somehow get wet (almost never happens) or too sweaty (more frequent). I also keep a second set of clothes in the office in case I forget to renew my clothes supply.
    It important to note here that all surfaces have to be covered, otherwise they get wet. That does not only apply to our body, but also to our shoes or head.
  • Cold weather. Winter gloves. A long piece of cloth that covers my neck, ears and part of my face.
  • Snow. See cold weather + rain. I also wear ski goggles. It looks funny but it is very effective. Otherwise because the snow falls slowly, it goes in my eyes and I cannot see very clearly. Plus, it covers another part of my face, so I don’t feel cold.
  • Haze. Same as snow.

How much I saved

This is going to be a direct comparison with the money saved by not taking the public transportation. I calculate the yearly ticket for public transportation as 782 francs per year. After 4 years, I have saved about 3000 francs.

How much I earned

Someone could argue there are also benefits that cannot be quantified. Some of them also result in cost savings, but that’s not what is important. At the end of the day, those benefits make you happier.

It is also proven through research, that exercise boosts our happiness levels. My experience agrees with that. When I had to take the bus/train/tram I was feeling that something is wrong and was missing from my everyday life. I remember vividly that when I had a dislocated shoulder and I couldn’t use my bike for about 1 month, I wasn’t feeling that happy (and it wasn’t just because of the dislocated shoulder).

Biking also has given me the opportunity to participate to some social activities (well, bike with friends) or meet new people that I wouldn’t have otherwise.

How much it cost

I keep a spreadsheet with all the costs since I bought the bike. There, I include everything related to the bike, including:

  • accessories (example: bike lights, batteries)
  • clothes (example: waterproof clothes, bike shoes)
  • spare or upgraded parts (example: chains, tires, cogs, brakes, lube, grease, cranksets)
  • tools (example: bike stand, bike toolset, chain wear indicator, pump)
  • service (2 times before I start doing it myself)

The bike cost 1500 francs. The cost of accessories/clothes/spare parts/tools (including a bike stand)/service (2 times before I start doing it myself) amounts so far to another 1500 francs.

Buying a bike is a good investment

After four years, I have replaced almost all moving parts with new ones (everything that touches the chain has been replaced), and upgraded some of them (rear brake, chainrings). I have also collected tools, clothes and accessories. I believe all of those together are at least worth the initial price of the bike. I could even argue it is worth even more since just today I replaced the chain and the jokey wheels and it feels like new. Nevertheless, this is beyond the point.

I have broken even on the cost of bike and its extras. To simplify things, let’s cross out a few terms. We assume that the expenses on the bike (see above) negate the expenses on public transportation. They also cover the cost of the bike. So let’s also cross that out. Let’s assume that the value of the bike when I bought it is the same as now (due to replacement/upgrade of parts + all the tools/clothes/accessories I have collected).

In short, 4 years ago, I put a amount of money into something, spent another a, and got back 3a (the money I saved from the transportation tickets = 2a + bike itself is another a).

Solving the equation:

2 * a * (1 + x)**4 = 3a

We find that this corresponds to a compound interest rate of about 10% per year during these four years. That beats by a great margin the stock market (7%) or bond market (5%) and it is a much safer investment (depending on your home location).

Unfortunately, this extrapolation is kind of misleading since the cost savings of a bike are of linear nature in reality. That should not, though, retract from the point of this section, that from a purely financial point of view, it makes sense to invest money in buying a good bike.


Background story

Buying cheap bikes

When I moved to Switzerland, after a few months, I bought my first second hand bike. It cost around 100 francs. It survived for a few months. When something broke down, I learnt that asking for repair would cost about 50 francs. I decided to buy a second second-hand bike instead, and use the first one as spare parts. That didn’t really happen, since the second bike was quite different and the parts didn’t match. Neither did I have the tools or knowledge to do that. So I bought a third, and eventually a fourth one after the third one was stolen. Despite having bought 4 bikes within 2 years, it was still cheaper than a yearly pass for the public transport (around 500 – 600 francs per year for people under 25 years old). Biking for two years daily was with no signs of slow down was enough to convince myself that this is something I really like.

Buying a good bike

A couple of months after graduation, I started working. There, I met a co-worker who was interested in buying a good bike. He started asking around what kind of bike would fit his needs. His needs were very close to mine. Some of those were:

  • Convenient for commuting.
  • Fast on a road.
  • Can go off road (mountains, gravel, etc).
  • Can cover large distances.
  • Not very heavy.
  • Good brakes.

That’s how I learnt about cyclocross bikes. There are in-between road and mountain bikes.

Back then, I knew nothing about bikes and I was too lazy to research it. Reading without trying it through experience was not feeling very compelling to me. So, to bootstrap my entrance to the higher-end world of bikes, I decided to trust my co-worker and buy exactly the same bike.

The decision was not easy. The cost was a multiple of the cost of the yearly pass for public transport. I remember when I was a kid, I could not understand why someone would buy an expensive bicycle when with the same amount of money they could buy a motorbike.

On the other hand, I knew that I would not have to buy a new bike for a long time, I would enjoy the better bike more, and also, buying a better bike gives you a good excuse of buying good replacement parts. Later on, I also learnt how to maintain the bike myself.

On servicing the bike

I knew almost nothing about how to service a bike. I learnt most of the things through youtube. I highly recommend the gcn youtube channel. Usually, I search for gcn + bike part I want to service.

The other important aspect of servicing a bike yourself is having the necessary parts and tools at hand. Usually, I am able to work on the bike on weekends only and ordering some parts may take a week for their delivery. It is useful to have some tools already at hand (I find useful to have a bike tool set), emergency supplies (inner tube), and anticipate needs before the next time you need to service your bike. This is not as hard as it sounds since most things on a bike can wait for a week (tires, chain, cogs, brakes, etc). For some things, I know I am going to use them regularly, so I just keep a stock of them (lube, screws, ferrules, grease, kitchen roll, …).

There are also great communities online that help people who work on their bikes. My personal favourite is r/bikewrench.

If you are not into fixing things manually, give it a try. It is fun, and makes you appreciate the elegance and simplicity of the design of a bike. With so few moving parts, it achieves great flexibility. I wish one day I will be able to design my code as elegantly, as a bike is designed.



Studying in Zurich under strict budget

This post is for ETH students who have strict budget constrains.

Before going into the details, two meta-comments.

First, I never felt comfortable sharing these details. Nevertheless, my past self (almost 7 years ago) would find it useful.

Second, if you can work on the side (even 1 day/week — especially in CS), that may be enough to give you more room in your budget.

Temporary place

Youth hostel / AirBnB / friends.

This is needed until you find a more permanent place of stay, and sometimes that may take a while (2-3 weeks until you move to your permanent place).

If you see a listing about a room in an apartment that is not rented for a while, you may contact the owner and ask if you can stay for few days by paying pro rata. This is useful if at some point (usually weekend) the Youth hostel is fully booked. I never tried the AirBnB/friends solutions because they were not available.

Food: If you can’t cook at the temporary place, you can take the precooked chicken. You can clean your hands with wet wipes afterwards.

Permanent place

Try student housing.

Alternatively: Find two more people. The goal is to find an apartment in a building that is going to be renovated/demolished after ~6 months. You can find an apartment that can host 3 people with a price around 1000 francs. This is usually too expensive for 1 student, and too bothersome for a family to move out again after few months.

Using you have good chances of getting accepted for the apartment.


Go to a German supermarket (Aldi, Lidl) once per week. Budget around 50 francs. Look at the price per kilo and not per item.Avoid food that costs more than 10 francs/kilo. Pasta/rice/chicken/pizza/Paella/toast/sausages can be cheap. Buy fish cans with different sauces that you can use it on pasta/rice so you don’t get bored of eating the same thing. Don’t eat at Mensa. Eat at home or take food from home with you.


On Saturday mornings on Helvetiaplatz you may find second hand clothes very cheap. Once, I bought a pair of jeans that were only 2 francs. Otherwise, try Brockenhaus.


Buy a second hand bike. Put in your backpack extra clothes. Have waterproof jacker, pants, gloves, shoe covers. Don’t repair your bike once it is broken. Buy a second one around 100 francs after 4-5 months, if the first one is broken. Use the materials from the first one as replacement for the second one. Even without that, it is cheaper than public transportation (amortized).

Alternatively, if you don’t like biking in the rain, get a Halbtax and a Gleis-7 card. Check the weather prediction every morning. It rains about twice per week in Zurich. If you return after 19.00 by train, you will have to pay only the 1-hour ticket to go to ETH.

Moving out/in

Initially, buy cheap furniture for all people together. Share transportation costs. When you move to your second apartment, rent a big car. Do the cleaning yourself carefully. It takes at least a day. One more day for the move.

Going out

Go to parks, friends places’. Invite friends. Spend time at ETH.

Health insurance

Get an exception if you have a health insurance in your home country. Otherwise, find the cheap insurance for students. Go to the dentist/do checkups in your home country.

Airplane tickets

Book well in advance for Christmas. It may be more convenient to have your roundtrip flights starting from Zurich, but usually it is cheaper the other way around.


Get the cheapest option. Call home through internet. If your parents do not use a chatting app, you can always buy credits on Hangouts/Skype.


Check if someone from a neighbouring apartment wants to share their connection. Refer your friends/other students and get a referral from someone.


Some costs are not recurring (e.g. clothes, bike, moving out, airplane tickets). Budget for those.

Make money

Try an internship or a part time job even at ETH — ask your advisor. Check the regulations. You can work during summer/exam period as much as you want. During the semester, 2 days per week.


Check the guide from ETH. Ask other students. Focus on your studies. You are not alone.

Heroes or enemies?

The one-armed woman said, “There was a movie called Maple recently. I don’t know if you’ve seen it. At the end, an adult and a child stand in front of the grave of a Red Guard who had died during the faction civil wars. The child asks the adult, ‘Are they heroes?’ The adult says no. The child asks, ‘Are they enemies?’ The adult again says no. The child asks, ‘Then who are they?’ The adult says, ‘History.’”

From the book “The three body problem”

Learn about chess endgames from stockfish

Stockfish has a very well documented codebase. Someone can learn a lot about chess even by just looking at the comments. As an example, here is what stockfish does in certain end games from the perspective of the strong side. For the weak side, the opposing plan is true. As a note for the rules that follow, they may not characterize all possible positions. If not, then the position has to be evaluated by looking more closely to its specifics.

Plenty of material vs King

– Just push the lone king towards the side and keep the distance of the two kings short.

King + Knight + Bishop vs King

– Similar as above. The difference is that the right corner is the corner with the same color as the bishop.

King + Pawn vs King

– It is evaluated based on some magic tables.

King + Rook vs King + Pawn

– If stronger’s side’s King is in front of the pawn, then this is a win.
– Similarly, if the weaker’s side’s King is too far from the pawn, it is also a win for the strong side.
– The position is a draw if the pawn is advanced and protected by the opposing king.

King + Rook vs King + Bishop

– Draw.

King + Rook vs King + Knight

– Draw, unless King and Kight are too far away.

King + Queen vs King + Pawn

– This is usually a win for the side with the Queen.
– The exception is when the Pawn is on the 7th rank, protected by the King, on the Rook or Bishop files, and the strong’s side King is far away from the pawn.

King + Queen vs King + Rook

– This is a win for the stronger side.
– The strong side wants the two kings closer and the enemy King driven to the edges.

King + 2 Knights vs King

– Draw.

King + Bishop + Pawns vs King

– This is in general a win for the strong side.
– Exception is when the pawns are in the same Rook file, where the promoting square is of different color compared to the Bishop and the enemy King can arrive there in time.

King + Bishop + Pawns vs King + Pawn

– Similar as above.
– Exception is when the pawns of the strong side are on a Knight’s file, there is an enemy’s pawn on the 7th rank and the bishop cannot attack it or if there is only one pawn from the strong side in that file. Then, there is a draw as long as the weak’s side King is within two squares from the blocking pawn, on the back two ranks, and the strong side’s King is farther away.

King + Queen vs King + Rook + Pawns

The weak is the one with King + Rook + Pawns.

– It returns a draw if the pawns form a “fortress” on the third rank and they defend the rook, and the king is at most up to rank 2, and the enemy king is farther away (rank 4 or beyond).

King + Rook + Pawn vs King + Rook

– Draw if the pawn is not too far advanced (5th rank), the defending king protects the queening square, and the attacking king is away. The draw is achieved through the third-rank defense.

– Draw if the pawn is on the 6th rank, by checking from behind the enemy King.

– Draw if the pawn is on the 6th rank or higher, the defending King controls the queening square, the defending rook is on the first rank and either the tempo is on the defending’s side or the distance between the two kings is at least two squares.

– Draw if the pawn is on A7, attacking Rook on A8, defending Rook behind the pawn, and defending King on H7 or G7. Symmetrically for a pawn on H7.

– Draw if the defending king is blocking the pawn and the attacking king is too far away.

– Win if the attacking king is closer to the pawn compared to the defending king. The pawn should not be on a rook’s file, though, and it should be close to be promoted.

King + Rook + Pawn vs King + Bishop

The only rule here concerns a possible pawn on a Rook file, which under some conditions can be a draw.

King + Rook + 2 Pawns vs King + Rook + 1 Pawn

Draw if the stronger side has no passed pawns and the defending king is actively placed.

King + Pawns vs King

Draw only if the pawns are on a Rook’s file and the defending king is in front of them.

King + Bishop + Pawn vs King + Bishop

– Draw if the defending King is in front of the Pawn and he can’t be kicked out.

– Draw if bishops are of opposite color and one of the following is true: (a) pawn is on rank 5 or earlier (b) the defending king is in front of the pawn or (c) the defending bishop attacks one square in front of the pawn and it is at least three squares farther away from the pawn.

King + Bishop + 2 Pawns vs King + Bishop

To have a forced draw, we need opposite color bishops. Then:

– Draw if the pawns are on the same file and the defending king is in front of the pawns.
– Draw if the pawns are on adjacents files, the defending king is in front of them, and the defending bishop controls the squares in front of them.

King + Bishop + Pawn vs King + Knight

– Draw easily if the defending King is in front of the Pawn, in a square that the attacking Bishop cannot go.

King + Knight + Pawn vs King

– Draw if a Rook pawn is on the 7th rank and the defending King is blocking it.

King + Knight + Pawn vs King + Bishop

– Win only if the Knight can prevent the Bishop from taking the Pawn.

King + Pawn vs King + Pawn

– Draw chances if the weaker side could achieve a draw even without its pawn.
– Exception is when the strong’s side Pawn is too advanced and the pawn is not on the Rook’s rank. Then, if the weaker side could have drawn even without its pawn, then it could have winning chances with its pawn.

Married functions

On Gödel Escher Bach, on page 137 there are two “married” functions defined:

for n >= 1:
F(n) = n – M(F(n – 1))
M(n) = n – F(M(n – 1))

for n = 0:
F(0) = 1, M(0) = 0

I wondered whether it is easy to define three function that increase their value every time n is increased by three, using only addition, subtracting and recursive calls to the previous value of the functions. It turns out it is not too hard to find some.

for n >= 1
F(n) = n – M(n – 1) – N(F(n – 1) + M(n – 1) + N(n – 1) – 2)
M(n) = F(n – 1)
N(n) = M(n – 1)

for n = 0:
F(0) = 1, M(0) = 0, N(0) = 0

Reverse recursively single linked list

There are two main ways to reverse a linked list: iteratively and recursively. I find the recursive solution easier to understand and cleaner. Unfortunately, I didn’t find any examples with tail recursion in the top results that I looked at, so I list my approach.

If someone wants to try their own approach, they can try on:

On marginalization

“I can’t bear to hear a human being spoken of with contempt just because of his group identification-even by other human beings. It’s these respectable people here who create those hooligans out there.”

The quote is from Dors from “Prelude to foundation” by Isaac Asimov.

“These respectable people here” refers to the snobbish class of people who made these comments. The “hooligans out there” refers to the marginalized part of the community who has developed violent behaviour.