Categories
perspective

Golden Section Search

For me, implementing code really helps me to understand the algorithms (i need to know) better. It might sound a bit odd in that you might need to understand the algorithm before you can implement it. And that’s partially true. An understanding is definitely required. But, with TDD and iterative processes ingrained, discovery of what makes the algorithm tick is made possible through doing it (by repetition and/or implementation).

Repetition helps you to understand it and use it. Implementing it in code is like rediscovering the algorithm from the beginning. It’s a small taste of that journey- and it’s addictive 🙂 Anyhooo, the Golden Section Search is not an exception- but surprisingly trivial. Maybe it was just all the fluff around the topic that got me distracted….

class Golden
  ...
  def search(tolerance)
    return if(@b - @a) <= tolerance

    dif =R*(@b-@a)
    x1 = @b - dif
    x2 = @a + dif
    vx1 = i_eval(x1)
    vx2 = i_eval(x2)

    if(vx1 > vx2)
      @b = x2
    else
      @a = x1
    end

    search(tolerance)
  end
  ...
end

“i_eval” just evaluates the formula you supply (and uses the built-in Ruby expression evaluation) but the part that makes the grok for me is the if(vx1 > vx2) bit.

The way the text books explain it is pretty long-winded. The interval of uncertainty changes, but you’ve got the unknowns a,b,x1 and x2 floating around and changing positions all the time during the explanation. Plus you’ve got to now try remember case 1, case 2 and case 3. Eish. And all that inter-mixed with function and set notation. But that can be maths for you: pick any number between 0 and 10 => pick any integer from the domain of real numbers over the interval from, and including 0 to, and including 10.

The short of it lies in… :

‘b’ changes to x2 if vx2 [or f(x2)] is smaller (or equal) and
‘a’ changes to x1 if vx1 [or f(x1)] is smaller ..

… for the next iteration, everything else keeps the same value. That’s it.

And graphically, it also makes more sense to simplify that for one second and draw the lines in and see how ‘a’ and ‘b’ move along the axis iteration after iteration. Once that’s settled, going back to the ever pedantic yet accurate language of maths is then a whole bunch easier.

Categories
Business

Refinancing Model

While explaining Morty, I left with a parting shot: Be careful about consolidating your debt. And before I continue, i will make the disclaimer that I’m not a financial advisor, just a curious number cruncher. So not entirely satisfied about not giving an example, I’ve now had the time to consider the model more carefully to present you with some numbers. So here goes…

Scenario: 2 loans exist, one for a house taken out in May 2004 for 800K at 14%, and one for a car in May 2006 for 160K at 16%. Come May 2009, you decide to consolidate your debt (for whatever reason).  Note, I will purposefully line up the dates and use nice round numbers to get the point across. Also, the interest rates used reasonably reflect the situation in South Africa at the time (as my memory serves).  But regardless of the actual numbers, the same maths (and hence lessons) apply. The math follows:

Home Loan:

  • 800K at 14% over 20 years = 9.9K repayment
  • You will end up paying 2.4M for the house over 20 years
  • That’s 1.6M in interest alone
  • After 5 years, you have paid off 600K, but have only 54K in equity

Car Loan:

  • 160K at 16% over 5 years = 3.8K repayment
  • You will end up paying 230K for the car over 5 years
  • That’s 73K in interest alone
  • After 3 years, you have paid off 140K, but only have 83K in equity

Now you want to consolidate your outstanding debt under one loan. And, we’ll assume you’re refinancing under more favourable interest rates- else why would you even reconsider it? So what you actually owe at this stage will be the sum of the settlement values on each loan, which will largely depend on the agreements you have in place. Let’s assume everyone plays nice and they let you off with the original loan less your current equity. It could be a lot worse! You now owe a total of approx 840K which you need to refinance, and because one of them is a house, you might end up reasonably re-mortgaging over 20 years again:

New Loan:

  • 840K at 11% over 20 years = 9.2K repayment
  • You will end up paying 2.2M for the combined loan over 20 years
  • That’s 1.4M in interest alone

So, where do you stand at this point?

You’ve definitely made a short-term saving in terms of your monthly repayments (10+4 vs 9). Your cash flow is a lot smoother! But with 2 seperate loans though, you would have paid a grand total of 2.6M (2.4M + 230k) over the lifetime of those loans. With a consolidated loan, you would have paid a grand total of 2.9M (2.2M for new loan plus payments already made on previous loans of 740K). Plus, your cash flow potentially deteriorates over the medium term. Once the car loan would have matured, you’re paying almost the same repayment (especially if by this time the interest rates have dropped) anyway. And then in the long term, you’ve got an extra 5 years of repayments to cover which is worth 0.5M of cash flow in the future.

All, in all, the simple summary of it that is you end up losing approximately 300K in the long run.

But it’s not all that bad- it can actually be to your advantage too. If the difference between the original financing rates and the new financing rates are large enough, you can actually save yourself a lot of money in the short, medium and long term too. But that requires approximately a 5% difference _at least_.

So think twice before you jump fall for the debt consolidation marketing trap. Make sure whoever is advising and structuring it for you that they go through all the numbers and look at it long-term. Obviously the refinancing will always benefit the lender which is expected and acknowledged, but just how much is fair and reasonable? We all have the right to make informed choices- and we should insist on that right- and just because it might sound technical or complicated or involve a lot of numbers, doesn’t mean it can’t be explained in a way that makes sense to you.

Hope that helps to at least think a little more deeply about the choices out there….

Categories
perspective Technology

Software Guarantees

It’s a long time coming: consumer protection for software. And it’s a good not altogether bad thing. How much software out there promises the world but delivers nothing but a world of headache? Of course, the devil is in the details and how they go about enforcing that is going to be interesting. Can you imagine the legal copy? Of course, this opens up the world for computer forensics in a big way. We might even get a new show: CSI Brussels, the Bits-n-Bytes version. Ha.

But from an engineering perspective, this kind of move will most certainly sift out the hype from the functional (and create more of a different hype) and all the war around the best technology might abate (while the war between lawyers rage) so that the job can just get done by those actually doing the job and knowing how to do it (which, by this stage will not be many). It also means developers will choose their tools more carefully and with more consideration and be less prone to just adopting the next best thing just because it’s the next best thing. Which, in turn will impact the software tool market (probably negatively though). Who’s going to write code to interact with a service (or even allow interaction) if you got no control over how the other end of your integration works and you could possibly get sued for thrice more than you earned on the job. Imagine the insurance?

Of course, i’m assuming that the implementation of this kind of policies (or others related to it) is well though-out, fair and just 🙂 The evil side to this kind of policy is just too staggering. That’s something for the budding authors (of CSI) out there to write about…

Categories
Life perspective

Your Word

In days of yonder (although, probably more of a romantic legend) “your word” used to mean quite a bit. No legal fluff or long-winded contracts- it was your word that counted most. Today, that still is true, but we also have legal contracts because, i guess, in days of yonder, much like today, people renege on their word for various reasons. And that is a complex issue on its own, but reasonably i see it as primarily coming down to not taking your own word seriously enough. The opposite of that is interesting…

And by word i do mean commitments and promises, both explicit and implicit. Explicit as in “I promise i’ll get that done by tomorrow” and implicit as in “Sure, i can do that by end of day”.

So the opposite is that you take your own word so seriously, you check yourself at every turn and make no commitments or promises, either explicitly or implicitly. Your speech changes to “I might have that done by the end day, but no guarantee”. It is a lot better in terms of expectation management, being realistic and does give yourself room to breathe a little; even under-promise somewhat. As a default, neither are great.

On the one side you get to disappoint a lot of people through broken commitments, and on the other side, you get to disappoint yourself because you never get to challenge yourself. It’s one of those situations where neither end of the spectrum really works, and the middle ground is pretty soft. The best is to fold the spectrum back on itself.

Take your word seriously AND make big (not brash) commitments (and then pull it off). Of course, the wisdom and grace to get that perfect won’t come without a bruised ego, but, like i read once, it’s hard(er) to stumble when you’re on your knees. Don’t be scared to commit and give yourself a challenge and then take your commitment seriously enough to see it through.

The ultimate is like saying “I do”. It’s not “I might” or “I could” or “I probably should”. Commit, lock and load and make it work. The fruit is way more than you could ever positively dream of.