finding the minimum of an equation - Traders Hideout | futures io social trading
futures io futures trading


finding the minimum of an equation
Updated: Views / Replies:956 / 12
Created: by adamov Attachments:3

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 3  
 
Thread Tools Search this Thread
 

finding the minimum of an equation

  #1 (permalink)
Elite Member
Budapest, Hungary
 
Futures Experience: None
Platform: ninjatrader
Favorite Futures: FGBL / FESX / ES / ZN / ZB
 
adamov's Avatar
 
Posts: 84 since Jun 2012
Thanks: 37 given, 48 received

finding the minimum of an equation

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:
Please register on futures.io 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!

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 1,981 since Sep 2013
Thanks: 1,396 given, 2,961 received
Forum Reputation: Legendary


The vertex equals the point where the first derivative is zero

Reply With Quote
The following user says Thank You to rleplae for this post:
 
  #4 (permalink)
Elite Member
Manchester, NH
 
Futures Experience: Beginner
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: Stocks
 
Posts: 887 since Jul 2012
Thanks: 596 given, 1,762 received

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

Reply With Quote
The following 2 users say Thank You to artemiso for this post:
 
  #5 (permalink)
Elite Member
Salt Lake City, UT
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Dormans/Zen-fire
Favorite Futures: 6E ES YM
 
Posts: 232 since Mar 2010
Thanks: 44 given, 321 received

this might help

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


Last edited by tulanch; March 17th, 2017 at 01:32 AM.
Reply With Quote
The following 2 users say Thank You to tulanch for this post:
 
  #6 (permalink)
Elite Member
Budapest, Hungary
 
Futures Experience: None
Platform: ninjatrader
Favorite Futures: FGBL / FESX / ES / ZN / ZB
 
adamov's Avatar
 
Posts: 84 since Jun 2012
Thanks: 37 given, 48 received

Thank you for all the inputs.

So after differentiating I got this:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



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.

Reply With Quote
 
  #7 (permalink)
Elite Member
Manchester, NH
 
Futures Experience: Beginner
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: Stocks
 
Posts: 887 since Jul 2012
Thanks: 596 given, 1,762 received

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
The following 2 users say Thank You to artemiso for this post:
 
  #8 (permalink)
Elite Member
Manchester, NH
 
Futures Experience: Beginner
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: Stocks
 
Posts: 887 since Jul 2012
Thanks: 596 given, 1,762 received

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
The following user says Thank You to artemiso for this post:
 
  #9 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,571 since Mar 2010
Thanks: 4,218 given, 25,168 received

Answer
This post has been selected as an answer to the original posters question Answer


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:
Please register on futures.io 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:
 
  #10 (permalink)
Elite Member
Budapest, Hungary
 
Futures Experience: None
Platform: ninjatrader
Favorite Futures: FGBL / FESX / ES / ZN / ZB
 
adamov's Avatar
 
Posts: 84 since Jun 2012
Thanks: 37 given, 48 received



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!

Reply With Quote
The following user says Thank You to adamov for this post:

Reply



futures io > > > finding the minimum of an equation

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

FIO Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

May
 

An overview of volumetric analytical tools w/Artem Topol @ PTMC

Elite only
 

Finding Success in Futures Trading w/John Hoagland

Jun 6
 

FuturesTrader71 Extended Ask Me Anything (AMA)

Elite only
 

Diving Into Order Flow w/Alex Haywood & Jigsaw Trading

Jun 8

John @ No BS Day Trading (TBA)

Elite only

An Afternoon with FIO member Softsoap (being rescheduled)

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Schrödinger Equation mroland19 Off-Topic 2 July 6th, 2015 05:19 AM
Need help formulating an equation in excel mmeyerin Off-Topic 0 March 7th, 2015 09:39 PM
Interesting Equation redratsal Off-Topic 13 December 14th, 2012 06:03 PM
Vant Tharp's Percent Volatility Position Sizing - FX equation - PLEASE ANYONE? fxhst329 Psychology and Money Management 5 November 16th, 2012 10:58 PM
The Trader's Equation: Should I Take This Trade? Anagami The Elite Circle 1 March 21st, 2011 05:33 PM


All times are GMT -4. The time now is 03:33 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-05-30 in 0.14 seconds with 38 queries on phoenix via your IP 54.162.168.187