SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Jan 29, 2020 7:07 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Feb 08, 2011 6:03 am 
Offline

Joined: Tue May 11, 2010 8:37 pm
Posts: 18
Hi,

Whats the most effecient way to reference an array of openquant data... for example of the last 1000 closing values of an instrument so that it can be passed to a double[] for other analysis? I'm trying to accomplish something like this

double[] dataArray = new double[1000];
for (int i = 0; i < dataArray.Length; i++)
{
dataArray[i] = instrument1.Bar.Close[i];

}

using (Engine eng = Engine.Open())
{
eng.SetVariable("data", dataArray);
eng.Eval("ReturnSeries1 = price2ret(data)");
eng.Eval("plot(ReturnSeries1);

I'm just a bit confused because it seems that it can be done a few ways in openquant and I've usually only needed first and last values to do similar things.

Thanks In Advance
L.C.


Top
 Profile  
 
PostPosted: Mon Feb 14, 2011 9:17 pm 
Offline

Joined: Mon Sep 08, 2008 2:20 am
Posts: 40
Location: Toronto, Ontario, Canada
Sorry... Don't really understand what you're getting at.
You just want to copy array values?

If that's what you want to do you could:
Code:
//
        // Instantiate the source array.
        //
        int[] source = new int[5];
        source[0] = 1;
        source[1] = 2;
        source[2] = 3;
        source[3] = 4;
        source[4] = 5;
        //
        // Instantiate and allocate the target array.
        //
        int[] target = new int[5];
        //
        // Copy the source to the target.
        //
        Array.Copy(source, target, 5);


If you want to just pass a pointer... in C# you need to use the fixed keyword.
http://msdn.microsoft.com/en-us/library/f58wzh21%28v=vs.80%29.aspx

If you want to copy values from a list of objects you can use linq.
http://msdn.microsoft.com/en-us/vcsharp/aa336746

But for just copying values from an array... you got it... just use a good ol for loop.


Top
 Profile  
 
PostPosted: Tue Mar 08, 2011 7:03 pm 
Offline

Joined: Tue May 11, 2010 8:37 pm
Posts: 18
Hi,

Thanks for the response...I'm actually just now returning to this project... To explain a bit better I'm using some Matlab wrappers that I need to convert BarSeries data into a type double array for a very lengthy script. My question would probably be better put is there a better way to place all the close data of a barseries in dataArray other than defining each value as Barseries.Ago(0).Close etc....?

Sorry the code is a little sloppy... I was just playing arround with a few ideas... Any help is greatly appeciated

Thanks In Advance


Code:
      
      Instrument TSEURUSD = InstrumentManager.Instruments["TSEURUSD"];
      BarSeries EURBars = DataManager.GetHistoricalBars(TSEURUSD, BarType.Time, 60);
      DateTime datetime2 = DateTime.Now;
      DateTime datetime1 = datetime2.AddHours(-4);
      foreach (Bar bar in DataManager.GetHistoricalBars(TSEURUSD, datetime1, datetime2, BarType.Time, 60))
      EURBars.Add(bar);


         double[] dataArray = new double[6];
         for (int i = 0; i < dataArray.Length; i++)
         {
            dataArray[0] = EURBars.Ago(0).Close ;   
            dataArray[1] = EURBars.Ago(1).Close ;
            dataArray[2] = EURBars.Ago(2).Close ;   
            dataArray[3] = EURBars.Ago(3).Close ;
            dataArray[4] = EURBars.Ago(4).Close ;
            dataArray[5] = EURBars.Ago(5).Close ;
            Array.Reverse(dataArray);

         }
         
         

         using (Engine eng = Engine.Open())
         {
            eng.SetVariable("data", dataArray);
            eng.Eval("retseries = price2ret(data)");
            eng.Eval("data_mean = mean(data)");
            Console.WriteLine("The mean is : {0}", eng.GetVariable<double("data_mean"));
                      eng.Eval("plot(retseries); figure(gcf)");
         
            // Clean up
            eng.Eval("clear ");
            eng.Eval("clc");         
         }
         Console.Read();
      }
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group