Sunday, January 29, 2012

The Meaning Of Edge.

In my previous post I gave you the answer to the ultimate question of life, the universe and everything. No, not 42, but .046! This number represents the "edge" that a trader needs to achieve provided that she risks 2% of her account per trade and is willing to accept a 1% risk of ruin. But what does this edge mean?

I have been searching all over the web for this and there are some misleading perceptions out there over the meaning of edge. First of all, my use of the word is strictly with respect to the risk of ruin formula:
PR = ((1-Edge)/(1+Edge))^RiskUnits
In this usage, we see that Edge is a number between 1 and 0. This is because PR is a probability number that is constrained to be between 1 and 0 and values of Edge outside of that create illegal probabilities. Edge is an advantage that creates the expectation of making money so if your edge is negative you need to fade that strategy.

Consider the meaning of Edge=0. This produces a PR of 1, certainty, no matter how small you are trading because 1 raised to any power is still 1. It is clear that Edge=0 is an even-money result that over time will eventually produce ruination. If we are playing an even-money game such as betting on coin-flips then if we play long enough then we will eventually encounter a string bad luck (not necessarily in consecutive flips) that reduces our capital to the point where we have nothing left and have to stop playing.

Now consider this infinite coin-flip contest: we win 1.02 for a heads result and lose 1.00 for a tails result on a fair coin. We risk 1 to make 1.02 but our average win/loss ratio is 1. One should say that we have an edge of  1% because we now have the expectation of a 2 cent gain on 1/2 of the coin flips. 

Suppose that the house in this coin-flip game wants to even things up by substituting an unfair coin. They wish to avoid detection by altering the coin by the smallest amount necessary. They only need make it so the win/loss ratio is 1/1.02. This is achieved by weighting the heads side so that the probability of a tails is .505. Thus in 1000 flips of that coin you would expect to see 495 heads paying almost 505 (504.9, to be precise) while the house collects 505 dollars on the tails outcomes. Thus #Wins/#Losses = Risk/Reward in an even-money game.

Thus edge can be mathematically defined as the win-rate times the difference between the Win/Loss ratio and the Risk/Reward ratio or:
Edge =  #Wins/#Trades  * ((#Wins/#Losses) - (Risk/Reward))
I find this particularly useful for my trading because I decree the Risk/Reward ratio by use of fixed stop and limit orders (or defined-risk option spreads.) Tracking the number of wins and losses is a simple matter of data collection.

Of course, average return per dollar of risk would also qualify as edge for the above risk of ruin calculation, too. This is because over a large number of trades one would come to expect this average in the future.

In one popular trading strategy (for which I am endlessly spammed) a limit order takes profit at 1.5 times the amount risked by a stop order. Yet, it is claimed that this wins about as many times as it loses. So I surmise from the claim that the edge of such a strategy is .167  (=.5 * (1-2/3)). We can then find out how many riskUnits we need  in order keep our risk of ruin low:
.01 = (1-.167)/(1.167)^RiskUnits
Plugging that into WolframAlpha because I am too lazy to solve for RiskUnits, tells me that I would need at least 14 times the amount risked, not including margin, in order to be able to trade that system safely.

Saturday, January 28, 2012

What Edge Do You Need?

I have been spending a bit of time pondering the risk-of-ruin (or as I will call it Probability Of Ruin so as not to confuse acronyms with return-on-risk) equation:

PR is a number between 0 and 1, where 1 is a virtual certainty and 0 is never-gonna- happen. Given the proper inputs, PR tells you what the probability is of blowing-out your account. You want to shoot for a PR under .1 and more ideally around .01-.02. That is to say if your PR is getting above 10% you need to reduce your trading size and if it is below 1% you are not earning as much as you might and should consider increasing your trading size.

When I was an InvesTools student I was taught not to risk more than 2% of account value on a trade. So this means that my RiskUnits are 50. Arbitrarily using .01 for the probability for PR, this morning's exercise is to work out what sort of trading Edge I need to stay out of trouble. Although, it is not possible to solve the PR equation explicitly for Edge, my son has introduced me to a website called Wolfram Alpha that can do an heuristic calculation based on these inputs without much fuss. The result I obtain is .046 or about 5%. 

Check it out!

So what does Edge mean?


Thursday, January 12, 2012

ThinkScript Included: Display Duration Of Range Bars With sdi_barmin

I've been experimenting with the new TOS range bars. With the slow grind to the upside today I found myself expending more neuronal energy calculating how much time a given range bar took to complete than I cared to. So this was the inspiration for a new companion study for range bars: sdi_barmin

SPY with Range Bars and sdi_barmin.

The lower study shows the duration in minutes of each completed range bar. Unfortunately it is not possible to show time accumulating in the forming bar with the current ThinkScript facilities (there is no access to the now-time from ThinkScript.)

Here's the ThinkScript:

# sdi_barmin
#hint: Plots the number of minutes a range bar took to complete Revision 1.0
# author: allen everhart
# date: 1/12/2012
# Copyleft! This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.

declare lower;
def dif = secondsFromTime(0)[-1] - secondsFromTime(0) ;
def duration =
  if dif >= 0 then dif/60 else (dif+(24*3600))/60
plot dur =  if !isnaN(close[-1]) then duration else double.NaN;