Categories: null, art, books, fashion, movies, music, television, ben tries to, ben tries to beat Livermore, ben tries to paint, fetishizing intellect and beauty, food, coffee, crepes, pizza, kittens, math, on writing, pictures, programming is for people with beards, ben builds a cluster, puppies, rant, the homeless don't eat bread, writing

posted by ben on 09.08.01 at 07:58, null, books, Leave a comment Permalink

Like most things in the story the natural sciences can tell about the world, it’s all so beautiful, so gracefully simple, yet so rewardingly complex, so neatly connected – not to mention true – that I can’t even begin to imagine why anyone would ever want to believe some New Age ‘alternative’ nonsense instead. I would go so far as to say that even if we are all under the control of a benevolent God, and the whole of reality turns out to be down to some flaky spiritual ‘energy’ that only alternative therapists can truly harness, that’s still neither so interesting nor so graceful as the most basic stuff I was taught at school about how plants work.

-Ben Goldacre, Bad Science, Pg. 117

posted by ben on 09.08.01 at 07:57, null, books, Leave a comment Permalink

...imagine a puddle waking up one morning and thinking, ‘This is an interesting world I find myself in’an interesting hole I find myself in’fits me rather neatly, doesn’t it? In fact it fits me staggeringly well, must have been made to have me in it!’ This is such a powerful idea that as the sun rises in the sky and the air heats up and as, gradually, the puddle gets smaller and smaller, it’s still frantically hanging on to the notion that everything’s going to be alright, because this world was meant to have him in it, was built to have him in it; so the moment he disappears catches him rather by surprise. I think this may be something we need to be on the watch out for.

Three Fundamentals for a VC

posted by ben on 09.07.08 at 13:36, null, null, Leave a comment Permalink

(1) What are you doing?

(2) How can I help?

(3) What do I gain?

Virgin is inept.

posted by ben on 09.06.11 at 11:01, null, null, London, Leave a comment Permalink

Virgin media disconnected my brand new fiber line for non-payment of my bill after 1 day of connectivity. My bill wasn't paid because Virgin put a "credit limit" on the account. This limit prevented them from taking the connection fee out of my bank account, despite the bank account itself having plenty of money. Now my access is going to be down for a day.

I pay for the downtime as well, since in their view this is my fault. You know, for being a foreigner.

The happy path worked!

posted by ben on 09.05.04 at 16:04, null, null, ben tries to beat Livermore, Leave a comment Permalink

Classification done at 2009-05-04T00:00:11.602436
The best symbol is HBC.
Scheduling trades for today.
Opening positions at 2009-05-04T09:29:30.100081
I am going to trade today.
action=buy~quantity=772~symbol=HBC~ordtype=Limit~price=36.65~expire=day~accountid=xxx
Waiting for order to fill...
772.0 shares filled at 36.65
action=sell~quantity=772.0~symbol=HBC~ordtype=Limit~price=37.38~expire=day~accountid=xxx
Closing positions at 2009-05-04T15:57:00.100089
We won today! All closed out.

Lack of Privacy

posted by ben on 09.04.17 at 14:50, null, boulder, Leave a comment Permalink

The arrow's pointing to Gene.

Or, see the original here. Graham pointed this out.

The guy in the foreground with his head blurred out, wearing the white linen, is always reading A Course in Miracles and that sort of thing. I can't remember his name.

Aiden Byrne Podcasts

posted by ben on 09.03.22 at 16:15, null, food, London, Leave a comment Permalink

here and here

Council Tax

posted by ben on 09.03.22 at 15:53, null, London, Leave a comment Permalink

Here's where it goes. I'd assumed a lot more went to schools... not really thrilled about paying for the projects.

In Soviet England...

posted by ben on 09.03.22 at 15:51, null, London, Leave a comment Permalink

I tried to buy hangers at Argos today. You poke through a phone book sized catalog, pick numbers of items you want and then a clerk gets them for you. The conversation went something like this:

Ben: I don't see any hangers in your catalog, but you sell them right?

Clerk: Yes. Let's see... page 143. But, they usually sell out as soon as we get them in. I'll check if we have any. No. Let me see if any of the surrounding stores have any... No.

Ben: When will you get more in?

Clerk: I don't know.

Ben: Is there anywhere else I can get hangers around here?

Clerk: I don't know.

Ben: Thanks anyway.

Demand > Supply -> Order more hangers. Right? What's next, toilet paper shortages?

Big Brother on Brick Lane

posted by ben on 09.03.22 at 09:27, null, pictures, London, Leave a comment Permalink

Trade Lifecycle

posted by ben on 09.03.22 at 07:13, null, null, ben tries to beat Livermore, Leave a comment Permalink

I'm a fair way along writing the trade engine for arbit (what I call my statistical arbitrage program that's something like 2.5 years in the making (the name of which still makes me think of these)). I've started to realize that I'm writing a finite state machine, one which looks alarmingly like the one in TIBCO BusinessEvents (BE).

So, out of curiosity, I built up the state model using BE. I'm now thinking BE makes lot of sense for trade life cycle. I've pitched the idea before, but I think trying to write a trade engine from scratch has made it really obvious how valuable this is.

Now I just have to figure out how to do this in Python. I'm thinking for each trading day I create a new object and then progress it through with a bunch of flags. Yay for non scalable approaches!

I'm also starting to wonder if my one language to rule them all approach is a good idea. I use Python for most everything, with occasional calls into C for a couple libraries I need that don't exist in Python. Python interoperates natively with C, so this isn't a big deal. That said, it'd be nice to be able to call something mathy (Matlab, R, S+, even Mathematica), and there are about a billion things in Java that'd be nice to have.

I don't want to use Jython because I'm not convinced it has a future. The integration to the Ameritrade API is already as much code as my entire arbitrage program. Likewise, the cluster code is easily 3x the size of the arbitrage code. Then there's the market data scraper which is probably 5x the arbitrage code. Integration is hard... That said, I really like the idea of keeping it all in Python so this problem doesn't get worse.

I finally built a closet.

posted by ben on 09.03.21 at 12:19, null, London, 2 comments Permalink
Comment from: graham [Member] · http://nonplatonic.com/graham.php
So how did you end up building it? I'm a little disappointed that it's not 15 feet long.
Permalink 04/20/09 @ 11:15
Comment from: ben [Member] · http://ben.nonplatonic.com
I build everything. I'm awesome. Yay shit drills and 2x4s!
Permalink 04/20/09 @ 15:25

posted by ben on 09.03.20 at 18:30, null, null, books, Leave a comment Permalink

I've read the book. I love it. If there is some hint of how to find you in it, I've missed it. As GK Ashe probably isn't available, let's go get dinner some other ridiculous place!

?

posted by ben on 09.03.19 at 14:30, null, null, books, Leave a comment Permalink

The Road Home by Rose Tremain is to Strawberry Fields by Marina Lewycka
as
House of Meetings by Martin Amis is to Russian Debutante's Handbook by Gary Shteyngart

posted by ben on 09.03.18 at 13:53, null, null, Leave a comment Permalink
I wish I'd had the self control to not argue with PETA in the comments... to not immortalize myself with an improperly conjugated verb. Sigh.
posted by ben on 09.03.15 at 15:26, null, null, Leave a comment Permalink

In related flawed reasoning, there are trillions in outstanding lottery tickets. Every time a person buys a lottery ticket, the state is potentially obligated to pay millions of dollars. It's only a matter of time before everyone wins the lottery at once and the state is required to pay out millions to each of millions of lottery players.

End the lottery! It may seem like a boon to public resources now, but soon the bubble will burst and this house of cards will come tumbling down!

--------------------

"2. Derivatives are unregulated, not traded on any public exchange, without universal standards, dealt with by private agreement, not transparent, have no open bid/ask market, are unguaranteed, have no central clearing house, and are just not really tangible."

Um, no. Anyone heard of CBOE?

Photo from Chamonix...

posted by ben on 09.03.08 at 08:01, null, pictures, places, Leave a comment Permalink

Seems strangely familiar.

python: xml to dict, bow to my recursive genius

import xml.dom.minidom

def xmltodict(xmlstring):
	doc = xml.dom.minidom.parseString(xmlstring)
	return elementtodict(doc.documentElement)

def elementtodict(parent):
	child = parent.firstChild
	if (child.nodeType == xml.dom.minidom.Node.TEXT_NODE):
		return child.nodeValue

	d={}
	while child is not None:
		if (child.nodeType == xml.dom.minidom.Node.ELEMENT_NODE):
			try:
				d[child.tagName]
			except KeyError:
				d[child.tagName]=[]
			d[child.tagName].append(elementtodict(child))
		child = child.nextSibling
	return d

Updated: Fixed a bug that didn't like null nodes and another about whitespace, though I stole some code from an O'Reilly book for that.

import xml.dom.minidom

def xmltodict(xmlstring):
	doc = xml.dom.minidom.parseString(xmlstring)
	remove_whilespace_nodes(doc.documentElement)
	return elementtodict(doc.documentElement)

def elementtodict(parent):
	child = parent.firstChild
	if (not child):
		return None
	elif (child.nodeType == xml.dom.minidom.Node.TEXT_NODE):
		return child.nodeValue
	
	d={}
	while child is not None:
		if (child.nodeType == xml.dom.minidom.Node.ELEMENT_NODE):
			try:
				d[child.tagName]
			except KeyError:
				d[child.tagName]=[]
			d[child.tagName].append(elementtodict(child))
		child = child.nextSibling
	return d

def remove_whilespace_nodes(node, unlink=True):
	remove_list = []
	for child in node.childNodes:
		if child.nodeType == xml.dom.Node.TEXT_NODE and not child.data.strip():
			remove_list.append(child)
		elif child.hasChildNodes():
			remove_whilespace_nodes(child, unlink)
	for node in remove_list:
		node.parentNode.removeChild(node)
		if unlink:
			node.unlink()

Update 2: Someone already did this in the 2nd edition of the Python Cookbook. There's another one here too: http://code.activestate.com/recipes/116539/. So much for there only being one way to do something in Python...

Comment from: qkiss [Visitor]
Hi,

Thanks for the simple solution, just what I was looking for.

I changed it a bit and removed the remove_whilespace_nodes function. Hope it will also help someone.

from xml.dom.minidom import parse, Node

def xmltodict(filename):
doc = parse(filename)
return elementtodict(doc.documentElement)

def elementtodict(parent):
child = parent.firstChild
if not child:
return None
while child.nodeType == Node.TEXT_NODE and not child.data.strip():
child = child.nextSibling
if child.nodeType == Node.TEXT_NODE:
return child.nodeValue

d={}
while child is not None:
if (child.nodeType == Node.ELEMENT_NODE):
try:
d[child.tagName]
except KeyError:
d[child.tagName]=[]
d[child.tagName].append(elementtodict(child))
if len(d[child.tagName]) == 1:
d[child.tagName] = d[child.tagName][0]
child = child.nextSibling
return d

qkiss
Permalink 01/11/10 @ 12:58
Comment from: qkiss [Visitor]
Sorry for the code... I hope this one will be better.


from xml.dom.minidom import parse, Node

def xmltodict(filename):
doc = parse(filename)
return elementtodict(doc.documentElement)

def elementtodict(parent):
child = parent.firstChild
if not child:
return None
while child.nodeType == Node.TEXT_NODE and not child.data.strip():
child = child.nextSibling
if child.nodeType == Node.TEXT_NODE:
return child.nodeValue

d={}
while child is not None:
if (child.nodeType == Node.ELEMENT_NODE):
try:
d[child.tagName]
except KeyError:
d[child.tagName]=[]
d[child.tagName].append(elementtodict(child))
if len(d[child.tagName]) == 1:
d[child.tagName] = d[child.tagName][0]
child = child.nextSibling
return d
Permalink 01/11/10 @ 12:59
Comment from: Nan [Visitor]
I adapted elementtodict to use numeric values instead of strings for actual numeric values, as well as base types instead of lists when there is only one element with a given name:

def elementtodict(parent):
child = parent.firstChild
if (not child):
return None
elif (child.nodeType == xml.dom.minidom.Node.TEXT_NODE):
val = child.nodeValue
try:
if '.' in val:
val = float(val)
else:
val = int(val)
except ValueError:
pass
return val

d={}
while child is not None:
if (child.nodeType == xml.dom.minidom.Node.ELEMENT_NODE):
try:
d[child.tagName]
except KeyError:
d[child.tagName]=[]
d[child.tagName].append(elementtodict(child))
child = child.nextSibling
for key, val in d.items():
if type(val) is list and len(val) == 1:
d[key] = val[0]
return d
Permalink 08/12/10 @ 15:54

Crumpets Royale

posted by ben on 09.02.01 at 16:33, null, null, food, pictures, Leave a comment Permalink

Program Trading

posted by ben on 09.02.01 at 14:29, null, null, ben tries to beat Livermore, 1 comment Permalink

It turns out there are more reasonable options between professional brokers and scraping yahoo, google, and Ameritrade pages:

http://www.interactivebrokers.com/ibg/main.php
http://www.tdameritrade.com/tradingtools/partnertools/api_dev.html

Comment from: JOHNNY JOHNNY [Visitor]
used to use IB.. they are not bad
Permalink 06/12/09 @ 04:28