Page 1 of 1

DBase

Posted: Sat Feb 28, 2004 8:53 pm
by shakyamuni
Anyone have DBase experience? I need to build one to house my historical data and snatch it out to run sims.

Posted: Sun Feb 29, 2004 8:41 am
by Bernd
:wink:

Posted: Sun Feb 29, 2004 10:38 am
by Forum Mgmnt
shakyamuni,

As Hiramhon mentioned, we use memory to store historical data during testing. This is part of the reason VeriTrader can run a simulation in a few seconds.

In VeriTrader 2.0 we will be using a small SQL embedded database to store test results. This will allow us to offer a research management system so you can start with ideas and keep track of the tests associated with those ideas. The reasons a database will be used here is only partially because the data won't fit in memory.

The main reason is because SQL offers an ad-hoc query ability which will allow us to provide features enabling our users to search historical tests in ways we can't even anticipate. This will allow VeriTrader to stay on the leading edge.

Please read the other thread that Bernd mentioned, and perhaps you will come to the same conclusions we did.

- Forum Mgmnt

Posted: Mon Mar 01, 2004 1:09 am
by shakyamuni
Awesome, thanks for the great help guys! I read the other threads and got some good info.

Posted: Sat Mar 06, 2004 5:13 pm
by verec
What does the code that actually does the testing look like? Presumably, something of the sort:

Code: Select all

for(int i = 0, length = quotes.length ; i < length ; ++i) {
    Quote q = quotes[i] ;
    float close = q.close ;
    float high = q.high ;
    float low = q.low ;

    // here starts the interesting bits
    ...
}
Assuming that is the case, what you are interested in is in saving/restoring the quotes array, and this for each instrument.

There are a number of ways you can do this, but the most simple way is to let Java builtin serialization do it for you:

Code: Select all

package com.yourcompany.yourstuff.storage ;

import com.yourcompany.yourstuff.Quote ;

import java.io.FileOutputStream ;
import java.io.ObjectOutputStream ;
import java.io.FileInputStream ;
import java.io.ObjectInputStream ;

import java.io.IOException ;
import java.io.FileNotFoundException ;

public class QuoteStore {

    private static final String dataStore   =   "datastore.bin" ;
    
    private static Quote[]
    get(ObjectInputStream s) {
        Quote[] quotes = null ;
        try {
            quotes = (Quote[]) s.readObject() ;
        } catch(IOException e) {
        } catch(Throwable t) {
        } finally {
            return quotes ;
        }
    }
    
    public static Quote[]
    get() {
        Quote[] quotes = null ;
        try {
            FileInputStream in = new FileInputStream(dataStore);
            ObjectInputStream s = new ObjectInputStream(in);
            quotes = get(s) ;
            s.close() ;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        } finally {
            return quotes ;
        }
    }
    
    private static void
    put(Quote[] quotes, ObjectOutputStream s) {
        try {
            s.writeObject(quotes) ;
        } catch(IOException e) {
        }
    }
    
    public static void
    put(Quote[] quotes) {
        try {
            FileOutputStream out = new FileOutputStream(dataStore) ;
            ObjectOutputStream s = new ObjectOutputStream(out) ;
            put(quotes, s) ;
            s.close() ;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
    }
}
How to handle more than one such instrument is left as an exerxcise ;-)

Given this skeleton, then the first example can be rewritten as:

Code: Select all

Quote[] quotes = QuoteStore.get() ;
for(int i = 0, length = quotes.length ; i < length ; ++i) {
    Quote q = quotes[i] ;
    // as before ...
BTW: this code doesn't assume anything more complex than this is needed to group your daily OHLC together:

Code: Select all

class Quote {
    public float open ;
    public float high ;
    public float low ;
    public float close ;
}
HTH.