Making a Python trading system for MT. - page 11

 
Yuriy Asaulenko:

Those who read the topic From theory to practice already know that my system and A_K2's system are built roughly on the same ideology - channel work. The only difference is that mine was built a year ago. I've already written before, that now this strategy is implemented and tested in Python, with some minor changes, but there's no sense in launching it - nothing new is expected.

Since I had no ideas in particular, I developed all sorts of indicators - one of them is in the post above. I've made about ten of them. As the result I have decided to cross hedgehog with hedgehog: to combine work in the channel with trend following into one consistent system. I have not tried it as a whole yet, but I have practiced some elements. Everything seems to fit, but I still have some questions. I cannot say what will come out in practice, may be nothing. Let us wait and see.

Yuriy, hello! May I download / look at the latest version of your development in order to develop Python knowledge and learn from it? :-)
 

Just in case, news for those using Python. Version 3.6 is no longer in development, there will only be security updates. Support will be up to 21.

The current version is 3.7. The current one is 3.7.2. I'm using 3.7.1 with the latest Anaconda.

Actually, broke my Anaconda, and when I went to install the new one, I found out that a lot has changed. As they say, version 3.7 is faster (I haven't noticed yet, I was fine with it before), syntax has been updated and new functions have been added.

 

I have not yet gotten around to neural networks and other ML stuff - I'm into metering. I make tools for measuring current market parameters and their trends. The thing is that no neural network, forest-trees and other Ml can neither think up nor calculate these parameters, but they can use it all and generalize it.

And here is another tool in Python.

Here it is only 3 hours, at 1 min TF. The curve measures market activity. As a rule, market activity increases significantly even before the price starts moving, and it is a good indicator, a precursor to the beginning of the movement. The beginning of a decline in activity is almost always the beginning of a move into a flat. In the picture you can see that the indicator is even ahead of the MA(12) on the price chart.

But the indicator does not determine the direction of the future movement. It's a simple thing to draw small rectangles by crossing points and shift the direction, as it is done in the MO branch, you can draw them in your mind and here is a trend indicator)). If we look at the algorithm, we will see that it is not only a trivial matter, but also unnecessary and harmful - it destroys a number of indicator parameters. And the system will do joint processing of indicators, and will do it more optimally.

PS It has been suggested to me in private that the indicator is similar to ATR.

In fact, yes, it also measures volatility, but the maths is different. It's volatility as I understand it,)) and in my mind better reflects trading activity.

 

At someone's suggestion here on the forum, I implemented a Kalman filter. I was so praised, so praised...

In general, I wrote there, that it is unlikely there will be tangible result, but nevertheless I decided to check it.

I have figure of MA 48 and Kalman filter made on the basis of this MA (for correct comparison we should deal with one and the same object).

Well, yes, it is faster by about 1.5 times, but it may well be replaced with MA with a period of 28-30. They won't overlap completely, but it's hard to say which one is better, MA or Kalman.

Conclusion: it causes much trouble but is of little use. For trading purposes, of course. We are not engaged in navigation).

 

Needed a polynomial regression for a Python model. Maybe you may need it too.

Source code:

import matplotlib.pyplot as plt
import numpy as np 
from sklearn.preprocessing import PolynomialFeatures 
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
from sklearn.pipeline import make_pipeline

# Подготовка данных
x=np.linspace(-5,5,num=100)
Y =np.array([(0.13*x1**3-0.5*x1**2-0.8*x1-0.1) for x1 in x])
# график исходной кривой.
plt.plot(Y)
X=x[:, np.newaxis]
N=3
# полином регрессия
model=make_pipeline(PolynomialFeatures(N, include_bias=False), Ridge())
model.fit(X,Y)
y_plot = model.predict(X)
# накладываем поверх графика линию регрессии
plt.plot(y_plot)

Graph:

This is not one graph, but two. They are completely superimposed, which is to be expected since both the original curve and the regression are polynomials of degree 3. The error is of the order of 1e-3.

 

Another polynomial regression model. Its error is already on the order of 1.0e-15.

import matplotlib.pyplot as plt
import numpy as np 
from sklearn.preprocessing import PolynomialFeatures 
from sklearn.linear_model import LinearRegression
#from  sklearn.linear_model import Ridge
#from  sklearn.pipeline import make_pipeline

#  Подготовка данных
x=np.linspace(-5,5,num=100)
Y =np.array([(0.13*x1**3-0.5*x1**2-0.8*x1-0.1) for x1 in x])
plt.plot(Y)
X=x[:, np.newaxis]
N=3
#  расчет и вычисление линии регрессии
poly=PolynomialFeatures(N,include_bias=False)
Xm=poly.fit_transform(X)
reg = LinearRegression().fit(Xm, Y)
y_plot=reg.predict(Xm)
#  график линии регрессии
plt.plot(y_plot)

I don't show the graph, it hasn't changed. See post above.

 

Now see if the MA can replace the regression line. See picture.

Green - regression line (3rd degree polynomial), orange - MA(350).

It took me a long time to select it but I was not even able to closely match it. This MA, perhaps, is one of the best. By the way, it is also about the usefulness of tunable indicators).

In the future, we may perform some more experiments with regression lines.

 
Yuriy Asaulenko:

At someone's suggestion here on the forum, I implemented a Kalman filter. I got so much praise, so much praise...

- I didn't like Pavarotti's voice, he's got a bad accent, he can't hit the notes...

- Were you at Pavarotti's concert?

- No, Rabinovich told me on the phone.

 
TheXpert:

- So I didn't like Pavarotti, he's got a bad accent, he can't hit the notes...

- Have you been to a Pavarotti concert?

- No, Rabinovich told me on the phone.

If you are going to implement the Kalman filter in trading, I can send you an article. It is a classical algorithm, without any artificial thinking. But you will have to program it yourself. The article contains only mathematics. You will form your own opinion, and you will not be guided by Rabinowitz).

Reason: