Vendredi 15 mai 2009

Tracer la droite de régression linéaire en automatique, version 2.

Voici une version améliorée du premier programme (c'est ici) qui traçait en automatique la droite de régression linéaire des k dernières bougies.  Ce nouveau code est beaucoup plus rapide (suppression des boucles) et n'est plus limité pour la longueur de la droite.  Une vue de YHOO avec k=50, puis k=1000.




Pourquoi faire simple quand on peut faire compliqué ?  Comment ne pas avoir pensé plus tôt à utiliser la commande "LinearRegression" ?  Voici le code pour Prorealtime, il faut introduire k en variable :

///////////// regression automatique v.02 /////////
once j=0
de48=DPO[k*2](close)
if de48=de48[1] and de48[1]=de48[2] and de48[2]<>de48[3] then
    flag=1
endif
n=(k*2)-4
p=(n/2)-1
d100=DPO[n](close)
moy100=close-d100
co=(moy100-moy100[1]+(close[p])/n)*n
if flag=1 and flag[1]=0 then
    test=linearregression[k](co)
    test1=linearregressionslope[k](co)
    a=test1
    b=test-test1*k
endif
if flag=0 then
    reg=undefined
else
    j=j+1
    reg=a*j+b
endif
return reg

Jeudi 14 mai 2009

Algorithme de Goertzel : recherche de l'amplitude, de la période et de la phase du cycle.

Dans le dernier article sur l'algorithme de Goertzel, le programme permettait de retrouver les 2 périodes des cycles qui avaient la meilleure réponse.  Je l'ai complèté et corrigé pour qu'il sorte également l'amplitude correcte du cycle ainsi que la phase : cela afin de pouvoir redessiner la courbe.
Dans l'exemple ci-dessous, le signal (en noir) est une sinusoïde de période 11 ajoutée à une sinusoïde de période 19 (d'amplitude 2) avec un décalage de phase (90),  le tout avec une pincée de bruit..   Les 2 courbes (rouge et bleue) sont reconstruites par le programme, il reste à les superposer pour avoir le signal sans bruit.



Le code pour Prorealtime (k, en variable, est la fréquence déjà trouvée) :

////////////////// sous prgm goertzel  biss ////////////
a=barindex
sig=sin(360*a/11)+2*sin(360*a/19+90)
b=SQRT(barindex*(b+1))
b=abs((b-ROUND(b))*4)
c=b-1
sig=sig+c
n=200
pr=sig
alpha=2*cos(360*1/k)
q1=0
q2=0
for i=n downto 0//fenêtre de 200 barres
    q3=pr[i]+alpha*q1-q2
    q2=q1
    q1=q3
next
amp=sqrt(square(q1)+square(q2)-alpha*q1*q2)
real=q1-(alpha*q2)/2
imag=q2*sin(360*1/k)
phas=atan(imag/real)
if real<0 then
    phas=phas+180
elsif real>=0 and imag<0 then
    phas=phas+360
endif
return (2*amp/n)*sin(360/k+phas[1]+90),sig

Jeudi 16 avril 2009

RSI Chandeliers.


Voici à la demande de Mallory, le RSI en représentation chandeliers.  L'indicateur est calculé sur la cloture des barres précédentes et sur les données intra-barre de la dernière bougie.  Une vue de l'indicateur (14) appliqué à GOOG en daily :



Il faut bien sûr créer 3 indicateurs : bas, haut et corps.  Mettre également p en variable : longueur du RSI.
Et les codes pour Proréaltime :

//////////// rsi chandelier bas ////////////////
hausse=max(0,close-close[1])
baisse=max(0,close[1]-close)
mh=wilderaverage[p](hausse)
mb=wilderaverage[p](baisse)
rs=mh/mb
rsii=100-100/(1+rs)
hauss=max(0,open-close[1])
baiss=max(0,close[1]-open)
testh=(mh[1]*(p-1)+hauss)/p
testb=(mb[1]*(p-1)+baiss)/p
testrs=testh/testb
testrsi=100-100/(1+testrs)
hauss1=max(0,low-close[1])
baiss1=max(0,close[1]-low)
testh1=(mh[1]*(p-1)+hauss1)/p
testb1=(mb[1]*(p-1)+baiss1)/p
testrs1=testh1/testb1
testrsi1=100-100/(1+testrs1)
c2=min(rsii,testrsi)
r=abs(c2-testrsi1)
r=(r)/29
b1=testrsi1
c=1
b2=b1+r
b3=b2+r
b4=b3+r
b5=b4+r
b6=b5+r
b7=b6+r
b8=b7+r
b9=b8+r
b10=b9+r
b11=b10+r
b12=b11+r
b13=b12+r
b14=b13+r
b15=b14+r
b16=b15+r
b17=b16+r
b18=b17+r
b19=b18+r
b20=b19+r
b21=b20+r
b22=b21+r
b23=b22+r
b24=b23+r
b25=b24+r
b26=b25+r
b27=b26+r
b28=b27+r
b29=b28+r
b30=b29+r
return b1 coloured by c,b2 coloured by c,b3 coloured by c,b4 coloured by c,b5 coloured by c,b6 coloured by c,b7 coloured by c,b8 coloured by c,b9 coloured by c,b10 coloured by c,b11 coloured by c,b12 coloured by c,b13 coloured by c,b14 coloured by c,b15 coloured by c,b16 coloured by c,b17 coloured by c,b18 coloured by c,b19 coloured by c,b20 coloured by c,b21 coloured by c,b22 coloured by c,b23 coloured by c,b24 coloured by c,b25 coloured by c,b26 coloured by c,b27 coloured by c,b28 coloured by c,b29 coloured by c,b30 coloured by c

///////////// rsi chandelier haut ///////////////
hausse=max(0,close-close[1])
baisse=max(0,close[1]-close)
mh=wilderaverage[p](hausse)
mb=wilderaverage[p](baisse)
rs=mh/mb
rsii=100-100/(1+rs)
hauss=max(0,open-close[1])
baiss=max(0,close[1]-open)
testh=(mh[1]*(p-1)+hauss)/p
testb=(mb[1]*(p-1)+baiss)/p
testrs=testh/testb
testrsi=100-100/(1+testrs)
hauss1=max(0,high-close[1])
baiss1=max(0,close[1]-high)
testh1=(mh[1]*(p-1)+hauss1)/p
testb1=(mb[1]*(p-1)+baiss1)/p
testrs1=testh1/testb1
testrsi1=100-100/(1+testrs1)
c2=max(rsii,testrsi)
r=abs(c2-testrsi1)
r=(r)/29
b1=c2
c=1
b2=b1+r
b3=b2+r
b4=b3+r
b5=b4+r
b6=b5+r
b7=b6+r
b8=b7+r
b9=b8+r
b10=b9+r
b11=b10+r
b12=b11+r
b13=b12+r
b14=b13+r
b15=b14+r
b16=b15+r
b17=b16+r
b18=b17+r
b19=b18+r
b20=b19+r
b21=b20+r
b22=b21+r
b23=b22+r
b24=b23+r
b25=b24+r
b26=b25+r
b27=b26+r
b28=b27+r
b29=b28+r
b30=b29+r
return b1 coloured by c,b2 coloured by c,b3 coloured by c,b4 coloured by c,b5 coloured by c,b6 coloured by c,b7 coloured by c,b8 coloured by c,b9 coloured by c,b10 coloured by c,b11 coloured by c,b12 coloured by c,b13 coloured by c,b14 coloured by c,b15 coloured by c,b16 coloured by c,b17 coloured by c,b18 coloured by c,b19 coloured by c,b20 coloured by c,b21 coloured by c,b22 coloured by c,b23 coloured by c,b24 coloured by c,b25 coloured by c,b26 coloured by c,b27 coloured by c,b28 coloured by c,b29 coloured by c,b30 coloured by c

////////////// rsi chandelier corps ///////////////
hausse=max(0,close-close[1])
baisse=max(0,close[1]-close)
mh=wilderaverage[p](hausse)
mb=wilderaverage[p](baisse)
rs=mh/mb
rsii=100-100/(1+rs)
hauss=max(0,open-close[1])
baiss=max(0,close[1]-open)
testh=(mh[1]*(p-1)+hauss)/p
testb=(mb[1]*(p-1)+baiss)/p
testrs=testh/testb
testrsi=100-100/(1+testrs)
r=abs(testrsi-rsii)
r=(r)/29
if testrsi<rsii then
    b1=testrsi
else
    b1=rsii
endif
b2=b1+r
b3=b2+r
b4=b3+r
b5=b4+r
b6=b5+r
b7=b6+r
b8=b7+r
b9=b8+r
b10=b9+r
b11=b10+r
b12=b11+r
b13=b12+r
b14=b13+r
b15=b14+r
b16=b15+r
b17=b16+r
b18=b17+r
b19=b18+r
b20=b19+r
b21=b20+r
b22=b21+r
b23=b22+r
b24=b23+r
b25=b24+r
b26=b25+r
b27=b26+r
b28=b27+r
b29=b28+r
b30=b29+r
c=rsii-testrsi
return b1 coloured by c,b2 coloured by c,b3 coloured by c,b4 coloured by c,b5 coloured by c,b6 coloured by c,b7 coloured by c,b8 coloured by c,b9 coloured by c,b10 coloured by c,b11 coloured by c,b12 coloured by c,b13 coloured by c,b14 coloured by c,b15 coloured by c,b16 coloured by c,b17 coloured by c,b18 coloured by c,b19 coloured by c,b20 coloured by c,b21 coloured by c,b22 coloured by c,b23 coloured by c,b24 coloured by c,b25 coloured by c,b26 coloured by c,b27 coloured by c,b28 coloured by c,b29 coloured by c,b30 coloured by c



Dimanche 15 février 2009

Jeudi 12 février 2009

Les mots sont lachés.

Voici un petit site génial : http://www.wordle.net/



Je posterai dorénavant sous cette forme .


Mardi 20 janvier 2009

La Saisonnalité du CAC.

Voici 2 petits programmes qui permettent de superposer les cours de différentes périodes.  Le premier démarre avec une base 100 au 1er janvier alors que le second donne la courbe brute.

Ci-après une vue du CAC :
- En noir 2008.
- En vert 2007
- En blanc 2006
- En rouge foncé 2005
- En jaune 2004
- En orange 2003
- En bleu 2002
- En turquoise 2001
- En olive 2000
- En rouge 1999
- En violet 1998




On peut ainsi comparer le bear market précédent et la période actuelle.  On peut également faire une analyse de la saisonnalité.

Les codes des programmes pour Prorealtime :  Il faut introduire période (intervalle de temps passé) et compa (intervalle sur lequel on superpose le précédent) en variables.  Par exemple : période=2006 et compa=2008 donne l'année 2006 superposée sur l'année 2008. 

/////////////// prgm indicateur /////////////////
once a=0
if year>=periode then
    a=a+1
endif
if year=compa  then
    a=a-1
    c=close[a]
else
    c=undefined
endif
dif= (c-c[1])/c[1]
if year=compa and year[1]<>compa then
    gg=1
    base=100
else
    gg=dif+1
    base=base[1]*gg
endif
return base

/////////////// prgm sur les prix /////////////////
once a=0
if year>=periode then
    a=a+1
endif
if year=compa  then
    a=a-1
    c=close[a]
else
    c=undefined
endif
return c

Lundi 15 décembre 2008

Over / Under Divergence : Part II.

Voici donc la version baissière de "l'Over / Under Divergence".  Le premier article se trouve ICI (avec les conditions de validation).
Le screener a sorti GDI sur le NYSE, dont voici une vue :



Et le code pour Prorealtime :

x=stochastic[7,3](close)
z=stochastic[21,10](close)
if x>x[1] then
    hi=max(hi,x)
    hico=max(hico,max(high,high[1]))
endif
if x<x[1] and x[1]>x[2] then
    zt1=zt
    zt=z[1]
    sto2=sto1
    sto1=hi
    hi=0
    p3=p1
    p2=max(p1,hico)
    p1=max(highest[3](high),hico)
    if p2=p1 then
        p2=max(p3,p4)
    endif
    hico=0
    hico1=0
endif
if x<x[1] then
    p4=hico1
    hico1=max(hico1,high)
endif
c1=(p1>p2 and sto1<sto2 and x<x[1] and x[1]>x[2])
c2=(c1 and sto2>zt1 and sto1<zt)
if c2 and high[1]=highest[7](high) and low<low[1] and close<open then
    divi=3
else
    divi=0
endif
return divi

Dimanche 14 décembre 2008

Divergences baissières Stochastic et MACD.

A la demande de Jean-Michel, voici les codes convertis pour les divergences baissières Stochastic et MACD.  Le premier article, sur les divergences haussières, se trouve ICI.
Voici une vue de ADM, détectée par le screener :



Et les codes pour Prorealtime :

//////////////// divergence baissière stochastic ////////////////
x=stochastic[14,3](close)
y=average[5](x)
if x>y then
    hi=max(hi,x)
    hico=max(hico,max(high,high[1]))
endif
if x crosses under y then
    sto2=sto1
    sto1=hi
    hi=0
    p3=p1
    p2=max(p1,hico1)
    p1=max(highest[3](high),hico)
    if p2=p1 then
        p2=max(p3,p4)
    endif
    hico=0
    hico1=0
endif
if x<y then
    p4=hico1
    hico1=max(hico1,high)
endif
if p1>p2 and sto1<sto2 and x crosses under y and x<x[1] then
    sign=10
else
    sign=0
endif
return sign

///////////// divergence baissière MACD /////////////
m=macdline[9,19,6](close)
s=exponentialaverage[6](m)
if m>s then
    hi1=max(hi1,m)
    hico=max(hico,high)
endif
if m<s then
    hico1=max(hico1,high)
endif
if m crosses under s then
    a=hi1
    hi1=0
    c=max(hico,hico1)
    hico=0
    hico1=0
    a1=a0
    a0=a
    c1=c0
    c0=c
endif
if m crosses under s and a0<a1 and c0>c1 then
    sign=1
else
    sign=0
endif
maxmac=highest[4](m)
maxco=highest[5](high)
if m>s and maxco>c0 and maxmac<a0 then
    pre=.5
else
    pre=0
endif
return sign,pre

Mardi 9 décembre 2008

Boîtes de Darvas et Stratégies.

La stratégie employée par Darvas est une technique de breakout : achat lorsque le haut de la boîte est cassé, à cela on peut encore ajouter des filtres.  J'ai testé le système sur les actions US, celui-ci fonctionne mieux sur celles du Nasdaq que sur celles composant le Dow Jones (question de volatilité, valeur de croissance.....).  La majeure partie des gains s'effectue lors de la période 1999/2000 pour la plupart des valeurs.  Pour une première approche, il n'y a pas de slippage, ni de frais.  Le capital est de 20000, la portion investie de 10000, il n'y a pas de pyramidage.

Il y a comparaison entre les systèmes "bearish" et "bullish", ainsi qu'une variation de la validation de la cassure : par la cloture ou simplement par le high.  La condition de sortie du trade est une cassure par le bas d'une boîte.

Voici une vue de VRSN avec les EC's des différents systèmes :



Une autre vue avec OXY :



Le système 1 est le "bearish" + cloture.
Le système 2 est le "bearish" + high/low.
Le système 3 est le "bullish" + cloture.
Le système 4 est le "bullish" + high/low.

D'une façon générale, le système "bearish" est plus performant.  C'est curieux, j'aurais parié le contraire.  Je n'en ai pas analysé la raison, peut-être les sorties.  Sinon, pas de grosses différences entre les systèmes "cloture" et "high/low".  Suivant le support, c'est tantôt l'un, tantôt l'autre.

Voici les codes pour Prorealtime :

//////////////// système 1 /////////////////
if box=1 and (high>tth or low<ttl) then
    box=0
    flag=0
endif
if box=0 and flag=0 and low>low[3] and low[1]>low[3] and low[2]>low[3] then
    th=low[3]
    flag=1
endif
if flag=1 and box=0 and low<th then
    flag=0
endif
if flag=1 and box=0 and high<high[3] and high[1]<high[3] and high[2]<high[3] then
    tth=high[3]
    ttl=th
    box=1
endif
once tth=undefined
once ttl=undefined
if close>tth then
    buy 50 %CAPITAL at market thisbaronclose
endif
if close<ttl then
    sell at market thisbaronclose
endif

//////////////////// système 2 ////////////////
if box=1 and (high>tth or low<ttl) then
    box=0
    flag=0
endif
if box=0 and flag=0 and low>low[3] and low[1]>low[3] and low[2]>low[3] then
    th=low[3]
    flag=1
endif
if flag=1 and box=0 and low<th then
    flag=0
endif
if flag=1 and box=0 and high<high[3] and high[1]<high[3] and high[2]<high[3] then
    tth=high[3]
    ttl=th
    box=1
endif
once tth=undefined
once ttl=undefined
buy 50 %capital at tth stop
sell at ttl stop

////////////////// système 3 ///////////////////
if box=1 and (high>tth or low<ttl) then
    box=0
    flag=0
endif
if box=0 and flag=0 and high<high[3] and high[1]<high[3] and high[2]<high[3] then
    th=high[3]
    flag=1
endif
if flag=1 and box=0 and high>th then
    flag=0
endif
if flag=1 and box=0 and low>low[3] and low[1]>low[3] and low[2]>low[3] then
    ttl=low[3]
    tth=th
    box=1
endif
once tth=undefined
once ttl=undefined
if close>tth then
    buy 50 %CAPITAL at market thisbaronclose
endif
if close<ttl then
    sell at market thisbaronclose
endif

////////////////// système 4 ///////////////////
if box=1 and (high>tth or low<ttl) then
    box=0
    flag=0
endif
if box=0 and flag=0 and high<high[3] and high[1]<high[3] and high[2]<high[3] then
    th=high[3]
    flag=1
endif
if flag=1 and box=0 and high>th then
    flag=0
endif
if flag=1 and box=0 and low>low[3] and low[1]>low[3] and low[2]>low[3] then
    ttl=low[3]
    tth=th
    box=1
endif
once tth=undefined
once ttl=undefined
buy 50 %CAPITAL at tth stop
sell at ttl stop

Remarque : si vous voulez afficher pour contrôle, l'indicateur utilisé, il faut ajouter "return tth, ttl" à la place des instructions d'achat/vente.

Lundi 10 novembre 2008

The Bearish Darvas Boxes.

Voici donc, en prolongement de l'article précédent, les "Bearish Darvas Boxes".  Ici, les boîtes sont construites à partir d'un creux, ce qui devrait être plus efficace dans un marché baissier.  Ci-dessous une vue de GOOG, avec en fenêtre 1, les boîtes ordinaires et en fenêtre 2, les "bearish boxes".




Le résultat est complètement différent !  On voit bien que lorsque la tendance est baissière, le nouveau code est plus approprié : les boîtes sont plus étroites.

Et le code pour Prorealtime :

k=48
once tth=undefined
once ttl=undefined
n=(k*2)-4
p=(n/2)-1
h1=dpo[n](high)
moyh=high-h1
hi=(moyh-moyh[1]+(high[p])/n)*n
hi=(round(hi*100))/100
l1=dpo[n](low)
moyl=low-l1
lo=(moyl-moyl[1]+(low[p])/n)*n
lo=(round(lo*100))/100
low1=(round(low*100))/100
high1=(round(high*100))/100
if barindex > 100 then
    if box=1 and (high1>tth or low1<ttl) then
        box=0
        flag=0
    endif
    if box=0 and flag=0 and low1<=lo[46] and low1<=lo[45] and low1<=lo[44] then
        th=low1
        flag=1
    endif
    if box=0 and flag=1 then
        for zz=0 to 44
            if  lo[47-zz-1]<th or lo[47-zz-2]<th or lo[47-zz-3]<th then
                flag=0
                break
            endif
            if hi[47-zz]>hi[47-zz-1] and hi[47-zz]>hi[47-zz-2] and hi[47-zz]>hi[47-zz-3] then
                box=1
                ttl=th
                tth=hi[47-zz]
                break
            endif
        next
    endif
else
    tth=undefined
    ttl=undefined
endif
if box=1 then
    ba=ttl
else
    ba=tth
endif
return ba coloured by box-1, tth coloured by box-1, ttl coloured by box-1

Créer un blog sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus