Brain-training tasks related to trading in one way or another. Theorist, game theory, etc. - page 22

 
new-rena:
It's fine. I've already posted the code. I'm just going to shake it up to the right answer and that's it.

Will you share the result...? :-)
 
new-rena:
I wonder - what does it look like - a non-sinusoidal geometric progression?
 
avtomat:

Very decent. I.e. we say that every subsequent step-opening of the lot in pips is getting closer and closer to a trend reversal, so we will not increase the order size, but we will open it just in case something goes wrong)))
 

Renat, so what do you need - to solve an equation or something else?

If the equation

MiniLot^(x^0)+MiniLot^(x^1)+MiniLot^(x^2) ... + MiniLot^(x^(N-1))=VolMax

is to be solved with respect to x, then it's easier than ever - by Newton's method or secants. But you need to specify MiniLot, VolMax and N.

 
new-rena:
That's pretty decent. I.e., we say that every subsequent lot opening step in pips is getting closer and closer to a trend reversal, so we won't increase the order size, but we will open it just in case something goes wrong)))

i don't know about that.... I was just solving a problem... it wasn't about reversals, trends or anything else.

And I've got my own ideas about that, too.

 
Mathemat:
Renat, so what do you need - to solve the equation or something else?

Now I want to write its solution in the form of a formula. I'm already deriving the formula.

Thank you very much.

 
new-rena: Now I want to write its solution in the form of a formula. I'm already working out the formula.
You can't derive a formula, you'll get a cancerous brain. But it is possible to write a function that solves it approximately. But that's if you have to solve it with respect to x, of course.
 
Mathemat:
You can't derive a formula, you'll get cancer in your brain. But you can write a function that solves it approximately. But that's if you have to solve it with respect to x, of course.
I've done it, but it's really a function
 
new-rena: Done, indeed the function

Show me.

P.S. My brain refuses to solve such a strange, alien problem. The monotonicity of the first derivative is not respected. And this prevents me from easily and simply solving the equation on x by secants/Newton's method. Although a dumb search (strongly optimized) solves it rather quickly.

But if it were not doubling, but simple multiplication, everything would be easier and clearer.

Here's the dumbest algorithm. It's quick, though. It needs about 50 iterations to get an accuracy of 10^(-8).

Here is avtomat's picture from the previous page, for starters.

And now mine (same parameters):

And code:

#property show_inputs

extern double _MiniLot = 0.01;
extern double _N = 77;
extern double _VolMax = 5.96;
extern double _err = 0.0000000001;
extern double _parts = 7;


double resolve( double err, int& count )
{
   double currErr = 10;
   double xLeft = 0.00000001;
   double xRight;
   double valLeft, valRight;
   double step = _VolMax / _parts;
   count = 0;
   while( step > err )
   {
      count ++;
      xRight = xLeft + step;
      valLeft = funct( xLeft );
      valRight = funct( xRight );
      if( valLeft * valRight > 0 )     
      { 
         xLeft += step; 
         continue; 
      }
      else                             step /= _parts;
   }
   return( xLeft );
}//+------------------------------------------------------------------+


      double funct( double x )
      {
         double sum = 0;
         for( int i = 0; i < _N; i ++ )
         {
            double xPowered = MathPow( x, i );
            sum += MathPow( _MiniLot, xPowered );
         }   
         return( sum - _VolMax );
      }//+------------------------------------------------------------------+




int start( )
{
   int st = GetTickCount( );
   int count;
   double x = resolve( _err, count );
   double gone = ( GetTickCount( ) - st ) / 1000.;
   Print( "Root is x = " + x + "; funct is f = " + funct( x ) + "; gone " + gone + " sec.; count = " + count  + " steps");
   return( 0 );
}//+------------------------------------------------------------------+

P.S. It's good to keep in mind that this algorithm works only for this function. It is monotone and therefore has a single root. Unfortunately, the non-monotonicity of the first derivative makes it impossible to apply the tangent method. True, the loss is not felt at all - the computation time taken using GetTickCount() is not even counted.

 

there's a bit more to the solution

to complete the picture ;))

Reason: