cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Kevin
Level I

find multiple peak values in a column

Hello,

I am working a data table that have time and length, and the length data is like wave. I want to find peak value of length of each wave, and label the time  when the peak happens in a new column as "peak". 

Can someone take a look and help me with the script?

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: find multiple peak values in a column

Here is a new column in your data table that detects peaks.

Jim

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: find multiple peak values in a column

Here is a new column in your data table that detects peaks.

Jim
Kevin
Level I

Re: find multiple peak values in a column

A lot of thanks!!

Marco1
Level IV

Re: find multiple peak values in a column

Hello Super TxNelsol,

I am pleased to greet you, a query:

Attached a table with 200 columns of high and low stock prices, I would like to create new columns that indicate or place 1 for lower prices and -1 for the highest prices (peaks), 0 for the rest of prices.

Close (200) - 1.18076
Close (199) - 1.18073
Close (198) - 1.18071
Optimal signal1: -1
Optimal signal2: 0
Optimal signal3: 0

Close (200) - 1.18056
Close (199) - 1.18056
Close (198) - 1.18057
Optimal signal1: 0
Optimal signal2: 0
Optimal signal3: 0

Close (200) - 1.18094
Close (199) - 1.18077
Close (198) - 1.1805
Optimal signal1: 0
Optimal signal2: 0
Optimal signal 3: 1

Greetings,

Marco

Marco1
Level IV

Re: find multiple peak values in a column

Scoping the Attachment 200 column table

txnelson
Super User

Re: find multiple peak values in a column

See if this works the way you are thinking

Names Default To Here( 1 );
dt = Current Data Table();

colCount = N Cols( dt );
// Loop across all of the columns
For( i = 1, i <= colCount, i++,

	// Create the new column and set all values to 0
	dt << New Column( "Optimal signal" || Char( i ), set each value( 0 ) );
	
	// Get the name of the column to work on
	theColName = Column( dt, i ) << get name;
	
	// Find all of the High Points
	Eval(
		Parse(
			"theRows = dt<<get rows where(lag(:\!"" || theColName || "\!"n,1) <= :\!"" || theColName
			 || "\!"n &   lag(:\!"" || theColName || "\!"n,-1) <= :\!"" || theColName ||
			"\!"n |
	(row()==1 & lag(:\!"" || theColName || "\!"n,-1) <= :\!"" || theColName ||
			"\!"n) |
	(row()==N Rows(dt) & lag(:\!"" || theColName || "\!"n,1) <= :\!"" ||
			theColName || "\!"n)
);"
		)
	);
	
	// Set the found rows to -1
	If( N Rows( theRows ) > 0,
		Column( dt, N Cols( dt ) )[theRows] = -1
	);

	// Find all of the Low Points
	Eval(
		Parse(
			"theRows = dt<<get rows where(lag(:\!"" || theColName || "\!"n,1) >= :\!"" || theColName
			 || "\!"n &   lag(:\!"" || theColName || "\!"n,-1) >= :\!"" || theColName ||
			"\!"n |
	(row()==1 & lag(:\!"" || theColName || "\!"n,-1) >= :\!"" || theColName ||
			"\!"n) |
	(row()==N Rows(dt) & lag(:\!"" || theColName || "\!"n,1) >= :\!"" ||
			theColName || "\!"n)
);"
		)
	);

	// Set the found rows to 1
	If( N Rows( theRows ) > 0,
		Column( dt, N Cols( dt ) )[theRows] = 1
	);
);
Jim
Marco1
Level IV

Re: find multiple peak values in a column

Dear Jim,

I am new to JMP, could you please adapt the script to the attached table?
Greetings

Marco

txnelson
Super User

Re: find multiple peak values in a column

Here is all you need to do

  1. Open the data table
  2. Go to    File=>New=>Script       This will open a blank script window
  3. Cut and past the script from the webpage into the Script Window
  4. Run the script by clicking on the txnelson_0-1641529000188.pngicon in the Script Window

     

That will run the script against the newly opened data table.

I strongly suggest that you take the time to read the Discovering JMP document available under the Help pull down menu.

Jim
Marco1
Level IV

Re: find multiple peak values in a column

Hi Jim,

 

Super easy to apply the Script, but the objective is for a formula in each new column to find the highest stock prices (peaks) and place -1 and the lowest stock prices place 1 ... within a column range that I define (column range = 1-2 or 1-10 or 1-100 or 1-1000 ... etc), that is, in a hypothetical scenario using a history of stock prices ... what moments During the day they would have been optimal to buy shares at a lower price .... and ..... sell shares at times of higher price or rise ......, in such a way that it can train a neural network to learn to buy when the share price reaches its lowest point or 1 and sell when the share price reaches its highest point or -1 and when the price is with little movement the formula put 0

Greetings,

Marco