• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 6:22am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 6:22am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Optimized Risk vs Reward Equation 335 replies

Loss Less Optimized Strategy 63 replies

Optimized Parameters in Metatrader Testing? 3 replies

"Optimized Parameter" feature in EA? 0 replies

Strategy with Optimized parameter 1 reply

  • Trading Discussion
  • /
  • Reply to Thread
  • Subscribe
  • 588
Attachments: Optimized Trend Trading
Exit Attachments
Tags: Optimized Trend Trading
Cancel

Optimized Trend Trading

  • Last Post
  •  
  • 1 2021Page 222324 63
  • 1 21Page 2223 63
  •  
  • Post #421
  • Quote
  • Edited 8:59pm Feb 19, 2009 8:49pm | Edited 8:59pm
  •  BlackMage
  • | Joined May 2007 | Status: Financial Hacker | 203 Posts
Quoting BarHopper
Disliked
Have you used any of these Matlab integration tools yourself?
Ignored
No, I use a platform which was programmed completely from scratch in C#. I cant really comment on using Matlab in general since I, like MisterH, am more into R and haven't used Matlab for a long time.

I know Matlab is supposed to be widely used on "The Street" for modelling, but I don't think it is widely used as a trading platform partly because of the issues you mentioned in your post. However I still think that it is an interesting alternative to MetaTrader (anything but that s...) if you are an experienced Matlab user.
 
 
  • Post #422
  • Quote
  • Edited Feb 25, 2009 8:07am Feb 24, 2009 9:23am | Edited Feb 25, 2009 8:07am
  •  MisterH
  • | Joined Mar 2008 | Status: Member | 32 Posts
If anyone wants to cooperate with me to do a small project to find the optimal timeframe/sampling rate with Taken's theorem in R: pls email me.
It's more work than simply plotting the average mutual information per sample size in seconds I think. If you are familiar with R (project),

send me an email, 2 people know more than 1!

ps: I'd be happy to report back some results to the thread
 
 
  • Post #423
  • Quote
  • Edited 12:55pm Feb 26, 2009 12:43pm | Edited 12:55pm
  •  adamant
  • | Joined Jan 2009 | Status: Member | 13 Posts
Moving back to FIR filters...

I have taken a look at the code for Igorad's popular NonLagMA.

http://www.forex-tsd.com/indicators-...ing-tools.html

Igorad
"Some time ago I found that coefficent in the formula of FATL and SATL (so named Digital Filters ) are described by the formula of a fading sinusoid.
Then I've developed formula for so named NonLagging Moving Average on the basis of Linear Weighted MA."

I analysed the coefficients. As you can see, he's not kidding about the fading sine wave. I haven't seen a set of FIR coefficients like this before (but then I've been designing FIR filters for all of a few days).

Obviously the filter is heavily biased towards recent values so that it can react quickly, but the long slow sine tail presumably allows it to include longer term data without too much lag (because of the negative coefficients).

His NonLagMA behaves pretty well to my eyes. Is anyone with a background in filter design familiar with this impulse pattern, and do you think he's onto something here?

Can it be improved upon?
Attached Images
Attached File(s)
File Type: txt nlcoeffs.txt   2 KB | 513 downloads
 
 
  • Post #424
  • Quote
  • Feb 27, 2009 5:59am Feb 27, 2009 5:59am
  •  Codebreaker
  • Joined Jan 2008 | Status: MathMaven | 193 Posts
Quoting adamant
Disliked
Moving back to FIR filters...

I have taken a look at the code for Igorad's popular NonLagMA.

http://www.forex-tsd.com/indicators-...ing-tools.html

Igorad
"Some time ago I found that coefficent in the formula of FATL and SATL (so named Digital Filters ) are described by the formula of a fading sinusoid.
Then I've developed formula for so named NonLagging Moving Average on the basis of Linear Weighted MA."

I analysed the coefficients. As you can see, he's not kidding about the fading sine wave. I haven't...
Ignored
Hi adamant,

Thanks for this contribution. Sadly, there is nothing new here. The Windowed Sinc Filter was first described by John von Neumann in the 1930's and came out of early radar development.

The first point to note is that the coefficient sets are NOT "fading sine waves""! They are sinc functions where sinc(x) = sin(x) / x.

There is nothing magic here - the derivation is glaringly obvious if you think about it. Ideally, we want a "brick wall" filter that passes certain frequencies. This can be low-pass, high-pass or band-pass. Whatever we want, the passband in the frequency domain is a square window rising from zero to unity at f1 and falling back to zero at f2.

Therefore, the impulse response (ie the time domain coefficients) is nothing more than the Fourier transform of a square window which is just our old friend the sinc function!

But while the square window is finite in length in the frequency domain, the sinc function is infinitely long in the time domain. So what do we do? Yup - you guessed it!! We truncate it with a square window, whose FT is a sinc function and then..........

So we just reflect back and forth between domains to optimise the (finite) coefficient set that defines the filter. This is just what Remez did in his eponymous algorithm. All my low-lag designs are windowed sinc filters of one form of another.

BTW, the filter is provably optimal in terms of cut-off. It cannot be improved on. If you look at the source code of Igorad's NonLagMA he tweaks the shape of the curve to slightly improve the phase response, but nothing worth writing home to Mother about.

CB
 
 
  • Post #425
  • Quote
  • Feb 27, 2009 9:26am Feb 27, 2009 9:26am
  •  adamant
  • | Joined Jan 2009 | Status: Member | 13 Posts
Fascinating as ever CB! Thanks for your reply. That makes very good sense to me.

I am still learning so much from this thread, most of all what it is I need but don't yet know!
 
 
  • Post #426
  • Quote
  • Feb 28, 2009 10:36am Feb 28, 2009 10:36am
  •  Codebreaker
  • Joined Jan 2008 | Status: MathMaven | 193 Posts
Guys

As you know, I have been targetting 10% a month as my return on capital employed. I have achieved this for 6 months now and I posted my January equity curve a while ago.

However, my own curiosity, together with enquiries from my "inner circle" of folk with whom I work very closely, prompted the question, "Could we do better and say achieve 20% a month?".

Without seriously intending to achieve this (as it is rather ambitious!) I adjusted the robots' parameters to lift the equity curve towards a target of 20% return. I opened a new £10K account on 3 Feb and the equity curve to yesterday morning (24 calendar days) is attached.

If you compare this with the January curve, you will see immediately that it is not almost ruler-straight as the Jan curve was. We now have 3 trades that break the linearity. One trade just before epoch 60 give a larger then usual profit. A trade between epochs 67 and 70 gave a larger than usual loss, then another trade at the end gave a larger profit again.

However, if we ignore these 3 trades and put a ruler on the curve, it is pointing directly at 20%.

So the interesting result is, "Yes, 20% appears quite feasible".

BUT... at the expense of some smoothness of the equity curve due to the robot being forced into some rather riskier trades in order to meet the demanded target. Please note that my lot size is still the same as it ever was (0.1-0.3 lots).

CB
Attached Image (click to enlarge)
Click to Enlarge

Name: DetailedStatement4a.gif
Size: 5 KB
 
 
  • Post #427
  • Quote
  • Feb 28, 2009 4:29pm Feb 28, 2009 4:29pm
  •  purley
  • | Joined Feb 2009 | Status: Member | 79 Posts
İnteresting link Fractalisation of the MA:
http://fractalfinance.blogspot.com/search/label/FRAMA
http://codebase.mql4.com/5308
Attached Image (click to enlarge)
Click to Enlarge

Name: FRASMA.PNG
Size: 23 KB
 
 
  • Post #428
  • Quote
  • Mar 1, 2009 6:53am Mar 1, 2009 6:53am
  •  challenger78
  • | Joined Sep 2007 | Status: Member | 297 Posts
Quoting Codebreaker
Disliked
"Could we do better and say achieve 20% a month?".
Ignored
Hi CB,

first of all congratulations on the results. Your experiment with the modified parameters is interesting for sure, however, if it was me trading real money, I think I would use the previous model parameters that yield the smooth equity curve and just increase the lot size to hit the 20% profit target with less drawdown.

Keep it up, good luck.
 
 
  • Post #429
  • Quote
  • Mar 1, 2009 12:49pm Mar 1, 2009 12:49pm
  •  Codebreaker
  • Joined Jan 2008 | Status: MathMaven | 193 Posts
Quoting challenger78
Disliked
Hi CB,

first of all congratulations on the results. Your experiment with the modified parameters is interesting for sure, however, if it was me trading real money, I think I would use the previous model parameters that yield the smooth equity curve and just increase the lot size to hit the 20% profit target with less drawdown.

Keep it up, good luck.
Ignored

Hi Challenger

I am sure you are right. I don't like pushing any piece of "machinery" to its limits - it is generally a sure fire recipe for disaster sooner or later.

One of the holes in my knowledge is the whole MM thing. I just trade very small lots and hope I am safe! I don't want to open a topic on MM as it would pull this thread away from its intended purpose, but a number of good folk are PM-ing me and trying to get me up to speed in this and other areas.

I am sure there is more to long term success than just a good algorithm.

CB
 
 
  • Post #430
  • Quote
  • Mar 2, 2009 7:25am Mar 2, 2009 7:25am
  •  challenger78
  • | Joined Sep 2007 | Status: Member | 297 Posts
Quoting Codebreaker
Disliked
I am sure you are right. I don't like pushing any piece of "machinery" to its limits - it is generally a sure fire recipe for disaster sooner or later.
Ignored
Well I believe it's still good to try different parameters and see if you can improve the system without introducing MM into the mix, i.e. better returns without increasing the drawdown. The MM is just the cherry in the pie, and it's not that hard... usually the risk and reward are just proportional to the lot size, so once you have stable and satisfactory results from your system over a long period of time just increase lots until your hit a draw down limit/constraint. Of course there are more sophisticated forms of MM to try to squeeze the last bit out of the system, but as I said these are just the cherry in the pie, you don't really need them to be very successful, and you are right, these are not currently the topic of this thread.

All the best
 
 
  • Post #431
  • Quote
  • Mar 3, 2009 12:33am Mar 3, 2009 12:33am
  •  dizzyd
  • | Joined Oct 2008 | Status: Member | 7 Posts
CB, Barhopper..

I implemented the FNN idea for identifying the "best" timeframe to trade a given pair -- running it against the EURUSD on tick data from November 15-28 showed that 33 mins seemed to have the lowest percentage of FNN (38.33%), using a dimension of 10 and a threshold of 0.10 (yes, I made that up). Most of the literature suggests using a threshold of 10-50, but given that we are dealing with currencies at 4 decimal places, I figured it was pretty unlikely to see distances of that scale. Does that sound right/logical? If not, how do you choose the threshold?

Other pairs reflect similarly for the same timeframe -- USDJPY @ 33 mins w/ 39% FNN, GBPUSD @ 32 mins w/ 36% FNN. 30 minutes def seems to be a sweet spot at this date/time, assuming a.) my analysis is right b.) this technique actually works.

Of course, the next step is to see if there is any meaningful difference by running the ULLMA+Goertzel and seeing if there is any correlation between "best" timeframe and performance. From what I've read about FNN, I don't think this is really the way it's supposed to be used, but it sounds like an interesting idea.
 
 
  • Post #432
  • Quote
  • Mar 3, 2009 6:12am Mar 3, 2009 6:12am
  •  Codebreaker
  • Joined Jan 2008 | Status: MathMaven | 193 Posts
Guys

Attached my equity curve for 3 Feb 2009 to 3 March 2009. There is also around £40 in Floating P/L so the return is around 22% for the month.

CB
Attached Image (click to enlarge)
Click to Enlarge

Name: DetailedStatement5.gif
Size: 5 KB
 
 
  • Post #433
  • Quote
  • Mar 3, 2009 8:07pm Mar 3, 2009 8:07pm
  •  ngawang
  • | Joined Oct 2008 | Status: Member | 52 Posts
First of all, congratulations to CB on the great trading results. Hope this continues.

I've been a bit swamped & so haven't been able to test that last idea about filtering forwards through the data and then again backwards as a means of doing a very simple noise filtering job. It turns out this idea works extremely well. Attached are 5 images which represent cycle amplitudes from 2 to 30 days over a time series of the last roughly 300 trading days. Price series is S&P 500.

First Chart -- Raw Price Series
Second Chart -- Price Filtered with a well designed elliptic filter
Third Chart -- Price Filtered with an FIR filter
Fourth Chart -- Price Filtered with the HP Filter
Fifth Chart -- Price Filtered both forwards and backwards with EMA

Both the HP Filter and (for lack of a better term) non-causal EMA Filter do very good jobs filtering out extraneous noise from the raw data. The results for the EMA noise filtering idea are impressive. It's within striking distance of being as effective as the HP Filter and much easier to code so potentially very useful for folks working with Easy Language or other similar coding languages.

Take a look,
Ngawang
Attached Image(s) (click to enlarge)
Click to Enlarge

Name: MATLAB1.jpg
Size: 178 KB
Click to Enlarge

Name: MATLAB2.jpg
Size: 176 KB
Click to Enlarge

Name: MATLAB3.jpg
Size: 176 KB
Click to Enlarge

Name: MATLAB4.jpg
Size: 175 KB
Click to Enlarge

Name: MATLAB5.jpg
Size: 177 KB
 
 
  • Post #434
  • Quote
  • Mar 4, 2009 6:50pm Mar 4, 2009 6:50pm
  •  ngawang
  • | Joined Oct 2008 | Status: Member | 52 Posts
Hi Barhopper,

(and anyone who has thought about this problem)

You recently proved that the Goertzel and FFT algorithms are identical. I can replicate your result if I use the following Matlab code, where x is a column vector containing a time series we wish to examine.

[N ncols] = size(x);
f = ((0:2:N)') ./ N ./ 2;
[goertzelAmp goertzelPhase] = goertzel(x, f);
fftAmp = sqrt(real(fft(x)).^2 + imag(fft(x)).^2);
epsilon = fftAmp(1:N/2) - goertzelAmp;

epsilon is very small -- just as you said.

The first half of the fft amplitude is equivalent to the amplitude computed by the Goertzel algorithm. But I have to define f for the Goertzel algorithm by skipping every other possible frequency.

It seems like we could compute the Goertzel algorithm as follows

f = ((0:1:N)') ./ N ./ 2;
[goertzelAmp goertzelPhase] = goertzel(x, f);

and get double the resolution of the fft algorithm using the same amount of data. To get that resolution with fft, don't we have to double the length of the data set?

Or am I missing something?

Thanks,
Ngawang
 
 
  • Post #435
  • Quote
  • Mar 4, 2009 8:12pm Mar 4, 2009 8:12pm
  •  ngawang
  • | Joined Oct 2008 | Status: Member | 52 Posts
The symmetry of FFT should guarrantee that Goertzel and FFT are equivalent.

To prove it, I think we need to create a new series xprime, which is half the length of x.

xprime is a complex valued vector where x was real.

The even numbered index elements of x go into the real values of xprime.
The odd numbered index elements of x go into the imaginary values of xprime.

so

xprime = x(even) + i*x(odd)

Then take the FFT of xprime.

output1 = fft(xprime);
output2 = output1((N/21)'); (reverse the order of the elements)
output2 = real(output2) + i*imag(output2); (complex conjugate)

output = (1/2)*(output1+output2)...
-(1/2)*i*(output1-output2) .* exp(2*pi*i*((0:N/2-1)')/(N/2));

fftAmplitude = sqrt(real(output).^2 + imag(output).^2);

There might be one or two more tricks involved in getting this to work out exactly, but I think this is the rough outline for proving that FFT and Goertzel are equivalent even in the case I mentioned in the previous note.

If someone has the exact algorithm, maybe they can post it. But this is the basic idea.

Ngawang
 
 
  • Post #436
  • Quote
  • Mar 5, 2009 4:26am Mar 5, 2009 4:26am
  •  BarHopper
  • | Joined Apr 2008 | Status: Pints and Points | 23 Posts
Hi Ngawang,

I quickly glanced at your code, so take this with a grain of salt, but I think I see the problem. You're defining your frequency vector as:
f1 = ((0:2:N)') ./ N ./ 2;
while the FFT defines the normalized frequency vector as
f2 = (0:N-1)/N;

If you use
[goertzelAmp goertzelPhase] = goertzel(x, f2);
I expect you'll get exactly the same values (within numerical limits) as
X = fft(x); fftAmp = abs(X); fftPhase = angle(X);

To answer your question about resolution, you can get K times the number of frequency points by doing:
f3 = (0:K*N-1)/(K*N);
[goertzelAmp goertzelPhase] = goertzel(x, f3);

which should be exactly equivalent to:
xk = [x; zeros((N*(K-1), 1)];
XK = fft(xk); fftAmp = abs(XK); fftPhase = angle(XK);

Assuming of course that everything is a column vector. Caveat: I haven't tested this code in Matlab, but barring any typos, I'm 90+ percent sure it's correct. Try it with K=5.

To see why zero padding the FFT works, go back to Oppenheim & Schafer or whatever DSP book you might have used. It's right in the definition of the DFT:

X(f) = sum(x[n] * exp(-j*2*pi*f*n/N)) where the sum is taken over n=1:N

If you zero-pad to K times the original length of N, you're then getting
X(f) = sum(x[n] * exp(-j*2*pi*f*n/(K*N))
where the sum is still just take over n=1:N, because x[n]=0 for n=N+1:K*N.

So what you've done by zero-padding is to create K times as many f points, spaced closer together than the original ones.

Again, I'm just typing, so I may have made a typo here or there, but I'm 90+ percent sure I'm saying the concepts correctly. Hope that helps...
 
 
  • Post #437
  • Quote
  • Edited Mar 6, 2009 8:06am Mar 5, 2009 11:15am | Edited Mar 6, 2009 8:06am
  •  ank2211
  • | Joined Jan 2009 | Status: Member | 1 Post
Yo Guys,

I'm new to the thread, looks like its pretty good though. Zero Padding your data vector would work but it has to be symmetrical on both sides of the vector for the Fourier Transform; however, all that really does is interpolate your frequency axis and does not really provide any new information. It would also be the same as just increasing the second argument to the fft algorithm [fft(x,N)] (in matlab) .

I was just wondering something about the SNR you guys are using to filter out bad trades, how are you determining the threshold to use? Completely adaptive, fixed based off historical optimization, or are you using some kind of classification scheme with it to determine whether this would be a good trade or not.

Finally for the adaptive time delay choosing mechanism with FNN, are you basically just cycling through given time lags on a data set and then seeing which one has the lowest embedding dimension? Also is there are reason why FNN is better than AFNN, from what I read/saw AFNN supposedly always gives more consistent parameter free results.

Nice robot btw CB.
 
 
  • Post #438
  • Quote
  • Mar 5, 2009 1:34pm Mar 5, 2009 1:34pm
  •  ngawang
  • | Joined Oct 2008 | Status: Member | 52 Posts
Barhopper,

Thanks for looking at that. Padding with 0s is infintely more straight forward. I was trying to do something from my notes, which were not complete and probably not 100% correct. I'm attaching as a PDF the section from "Numerical Recipes" which describes FFT of a real valued function. This is what I was trying reproduce yesterday if anyone is interested.

Thank You,
Ngawang
Attached File(s)
File Type: pdf FFT_Real.pdf   70 KB | 1,042 downloads
 
 
  • Post #439
  • Quote
  • Mar 7, 2009 1:10am Mar 7, 2009 1:10am
  •  dizzyd
  • | Joined Oct 2008 | Status: Member | 7 Posts
Hi all,

I've implemented the Goertzel DFT in my programming language of choice and, like adamant, have been running known signals through it to test that it's working correctly. One thing that I don't understand (and this is likely due to my poor grasp of the math behind the DFT) is why the magnitude returned out of the DFT is so large. For example, if I generate a simple sine wave with frequency of 1/60 and run it through my goertzel (Python code below), I'll get back an amplitude of 89.51 and phase of -1.571. The amplitude is far beyond what the original wave was -- is it scaled in some way? Is there a way to recover the original amplitude, or am I missing some fundamental concept here? I did notice that for each notch I increase amplitude, in the original function, the output of gx() is approx pi/2 * amp -- but I'm not sure what it means.

Any help/guidance would be appreciated.

Inserted Code
import numpy as np
import matplotlib.pyplot as plot

TWO_PI = 2 * np.pi

def gx(x, omega):
    s1 = s2 = 0.0
    zeta = 2.0 * np.cos(2.0 * np.pi * omega)

    for i in range(0, len(x)):
        s = x[i] + zeta * s1 - s2
        s2 = s1
        s1 = s

    real = s1 * (zeta / 2) - s2
    imag = s2 * np.sin(2.0 * np.pi * omega)

    amplitude = np.sqrt(np.power(real, 2) + np.power(imag,2))
    phase = np.arctan2(imag, real)

    return (amplitude, phase)

def wave(amp, freq, phase, x):
   return amp * np.sin(TWO_PI * freq * x + phase)

x = np.arange(0.0, 180.0)
y = wave(1, 1/60.0, 0, x)

(amp, phase) = gx(y, 1/60.0)
print amp, phase
 
 
  • Post #440
  • Quote
  • Mar 7, 2009 1:27am Mar 7, 2009 1:27am
  •  tdion
  • Joined Nov 2005 | Status: EURUSD Quant FREAK | 3,197 Posts
though i feel this may be an excellent academic exercise, at what point did we discover that markets are the equivalent of a digital signal?

therefore, at what point did we decide that vectors and fournier tranforms are appropriate methods of predicting where a price will go?

there is an old saying: give a man a hammer, and he will treat every problem as a nail.

i feel that common sense should not dictate being smart.
 
1
  • Trading Discussion
  • /
  • Optimized Trend Trading
  • Reply to Thread
    • 1 2021Page 222324 63
    • 1 21Page 2223 63
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023