Page 1 of 1

Any help about the price vector model,please?

Posted: Fri Sep 10, 2004 10:06 pm
by yoyo2000
Hi,recently, I read a book "Trading system analysis" by Robert Barnes.
In which there is a model generating synthetic market data,its name is (Simple) price vector model.
I am very interested in it,but I couldn't get the exactly steps to perform it,for there is only simple description about them in the book,no related fomulars and step-by-step examples.
Could anyone give me some further information about it in details?
much appreciation!

Posted: Sat Sep 11, 2004 6:05 am
by Roscoe
Attached is a random data generator in an Excel file - just copy the formulae down as many rows as you want then copy to a regular ASCII file to work with. I presume this is what you are asking?

Posted: Sat Sep 11, 2004 7:59 am
by yoyo2000
Thank you for your kindness,Roscoe,actually,I'v got another random data generator,but the pure random data can't show the characteristic of market,so I wanted to generate synthetic data from real data in some way,and that's the purpose of the price vector model.maybe it's my fault not to describ the way they are done.
Since the book doesn't say the exactly steps,I can only describe it in a brief.
the following is how the price vector model works:
1.get a series of real data,identify and catalog the price vector as bull(up) and bear(down),finding how many there are of each (up and down separately) and graphing them separately by numbers of segments or price changes fro each vector or move.
2.find out how many vectors are there,and how many cells there should be for each piece or segment in these vector
3.then start randomly with an upvector or downvector,determine vector segment length from the vector segment distribution graph,and create prices for each segment of the vector.

but I feel puzzle that how to identify and catalog vectors?that's,how to determine the length ?

Posted: Sat Sep 11, 2004 4:05 pm
by verec
There is an answer which is so obvious that I surely didn't understand the question :?

Let's take a simple sequence of numbers:

Code: Select all

20, 23, 28, 25, 26, 29, 27, 23, 21, 20
Then draw a mark each time there is a "trend" change:

Code: Select all

20, 23, 28, 25, 26, 29, 27, 23, 21, 20
------------^---^-------^-------------
In this example you end-up with four "segments":
  1. starts at 20 and ends at 28, length: 3, nature: up
  2. starts at 28 and ends at 25, length: 2, nature: down
  3. starts at 25 and ends at 29, length: 3, nature: up
  4. starts at 29 and ends at 20, length: 5, nature: down
Are you after some code which, given a sequence of prices as above would tell you the segments, length and direction, or is the basic problem more subtle?
FWIW: here's some code that just implements the above:

Code: Select all

import java.util.ArrayList;
import java.util.List;

public class Sequence {
    
    int     segStart ;
    int     segEnd ;
    
    class Segment {
        float[] values ;
        int     start ;
        boolean up ;
        
        Segment(float[] series) {
            values = new float[1 + segEnd - segStart] ;
            System.arraycopy(series, segStart, values, 0, values.length) ;
            start = segStart ;
            up = values[values.length -1] >= values[0] ;
        }
        
        public String
        toString() {
            return  " starting at " + start
                   + " of length " + values.length
                   + " is " + (up ? "up" : "down")
                   ;
        }
    }

    Segment[]
    calcSegments(
        float[] series) {
        
        List segments = new ArrayList() ;
        
        segEnd = segStart = 0 ;
        
        float   prev = series[segStart] ;
        float   curr = 0 ;
        
        for (int i = 1, length = series.length ; i < length ; ++i) {
            curr = series[i] ;
            
            if (    (curr >= prev) && (series[segEnd] >= series[segStart])
                ||  (curr <= prev) && (series[segEnd] <= series[segStart])) {
                segEnd = i ;
            } else {
                segments.add(new Segment(series)) ;  // start new segment
                segStart = segEnd = i ;              // segments share
                --segStart ;                         // last value
            }
            
            prev = curr ;
        }
        
        segments.add(new Segment(series)) ; 
        
        return (Segment[]) segments.toArray(new Segment[0]) ;
    }
    
    void run(float[] series) {
        Segment[] segments = calcSegments(series) ;
        
        for (int i = 0, length = segments.length ; i < length ; ++i ) {
            Segment segment = segments[i] ;
            System.out.println("segment #" + i + segment) ;
        }
    }
    
    public static void main(String[] args) {
        float[] sample = { 20, 23, 28, 25, 26, 29, 27, 23, 21, 20 } ; 

        new Sequence().run(sample) ;
    }
    
    /*
     * segment #0 starting at 0 of length 3 is up
     * segment #1 starting at 2 of length 2 is down
     * segment #2 starting at 3 of length 3 is up
     * segment #3 starting at 5 of length 5 is down
     */
}
I'm sure you can translate this any way you fancy :wink:

later edit
If you have Java installed, which you can get otherwise from here you can compile and run the code as:

Code: Select all

javac Sequence.java
java -cp . Sequence

Posted: Sat Sep 11, 2004 10:08 pm
by yoyo2000
Thank you,Verec,I will study your code.