Getting started in C#

atpackard

Newbie
Messages
1
Likes
0
If I could get some guidance on the best way to handle data that would be great!

If I want to start off by calculating say the average true range for a stock and I have the date, open, high, low, close in a .csv file should i create arrays for this data or is it better to define a class with the above 5 variables?

Thanks for the help!
 
In Java (and C# will be almost the same):

No doubt some may disagree with me but I would create a class called something like TimeSeries or OhlcvSeries. Your TS class should contain something like an array or Vector of OHLCV objects. eg

Code:
class OHLCV
{
    private long    timeStamp;
    private double open;
    private double high;
    private double low;
    private double close;
    private double volume;

    public getHigh ()
    {
        return high;
    }
    // and so on for all the getters and setters
}

class OHLCVSeries
{
    private Vector<OHLCV> data = new Vector<OHLCV> ();



    public OHLCV getBarAt (int i)
    {
        return data.elementAt (i);
    }

    public void appendBar (OHLCV bar)
    {
         data.add (bar);
    }

    .......

    public double getCloseAt (int barIndex)
    {
        return data.elementAt (barIndex).getClose ();
    }

    .......

    public int getBarCount ()
    {
        return data.size ();
    }

}

And so on. In your OHLCVSeries class, create methods to get last bar, change last bar, get bar at time less than or equal etc etc. Also good idea to keep the time zone in this class and stor your timestamps in univeral time (GMT). perhaps add static methods to do period conversion ie convert a 1 min series to a five min series etc.

If you use array instead of Vector (or some other collection), then you might have to manage growing the array yourself if you append enough bars. Arrays may be a bit quicker.
 
Last edited:
Top