Posts
Adam DrakeThe Efficient Market Hypothesis (EMH) is both important and often misunderstood. For our purposes, the term efficient is related to informational efficiency, or how quickly information affects prices. In a way, the level of informational efficiency in a market tells you what level of randomness to expect and consequently if it is possible to outperform the market. In its simplest form, the EMH states that market prices reflect decisions made by participants who have acted rationally based on information they possess. It is not required that all participants act rationally at all times, but only that at any given time most participants are acting rationally given the information they possess. In order to clarify the impact of varying levels of information, the EMH has been split into sub-types depending on what kind of information is incorporated into the asset price. There are currently three forms of the EMH: the Weak EMH, the Semi-strong EMH, and the Strong EMH.
...
read more Adam DrakeDon’t be fooled, this isn’t market commentary. This is commentary about market commentary. Many times when we come across market commentary, we see horrible examples of confusing correlation and causation, the logical fallacy of post hoc ergo propter hoc wherein event B is said to be caused by event A simply because event B followed A. This fallacy can be found in the vast majority of market commentary, and is especially obvious on days where the market didn’t move appreciably, yet there is someone claiming to know why the move occurred. Today is a good example. The Dow Jones Industrial Average gained 75 points today, or 0.6%, which is well within normal market fluctuations. In other words, nothing happened in the market today. However, that did not stop anyone from trying to find an explanation for this nothingness. Over on The Street they attributed the 0.6% gain to a narrowing trade deficit in the last month, amongst other factors.
...
read more Adam DrakeI’ve been thinking recently about fractal geometry with applications to finance, and I talked to an acquaintance who informed me that he watches the “fractals” on his charts when trading. This prompted me to do some research into how technical analysts use “fractals” and see what kind of information such an indicator provides. There are many issues with using fractal behavior as a technical indicator, namely that the way the term is used in technical analysis doesn’t sound like it has anything to do with fractals at all. According to Investopedia, in technical analysis a fractal is defined as
...
read more Adam DrakeCompared to the Ruby version, computing this in R is much easier due to the built-in stochastic differential equation simulator. Assuming you have R installed, make sure you also install the sde package. Here is all the initial work that cleans up everything from your workspace, sets the initial value of the process, the end-point, how granular you want the simulation to be, and how many trajectories you want.
rm(list = ls(all = TRUE)) x0 = 50 end_point = 200 discretization_factor = 100 total_steps = end_point * discretization_factor #Use the same seed for multiple trajectories if (number_trajectories > 1) number_trajectories = 1 set.seed(rnorm(1)) Here we have a 0 drift parameter and a standard deviation of 1, followed by the simulation and plot of the process.
...
read more Adam DrakeThis code is adapted from some Matlab code I found that simulates the OU process exactly. I had to code up a quick Gaussian random number generator in Ruby because I didn’t find a method to handle that. As noted in the comments I used the Box-Muller Transformation but if lots of random numbers are required the Ziggurat Algorithm could be used instead.
#!/usr/bin/env ruby include Math require 'rubygems' require 'gnuplot' #Gaussian random number generator using the Box-Muller Transformation #If this is too slow it can be replaced with the Ziggurat Algorithm def randn z1 = rand z2 = rand rand_normal = sqrt(-2.0*log(z1))*sin(2.0*PI*z2) return rand_normal.to_f end #Enter the parameters for the simulation steps = 400 #start_time = 0 #simulation start time #end_time = 400 #simuation end time dt = 0.01 #time step tau = 0.1 #relaxation time c = 1.0 #diffusion constant x0 = 0.0 x = [] #initial value for stochastic variable x mu = 0.0 #mean of stochatic process x y0 = 0.0 y = [] #initial value for integral x start_dist = -2.0 #start of OU pdf end_dist = 2.0 #end of OU pdf time = (0..steps).step(dt) i = 0 x[0] = x0 y[0] = y0 time.each do |t| i = i + 1 r1 = randn r2 = randn puts x[i-1] x[i] = x[i-1] * exp(-dt/tau) + sqrt((c*tau*0.5)*(1-(exp(-dt/tau))**2))*r1 y[i] = y[i-1] + x[i-1]*tau*(1-exp(-dt/tau))+sqrt((c*tau**3*(dt/tau-2* \ (1-exp(-dt/tau))+0.5*(1-exp(-2*dt/tau))))-((0.5*c*tau**2)* \ (1-exp(-dt/tau))**2)**2/((c*tau/2)*(1-exp(-2*dt/tau))))*r2+ \ ((0.5*c*tau**2)*(1-exp(-dt/tau))**2)/(sqrt((c*tau/2)* \ (1-(exp(-dt/tau))**2)))*r1 end k = 0 j = (start_dist..end_dist).step(dt) p = [] j.each do |l| k = k + 1 p[k] = sqrt((1/tau)/(PI*c))*exp(-(1/tau)*(l-mu)**2/(c)) end That’s it. Not too difficult to compute with Ruby, but I also did another version in R. I’ll post about that shortly.
...
read more