Machine learning in trading: theory, models, practice and algo-trading - page 3267

 
Alexandr Sokolov #:
I'll figure it out

... or at least tell me the principle
#  install.packages("quantmod")
library(quantmod)


#  Ето реальные тики которые мы заргужаем откудо то
real_tiks <- cumsum(rnorm(10000))
#  plot(real_tiks,t="l")
dft <- diff(real_tiks) #  ретурны



#  генерируем случайные тики из характеристик ретурнов реальных тиков
fake_tiks <- rnorm(n = 10000, mean = mean(dft), sd = sd(dft))
fake_tiks <- cumsum(fake_tiks)



#  создаем временной вектор чтобы создать обьект xts
times <- seq(as.POSIXct("2016-01-01 00:00:00"), length = length(fake_tiks), by = "sec")
xts_fake_tiks <- xts(fake_tiks, order.by = times)


# из тиков  создаю  м1
ohlc_m1 <- to_period(xts_fake_tiks, period = "minutes", k = 1)
#  head(ohlc_m1)
chart_Series(ohlc_m1)


for each function there is a help "question mark + function name" in the console.

?cumsum





There are also special packages for time series simulation


https://cran.r-project.org/web/packages/simts/vignettes/vignettes.html

https://search.r-project.org/CRAN/refmans/forecast/html/simulate.ets.html

 
mytarmailS #:


for each function there is help for each function "question mark + function name" in the console





There are also specialised packages for time series simulation


https://cran.r-project.org/web/packages/simts/vignettes/vignettes.html

https://search.r-project.org/CRAN/refmans/forecast/html/simulate.ets.html

Thank you
 
mytarmailS #:


for each function there is help for each function "question mark + function name" in the console

wrong, you make a normal distribution, but on the foreground it's a tail distribution

 
Maxim Dmitrievsky #:

Wrong, you're making a normal distribution, and the forex is tailed.

I showed a simple method, the most correct simulations in special packages, there everything is much more complicated than just repeating the distribution.

 
Maxim Dmitrievsky #:

Wrong, you're making a normal distribution, and the forex is tailed.

++

If you already have a downloaded array of ticks, I would do as fxsaber suggested here somewhere, generate a new array of ticks with a probability of 50% up or down. And I would make 100500 such different samples.
.

It would be a SB, with volatility like the original ticks.
 
sibirqk #:

++

If there is already a downloaded tick array, I would do as fxsaber suggested here somewhere, generate a new tick array with a 50% probability of up or down. And I would make 100500 such different samples.
.

It would be a SB, with volatility like the original ticks.
I did it through KDE (kernel density estimation), I get market distribution too
 

It's a great book!

It must cover all the problems of the MoD.

Tidy Modeling with R
Tidy Modeling with R
  • Max Kuhn and Julia Silge
  • www.tmwr.org
The tidymodels framework is a collection of R packages for modeling and machine learning using tidyverse principles. This book provides a thorough introduction to how to use tidymodels, and an outline of good methodology and statistical practice for phases of the modeling process.
 

R is remarkable for its hodgepodge. At any given moment, it has everything, any packages for any occasion.

But after a year or two, it's inimitable - it will be impossible to execute the examples in the book.

 
Maxim Kuznetsov #:

R is wonderful....

Everything else is not true)
 
Forester #:

I think PearsonCorrM2 will work quickly. We feed 1 matrix full, 2nd matrix from one row to be checked. And if you go from the end, you can specify the size of the first matrix as the number of the next row, so that you don't recalculate the correlation repeatedly to rows below the row being tested.

I tried to do the frontal variant at first - to count all rows each time. I got the impression that there is some error in Alglib, because I could not find it myself.

#include <Math\Alglib\statistics.mqh> // https://www.mql5.com/ru/code/11077

const matrix<double> CorrMatrix( const matrix<double> &Matrix )
{
  matrix<double> Res = {};
  
  const CMatrixDouble MatrixIn(Matrix);
  CMatrixDouble MatrixOut;  

  if (CBaseStat::PearsonCorrM(MatrixIn, MatrixIn.Rows(), MatrixIn.Cols(), MatrixOut)) // https://www.mql5.com/ru/code/11077
    Res = MatrixOut.ToMatrix();
  
  return(Res);
}

const matrix<double> CorrMatrix2( const matrix<double> &Matrix )
{
  matrix<double> Res = {};
  Res.Init(Matrix.Cols(), Matrix.Cols());
  
  const CMatrixDouble MatrixIn(Matrix);
  CMatrixDouble Vector(Matrix);
  CMatrixDouble Corr;

  for (int i = 0; i < (int)Matrix.Cols(); i++)
  {
    if (i)
      Vector.SwapCols(0, i);
    
    CBaseStat::PearsonCorrM2(Vector, MatrixIn, MatrixIn.Rows(), 1, MatrixIn.Cols(), Corr);
      
    Res.Col(Corr.Row(0), i);
  }
  
  return(Res);
}

#property script_show_inputs

input int inRows = 5; // Длина строки
input int inCols = 100; // Количество строк

void FillArray( double &Array[], const int Amount )
{
  for (uint i = ArrayResize(Array, Amount); (bool)i--;)
    Array[i] = MathRand();
}

bool IsEqual( matrix<double> &Matrix1, const matrix<double> &Matrix2, const double Sens = 1 e-10 )
{
  Matrix1 -= Matrix2;  
  
  const bool Res = (MathMax(MathAbs(Matrix1.Max()), MathAbs(Matrix1.Min())) < Sens);
  
  Matrix1 += Matrix2;
  
  return(Res);
}

#define  TOSTRING(A) #A + " = " + (string)(A) + " "

void OnStart()
{  
  double Array[];
  FillArray(Array, inRows * inCols);

  matrix<double> Matrix;  
  Matrix.Assign(Array);
  Matrix.Init(inCols, inRows);
  Matrix = Matrix.Transpose();
  
  Print(TOSTRING(inRows) + TOSTRING(inCols));
  
  matrix<double> Matrix1 = CorrMatrix(Matrix);
  matrix<double> Matrix2 = CorrMatrix2(Matrix);
  matrix<double> Matrix3 = Matrix.CorrCoef(false);
  
  Print(TOSTRING(IsEqual(Matrix1, Matrix2)));  
  Print(TOSTRING(IsEqual(Matrix1, Matrix3)));  
}


The result often coincides.

inRows = 5 inCols = 90 
IsEqual(Matrix1, Matrix2) = true 
IsEqual(Matrix1, Matrix3) = true 


But in some situations it doesn't.

inRows = 5 inCols = 100 
IsEqual(Matrix1, Matrix2) = false 
IsEqual(Matrix1, Matrix3) = true 


If it was always like this, it would be my mistake for sure. But there is something unclean here.