Trial and Epic Fail

Ventures of an indie game developer

Feasibility of if statements and mechanized friends

Since one and a half months my latest robot has only made 4 purchases. Of those, 75% were a catastrophe:

The jittery stuff is the actual stock movement, the straight drop ending each ownership period is the difference between asking and bidding price. On that good day, the robot bought a x12 Danish bull contract on silver, which gained 3.8% in 5 hours and 15 minutes. Discounting the 3.2% price difference, there is only 0.8% left. I checked the autocorrelation of that instrument compared to a few others where my deals haven't gone too well and noticed an interesting thing:

It's not surprising that silver prices are fairly stable, but it's curious that this is where my soft-coded if statements happened to make a worth-while deal.

From very few datapoints I guess that:

  1. The volatile price gap between buy and sell is making leverage instruments hazardous.
  2. The big price gap makes it near impossible to make a profit by owning an instrument a few hours.
  3. Stable instruments might work better.
So what instruments are stable and have lower price gap? Well stock is and does. D'oh! Back to square one.

I've decided to give machine learning a try. Using backpropagation means not knowing what I'm doing, but I've come to the conclusion that only pattern matching can give a good profit, if I keep using soft-coded if statements I'm only going to manage a slight profit at best. The machines are our friends.

Recluctant trader

My robot has refused to make any bets so far, so no trade has taken place since the re-write. I don't even know if it works in practice. For tomorrow (Monday) morning, I'll switch to a more risk-taking algorithm, which should trade more frequent (and at higher risk). Before going all in I'd like to see it work. So far I've lost 200 Euros (not counting the time I've spent) to prototyping. As soon as I've pulled through a whole cycle of trading, and done the due analysis, I should hopefully be able to inject around 1000 Euros and be scared shitless.

Rewrite ready for launch

My guesstimate of the trading bot rewrite was off by 1,5 months - in the right direction! So now I have a first version running, it's tested and fairly bug-tree. I won't know how it handles actual trading until tomorrow morning though, but much of the code is copy-paste so it should be close to ok.

Well I must say that was a nice surprise. The main reason for it being so quick was that I quickly could find a sensible algorithm, which seems to make a terrific profit on 3 months worth of stock history. There also was no wiggle-room from a grand local maxima I found, which made tweaking futile. Only two nights of tweaking and 2.5 kfloc including a lot of copy-paste in the other nine. Splendid!

The old code-name was Hasselhof. The new one is Zeno. Stoic founder instead of free diva.

I can only think of two things which could go wrong now:
1.The algorithm coincidentally worked for three months of data, but won't make much profit in the future.
2.My trading bot is traced by the bank, disallowed and my account is blocked. From what I've seen of their APIs, they aren't exactly on top of shit, and I have a hard time believing they could and would do that.
3.The username+password API is deprecated and replaced with manual requirement and/or recaptcha.

None of the above seems very likely, so this may be the start of making my wallet great again. And freeing up some time for book writing and LENR research! :)

If this goes down beautifully, I'll take some well-earned "vacation" in the evening time for some days. I haven't had many such days in the last decade. Ahhh, the blissful dreams of not being under the yoke of "have to" but instead "want to!"

Python and performance absence

Performance will always be the most important feature. While Python is performant in terms of development time, it has always caused me headaches when trying to cram out the juice in a real project. This, of course, will always eventually happen in any real scenario.

I've tried numpy, and sure it's great for certain vector algebra and time-to-market, but for getting high performance in irregular traversing of millions of datapoints... not so much. I know there's been plenty written in Python, Instagram back-end being the most notable, and I agree Python is an excellent scripting tool, but not when doing something real. (By real I don't mean delivering tons of crap content in social media, I mean search, map-reduce, crunch, calculate, compute.)

Go, however, has made an impressive journey to version 1.8. Performance is on par with Java (which also have made some small strides the last decade), but without the baggage of a shitty past. It's still only half the speed of C++ for optimized, parallel number crunching, but already I think it's where I had hoped D would be years ago. And the advantage of having fast, simple, portable and cross-platform builds without any configuration what so ever, along with a fairly lean syntax and a good standard library, as well as easy integration with C/C++ surely outweighs the cons. Already I think it's killed whatever was left of rust Rust - the syntax and immaturity speaks itself - as Rust is only 50% faster than Go 1.8.

So right now I'm banging my head wishing I could write my one-liner loop in Go instead of Python.

        while ti < l and perf[ti][0] < t:
            ti += 1


Scrapping my approach

I realized that half of my trading bot is worthless. It's not a huge surprise, as I went in to this with a brute force, try anything simple approach. Here's approximately how I've spent my dev time:

So half of the code is shit. It may or may not make a profit, it matters not.

Initially I just waved off the technical analysis concept; as usual for me I wanted to try from the ground up first. Now I have. That didn't work, but I found that technical analysis definitely will. From hereon have four options:
  1. Rewrite the core analysis and time-of-day trade bits.
  2. Same as 1, but also use numpy and pandas for the data processing, resampling, etc.
  3. Total rewrite, with a pinch of copy-paste.
  4. Total write and change of technology, using neural nets for the analysis.
I've spent six months on it, but the question now is not if I've wasted X time, but how I want to organize it to support my Y time left in life. The choice can be only one. Three, I mean.

3. Total rewrite

I have no doubt it can be done extremely well with a neural net, but I'm not knowledgeable enough and the learning curve is steep, plus I'm slightly biased against it for debuggability reasons.

It will take me a month to get a prototype running, which means two calendar months. But then only a couple of days to bug fix, tweak and put in production. I'm absolutely confident this will work, and the yield will be great again. Absolutely terrific! A yield like the world has never seen before. Amazing.

Delta price

The ask/bid delta may be one of my biggest problems. Here's an image of what I mean:
Even though this imaginary stock's trend (of course both asking price and bid) are going up, the discrepancy is going to cause a loss in this scenario. Between this and the commission, my downfall might be imminent. But I doubt it. I still think I'm going to find some way to earn money off of this. And the main reason I'm confident is that the stock market is not random. Things happen for a reason and whenever human psychology is involved, there's a certain inertia which can be harvested. Eventually I'll be a farmer and not the crops. ;)

NRG and Nazis

The energy revolution is coming along nicely. Two months ago the E-Cat/Rossi litigation was won, with both patent and license returned to inventor Andrea Rossi. This is by no means the only hint that things are moving in the right direction. There have been independent cold fusion/LENR replication of all sorts. Martin Fleischmann Memorial Project have three different groups independently seeing neutron emissions. A US Department of Defence document became unclassified, supporting Widom/Larsen LENR theory. NASA replicated and pondered LENR aircraft. MIT's NANOR device have showed a COP of 12, and in 2013 increased it to COP 80. Brillouin Energy claims to be close to a technology breakthrough. CNN interviewed Brilliant Light Power on their "SunCell" LENR product. CBS 60 minutes published Cold Fusion is Hot Again. In 2017 US Congress requested a briefing from Secretary of Defence on the topic. And so on, and so forth. (Anyone who likes can of course sit through hours of Myron Evans boringly reading his essays Unified Field Theory, but not sure if that helps in understanding LENR, and perhaps even less so in unifying quantum and relativity theory.)

Andrea Rossi and his invention, the E-Cat, still seems to be on top, with the 1MW industrial-grade solution verified, all the while claiming that he's close to finalizing a consumer-grade product, E-Cat QX.

Some of the most interesting things for me, as an intrigued amateur, are some of the super-simple LENR experiments that have been published: Cold Fusion in the Pot, Parkhomov's E-cat replication, How to Make Cold Fusion, Free From Fuel. You can even order your own LENR start-kit for 300 USD.

I recently took a Tesla P100D test drive. The performance of a proper electric motor is no childs-play although it feels like sitting in a very high-performing roller-coaster. Here are some reactions to the less performant P85D:

Goes without saying, I was sold after my first Ludicrous Launch. The only thing remaining is that manufacturing the Tesla batteries are very bad for the environment. Hopefully LENR can remedy this in a few years.

One more thing is of the essence here (which often is claimed to be but rarely is). Terrorism. Put infinite energy in the hands of a terrorist and everything dies. I have no good solutions to that one. For me, as an amateur student of parapsychology, an interesting side-note is that the head of Waffen-SS in Nazi Germany came up with the crazy holocaust idea partially as a means of trying to avoid civilizations imploading. One-ness by eliminating others. Let's make sure history doesn't repeat itself. But let's also enjoy the ride. Now is a good time to be alive!

About the author

Mitt foto
Gothenburg, Sweden