Trial and Epic Fail

Ventures of an ex indie game developer

High and low risk

Overly high risk is no good. Knew that. Now I know that in a more concrete sense.

So this time around I devised a separation of a truly low risk version as well as a high risk instance. Put 10% in the high risk fund, and the remaining 90% in the other. Already after two weeks it's obvious that high risk is good for profit, provided you don't get rekt.

In this pace, assuming B doesn't get rekt in the meanwhile, how long time will it take to catch up with A?

Well, A is up by 1.42937113362935% and B 3.34461425929646% in 12.958499016203703 days. That means A has an average gain of 0.1095828631407% per day, while B's growth is 0.25420215990337% a day.

\[\left\{ \begin{array}{} \text{d = number of days elapsed}\\ a_0 = 9b_0 \\ a = a_0 \cdot 1.001095828631407^d \\ b = b_0 \cdot 1.0025420215990337^d \end{array} \right.\]

And we solve this equation:

\[9b_0 \cdot 1.001095828631407^d = b_0 \cdot 1.0025420215990337^d \\ \text{ } \\ d = \frac{\ln{9}}{\ln{1.0025420215990337} -\ln{1.001095828631407}}\]

which gets us somewhere in the vicinity of 1522 days, or four years and two months. It will however be much, much faster than that, since maximum gain is reached in the extremes which happens once every month or so. The real number is probably closer to one year. And B will also get rekt a number of times, so it's important to transfer the proceeds into A on a regular basis. The question is just when.

REKT - but to liquidation this time

Yesterday all our funds were taken by some huge whales.

Our funds, mostly mine (but also friends and charity) went from 8 Bitcoins to zero in a few hours in my overly high risk fund.

If the Bitcoin spike had been 40% instead of 43% on the daily we would have made a huge profit, but this hasn't happened since 2011 so nobody anticipated it.

After the initial shock, I decided that losing 67000 USD was not enough. Since the robot had made 720% up until that point, there obviously was moneys to be made. Although I need to go about it in a slightly lower pace.

Looking at what went wrong revealed, as is the case in any sufficiently complex system, errors. Because according to my backtesting, I should have been in the free! I found two serious bugs. One in the robot itself, and another in the simulation. Both only visible under extreme situations like this one.

The bot bug had to do with replacing a taken order too quickly, so it doesn't match the simulation (over-buying). I've code in place to handle that scenario, but obviously not as effective as I would have wanted. Should be a simple fix. The other one was in the simulation, where I've tried to approximate BitMEX's liquidation formula with an oversimplified one parameter, one degree polygon (I've never really understood financial instruments).

I've noted both these bugs before, but didn't think they'd be crucial. Ouch.

BitMEX's cross margin liquidation formula
The calculator on the BitMEX page is incorrect according to some, but it's the best I've got. So I implemented it in Python, which took several hours.

This 100 line giant is nothing I can use in my backtesting for "all the minutes since 2017". I need to optimize it. But it's surprisingly non-linear to the input parameters wallet size, order quantity and price. For polynomial fitting I want to solve


Where x contains samples of wallet size, order quantity, price and a constant, and B the actual liquidation prices as calculated with the calculator above. A will contain the 1-degree coefficients when using this Numpy code:

p,q,r = df[['wallet','contracts','price']].T.values
A = np.column_stack([p, q, r, np.ones(len(p))])
B = df['liquidation-price'].values
(a,b,c,d),_,_,_ = np.linalg.lstsq(A, B, rcond=None)

Projecting on a price of 3000 USD and wallet of 1 Bitcoin and plotting both long and short liquidation prices along with our fit plane doesn't look too good:

Fitting a 2D polynomial to that surface proved more difficult than I had thought. In particular I don't want my poly to result in points below the curve (for longs), as that would yields false negatives. Too close to the entry price, and I can hardly take any trade. Hm. I'm going to have to spend some time on this. But then I'm ready to waste some more hard-earned cash. :-/

Crime IRL and future assumptions

In the last three months I've seen a gang beating up close (Afghan thugs), and so did my colleague Johan at another instance. There was an explosion in my girlfriend's neighborhood. Co-worker Johan also had an explosion followed by a car fire in his, even though he lives in an expensive and posh one.

My girlfriend works in a grocery store, which had a break-in last night. My friend Lars went to the movies for the first time in ten years, to watch a kids movie with his son and wife. A street gang of Somalis walked straight in behind the candy store counter and started filling their holes with popcorn and candy.

A few years back Matilda and her husband had their neighbor kicked to the ground, a shooting in their kindergarten at 9 pm, molotovs thrown into cars nearby and a double homicide a couple of hundred meters from home.

This is what I've seen and heard in my circle of friends, but of course this is just scratching the surface of the real problems, which run very deep.

I'm still flabbergasted that some people are surprised by the fact that in the latest polls the Sweden Democrats have passed the Social Democrats. The socialists, and especially the left-leaning media, got us into this mess to begin with. They are starting to come around, but it's too late. Hope there will be some reckoning, the ruining of a state does not deserve to go unpunished.

My awakening was late, a decade ago, but I didn't realize the magnitude of the problem until four years ago when I stopped watching Swedish public brainwash tv, and delved into the alternative media.

In the last year or so, my concerns for where the filter bubbles and extreme voices on both ends is about to push humanity has increased. But perhaps it's better to just assume it's for the best. Let the World shake to its core. Let all the peoples see the Vatican with their pants down. Reveal what havoc egalitarian socialists cause when they play pk with a state. And show everyone that nobody is going to die from from carbon dioxide emissions (quite the contrary). Perhaps that can get us on our feet, and enlighten humanity in that truth, sensibility and cooperation is the way forward.

I think I'll assume so. Not because it'll make me feel better, but because it is the right thing to do.


My monthly trading robot turnover is approximately $3.5M right now. Looks like volatility is on the rise, which is good for my gains. The profits have been flat last month. Which usually means something is going down real soon.

This time perhaps a month of increasing prices? Keep you posted as my turnover increases.

I've also added a second instance of my trading bot which takes a lot higher risk, but with higher rewards. The idea is that it will make some money even in slow times. It will however get utterly rekt in times of super-high volatility.

Notice that instance B holds a position that is 50% of the position held by instance A, even though it has 13 times less capital. With that kind of risk, gains could be huge, as could losses. :-P

What I'll do is regularly transfer moneys back from instance B to instance A, to ensure I don't loose too much in case of huge bull or bear hunts. Wish me luck!

How to optimize your backtesting

My recommendations for optimizing your margin trading bot's performance are:
  1. Optimize for Sharpe ratio (not for gains);
  2. Optimize your weak spots according to price history (not your strong gains).
The reasons are very simple. When optimizing your result for Sharpe ratio, you'll find steady gains. Steady wins over rush-pullback in the long run. The weak spots are what kill you in margin trading. Optimizing these ensure you don't get rekt.

The optimizing pseudo code goes something like this:
P = initial backtesting parameters
    parameters P1 = randomize or gradient from P
    funds_over_time = backtest using P1
    sharpes = split funds_over_time into N slices and calc sharpe
    if minimum sharpes > best_sharpes:
        best_sharpes = minimum sharpes
    goto main_loop
With this you can't possibly go wrong. And can that quantum trading idea you heard about - this is a gazillion times better!

Prepare for sharp crypto drop

Bitcoin volatility has only been this low once before. Prepare for a surreal BTC drop in the next few days.

I reduced my risk a bit (order sizes) - I have a hunch this could be mayhem. Probably going to make a good buck anyway. Perhaps the reversal is going to be quick this time, both since whales have been very quiet lately and fear is high.

Sweden crumbling

Today, media and government and parliament are talking about what to do about the exponential growth of crime. It is of course too little, too late. Executions are commonplace today, as are bombings, hand-grenade attacks and shootings. Police resources are too limited and the cartels have been allowed to grow uninhibited for too many decades.

Already criminals are put on hold to serve their sentences, and in the mean time they're allowed to roam free!

What needs to happen is an unprecedented and fierce attack on these gangs - on par with Indonesia, The Philippines and Brazil. That's never going to happen though.

The mass migration from earlier decades is a direct cause of this, as second generation immigrants primarily are the perps. And in more recent years the super mass migration has more of  an indirect, economic cause of the explosion of crime (if you discount rape), as it weighs down already overburdened institutions.

School results are dropping rapidly, but not at all among pupils with Swedish background.

The problem is here to stay. For decades. Perhaps a half-century or even more. What we can expect in the mean time:
  • brain-drain;
  • public health-care loosing it's world class quality with ever increasing queues;
  • school dropping further, from 5th in world ranking in 2003, to 38 and falling in 2012;
  • police totally stifled by overburdening;
  • justice system unsafe for witnesses and totally overburdened;
  • detention centers overflowing;
  • massively expanding mafias in the larger cities;
  • steep degradation of the Swedish welfare system;
  • elderly being cared for at home - meaning reduced equality and freedom;
  • increasing taxes to the point that normal swedes will try evade them as best they can;
  • poverty expanding among the elderly, the handicapped and the ill.
I knew it was going to be bad, but didn't really see a collapse coming. But it's coming alright. And this upcoming recession is something of an indication of how much.

On the upside, most of the idiots who used political correctness as a shield against the racism in all of this, has had to change stance. (Without admitting that they did, of course.) Even in Swedish public service radio - the most communist part of government we still have - are now talking about it. Only too little. Too late.

About the author

Mitt foto
Gothenburg, Sweden