finding the minimum of an equation | Traders Hideout - futures trading strategies, market news, trading charts and platforms

Traders Hideout

Discuss day trading practices and futures trading strategies on this forum for all markets. This forum is also for discussing and reviews for brokers, data feeds, and commercial or third party add-ons


finding the minimum of an equation

  #9 (permalink)

Berlin, Europe
Trading Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
Fat Tails's Avatar
Posts: 9,779 since Mar 2010
Thanks: 4,234 given, 26,281 received

adamov View Post
I am trying to get the minimum value of curves in NT7 (C#) in the most resource efficient way.
The equation of one curve is:

y= |-22-16x|+|44-22x|+|21-25x|+|40-22x|+|6-11x|+|12-4x|

They always have and only one minimum point and they look like something like this:
Please register on to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Actually I am looking for the value of x when y is lowest.
Any help is appreciated!

This is a funny little puzzle!

If I look at your function it is built from six components, each component being the absolute amount of a linear function. Now let us look at a component function, for example

y1 = |-22-16x|

This function has two linear legs, a descending leg on the left side and and a rising leg on the right side. For x = -1.375 it takes the value zero.

The same is true for the other five component functions. Each of them is built from two legs and has a low point, where it takes the value 0. I conclude that the function y that you have exposed, has six points where it is not differentiable. Newton-Raphson cannot be used.

However, your function has another property, which makes a solution easy. With the exception of the low points of the six component functions your function can be built by adding six linear functions. Therefore it is linear itself between two low points. As a consequence one of the low points of the component function is the minimum for which you are looking.

Therefore you just need to calculate x1, x2, x3, x4, x5, x6 representing the low points of the component functions and then find out for which of those the function

y = |-22-16x|+|44-22x|+|21-25x|+|40-22x|+|6-11x|+|12-4x|

takes the lowest value.

Reply With Quote
The following 4 users say Thank You to Fat Tails for this post: