In the stock market, the trend is often pre-judged. The so-called trend, that is, relatively regular pattern recognition patterns. In terms of image, it is the distribution of the curve of a stock for a period of time.
So, here's the problem.
Although we can distinguish between a small number of images, the difference is not a very large trend between the similarity degree. If, in the quantitative transaction, the process of sequencing batch matching, how to distinguish between the most similar curve mark? This requires a programmatic algorithm for matching.
For a curve, there is nothing more than a series of lines of coordinates. In the recursive calculation of the angle of the adjacent coordinate points, we can sum up the slope angle distribution product of the curve, which represents the shape of the curve. So, how to do batch matching? It is necessary to normalized the distribution product of the inclined angle, and the normal linear function is helpless to deal with the dimensionless interval. What to do with it? In fact, we can change the thinking, the difference calculation for each set of tilt angle, due to the 180°< adjacent coordinate point tilt angle interval > 0°, then the slope of the distribution gap, then the normal linear function of the normalized processing range.
package com.mms.tools; import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map; /** * trend line Fitting algorithm * ww */ public class Trend { /* Tilt angle Algorithm for any two-point line */ public static void main (String[] args) throws exception { //datum coordinate system list<map<string,double>> ls = new ArrayList<Map<String,Double>> (&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;MAP); <String,Double> m = new HashMap<String,Double> (); string strs = ""; m = new hashmap<string,double > (&NBSP;&NBSP;&NBSP;&NBSP;&N);Bsp; m.put ("x", 1.0); M.put ("Y", 1.0); ls.add (m); m = new HashMap<String,Double> (); m.put ("x", 2.0); M.put ("Y", 2.0); ls.add (m); m = new HashMap<String,Double> (); m.put ("x", 3.0); M.put ("Y", 3.0); ls.add (m); m = new HashMap<String,Double> (); m.put ("X", 4.0); M.put ("Y", 4.0); ls.add (m); m = new HashMap<String,Double> (); m.put ("X", 5.0); M.put ("Y", 5.0); ls.add (m); m = New hashmap<string,double> (); m.put ("X", 6.0); M.put ("Y", 6.0); ls.add (m); m = new HashMap<String,Double> (); m.put ("X", 7.0 ); M.put ("Y", 7.0); ls.add (m); m = new hashmap<string, Double> (); m.put ("X", 8.0); M.put ("Y", 8.0); ls.add (m); m = new hashmap<string, Double> (); m.put ("X", 9.0); M.put ("Y", 9.0); ls.add (m); m = new hashmap<string, Double> (); m.put ("X", 10.0); M.put ("Y", 9.0); &Nbsp; ls.add (m); Slope Normalization of //coordinate system List<Double> lvs = getlvs (LS); if (lvs != Null && lvs.size () >0) { / /Matching coordinate system List<Map<String,Double>> Lss = new arraylist<map<string,double>> (); for (int i=0;i<10;i++) { m = new HashMap<String,Double> (); m.put ("x", (double) (i+1)); M.put ("Y", (double) Getintmathnumber (1,9)); lss.add (m); } double guis = getguis (LSS,LVS); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//SYSTEM.OUT.PRINTLN ("Two coordinate system curve fitting (the smaller the value the more fitting): " +guis); } } /* * calculates the slope set of adjacent coordinates according to the coordinate system */ public static list<double > getlvs (List<map<string,double>> ls) { list<double> lvs = New arraylist<double> (); //sort if (Ls != null && ls.size () >0) { //system.out.println ("Datum coordinate system, slope set accounting"); for (Int i=0;i<ls.size (); i++) { if (I >0 && i<ls.size ()) { lvs.add (Getguilv (Ls.get (i-1). Get ("X"), Ls.get (i-1). Get ("Y"), Ls.get (i). Get ("X"), Ls.get (i). Get ("y"), 0 )); //system.out.println (i+ " | " +ls.get ( i-1). Get ("y") + " | " +ls.get (i). Get ("y") + " | datum slope " +getguilv (Ls.get (i-1). Get ("X"), Ls.get (i-1) . Get ("Y"), Ls.get (i). Get ("X"), Ls.get (i). Get ("y"), 0)); } } //system.out.println (""); } return lvs; } /* * calculates the slope set of adjacent coordinates based on the coordinate system, with respect to the weight value of the datum (aggregate weight) */ public static double getguis (List<map<string,double>> ls,list<double> lvs) { double guis = 0; //Sort if (Ls != null && ls.size () >0) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//SYSTEM.OUT.PRINTLN ("Matching coordinate system, slope set accounting match"); for (Int i=0;i<ls.size (); i++) { if (I >0 && i<ls.size ()) { guis += getguilv (Ls.get (i-1). Get ("X"), Ls.get (i-1). Get ("Y"), Ls.get (i). Get ("X"), Ls.get (i). Get ("Y"), Lvs.get (i-1)); // System.out.println (i+ " | " +ls. Get (I-1). Get ("y") + " | " +ls.get (i). Get ("y") + " | datum slope " +lvs.get (i-1) + " | Match weighted " + Getguilv (Ls.get (i-1). Get ("X"), Ls.get (i-1). Get ("Y"), Ls.get (i). Get ("X"), Ls.get (i). Get ("Y"), Lvs.get (i-1)); } } //system.out.println (""); } return guis; } /* * according to any two-point coordinate slope, the baseline, and the deviation normalization weight calculation (can calculate the slope, can also calculate the weight) */ public static double getguilv (double x1, Double y1,double x2,double y2,double atan) { double i = 0; // Tilt angle of the line between any two points double x = math.atan2 (x2-x1,y2-y1) *180/math.pi; if (atan == 0) { i = x; }else{ //Linear normalization function conversion (dispersion) normalization: (x-min)/(max-min); double y = x-atan;if (y <0) {y = -y;} //deviation weight i = (y-0)/(x-0); } return i; } /* * Random integers from startnumber to Endnumber */ public static int getintmathnumber (Int startnumber,int endnumber) { return (int) Math.Round (Math.random () * (Endnumber-startnumber) +startnumber); } }
Here is the Java algorithm code, the following is a graphical result.
Quasi-fit algorithm for arbitrary multiple curves