NexusFi: Find Your Edge


Home Menu

 





finding the minimum of an equation


Discussion in Traders Hideout

Updated
      Top Posters
    1. looks_one artemiso with 3 posts (5 thanks)
    2. looks_two adamov with 3 posts (1 thanks)
    3. looks_3 tulanch with 2 posts (2 thanks)
    4. looks_4 Fat Tails with 2 posts (4 thanks)
      Best Posters
    1. looks_one Fat Tails with 2 thanks per post
    2. looks_two artemiso with 1.7 thanks per post
    3. looks_3 tulanch with 1 thanks per post
    4. looks_4 adamov with 0.3 thanks per post
    1. trending_up 6,925 views
    2. thumb_up 13 thanks given
    3. group 5 followers
    1. forum 12 posts
    2. attach_file 3 attachments




 
Search this Thread

finding the minimum of an equation

  #1 (permalink)
 
adamov's Avatar
 adamov 
Budapest, Hungary
 
Experience: None
Platform: ninjatrader
Trading: FGBL / FESX / ES / ZN / ZB
Posts: 84 since Jun 2012
Thanks Given: 37
Thanks Received: 49

Hey
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:



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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
15 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
11 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


The vertex equals the point where the first derivative is zero

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 artemiso 
New York, NY
 
Experience: Beginner
Platform: Vanguard 401k
Broker: Yahoo Finance
Trading: Mutual funds
Posts: 1,152 since Jul 2012
Thanks Given: 784
Thanks Received: 2,685

@rleplae's answer is correct, a simple numerical solution to implement is the Newton-Raphson method.

Reply With Quote
Thanked by:
  #5 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 387

this might help

https://www.symbolab.com/solver/derivative-calculator/%5Cfrac%7Bd%7D%7Bdx%7D%5Cleft(12-4x%5Cright)

Reply With Quote
Thanked by:
  #6 (permalink)
 
adamov's Avatar
 adamov 
Budapest, Hungary
 
Experience: None
Platform: ninjatrader
Trading: FGBL / FESX / ES / ZN / ZB
Posts: 84 since Jun 2012
Thanks Given: 37
Thanks Received: 49

Thank you for all the inputs.

So after differentiating I got this:


This is what I should solve to 0

I looked into this Newton-Raphson method, its really interesting and could provide a really good approximation of root this function in a couple of steps but I should differentiate this again, and it makes it way too complicated.
only the first part looked like this:



wouldn’t be more efficient just increasing/decreasing the value of x in a cycle In the original equation until the value of y won’t get any smaller?
Whole numbers are fine for me, I don’t need any decimals.

Started this thread Reply With Quote
  #7 (permalink)
 artemiso 
New York, NY
 
Experience: Beginner
Platform: Vanguard 401k
Broker: Yahoo Finance
Trading: Mutual funds
Posts: 1,152 since Jul 2012
Thanks Given: 784
Thanks Received: 2,685

You need to distinguish between symbolic and numerical differentiation here. There's 3 different approaches depending on what you're trying to do:

If you're trying to find the analytical form of the first derivative, f' and solve the root for it, and you know the analytic formula of f at compile-time, you can solve f'=0 by hand and hard-code that into your program. Or you can find f' and then get quadratic convergence on the minimum with Newton-Raphson.

If you know the analytic form of f at runtime, there's different ways to perform symbolic differentiation, and chain rule-based approaches are popular, e.g. in backpropagation literature for neural networks.

If you don't know the analytic formula of f either at compile-time or runtime, you can still use Newton-Raphson but approximate f' numerically with any finite difference method (secant, forward difference, backward difference, central difference), then converge on f'=0 iteratively.

Reply With Quote
Thanked by:
  #8 (permalink)
 artemiso 
New York, NY
 
Experience: Beginner
Platform: Vanguard 401k
Broker: Yahoo Finance
Trading: Mutual funds
Posts: 1,152 since Jul 2012
Thanks Given: 784
Thanks Received: 2,685

Also if you do know the analytic form and decide to solve the first order necessary condition, do make sure that your function is strictly convex. (The derivative does not exist at x=0 for f(x) = |x|.)

Reply With Quote
Thanked by:
  #9 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


adamov View Post
Hey
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:



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
Thanked by:
  #10 (permalink)
 
adamov's Avatar
 adamov 
Budapest, Hungary
 
Experience: None
Platform: ninjatrader
Trading: FGBL / FESX / ES / ZN / ZB
Posts: 84 since Jun 2012
Thanks Given: 37
Thanks Received: 49



Fat Tails View Post
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.

Awsome!!
Thinking out of the box.

I had some similar reasoning in my head. I was sure the it has to be somewhere between the biggest and smallest root of the components like you explained.
I was experimenting to calculate the minimum point from all the roots somehow, but I wouldn't thought its gonna be one of them.

Flawless logic!
Thanks you and everybody who contributed!

Started this thread Reply With Quote
Thanked by:




Last Updated on March 22, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts