SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Oct 19, 2018 10:22 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Jul 03, 2015 7:41 pm 
Offline

Joined: Wed Mar 17, 2010 4:55 pm
Posts: 19
Dear Support

Because of plotting limitations of quote data we want to create bars programmatically after loading the quote data.

Here is the code that we run after we filled up the instrument with quote data:

Code:
         // compressing to bars
         var barSize = 60*15;
         var quoteSeries = DataManager.GetHistoricalQuotes(fxInstr, firstObsDate, lastObsDate);
         DataManager.CompressBars(quoteSeries, QuoteData.Bid, BarType.Tick, barSize);
         Console.WriteLine("Compressed quotes to bar series with bar size {0}", barSize);


What we observe is that only the first instrument (in alphabetic order with respect to symbol) has bar data create.
All other instruments do not have bar data in the data window in OQ.

Once we want to use the bar data in a simulation (also for that instrument which has bar data created) OpenQuant reports that they are not there and instead another bar series is subscribed.

What do we do wrong?

Many thanks for your help

Daniel


Top
 Profile  
 
PostPosted: Fri Jul 03, 2015 8:08 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

the first question is why do you not use the standard OQ dialog which allows to create the bars from the ticks?
also, could you provide the full code you use.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Sat Jul 04, 2015 10:14 am 
Offline

Joined: Wed Mar 17, 2010 4:55 pm
Posts: 19
Hi Alexei

I need to set it up programmatically because it is too time consuming to click through all the instruments and we have to set it up in an automated way.


Top
 Profile  
 
PostPosted: Sat Jul 04, 2015 11:31 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6808
Could you post complete code?

Thanks,
Anton


Top
 Profile  
 
PostPosted: Sat Jul 04, 2015 5:25 pm 
Offline

Joined: Wed Mar 17, 2010 4:55 pm
Posts: 19
Hi Anton

Here is the full code

Code:
using System;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Xml;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyScript : Script
{      
   public override void Run()
   {
      var verbose = 0;
      
      var dataPath = System.Environment.GetEnvironmentVariable("STRATEGYHOME") + "/data/hist";   
      
      Console.WriteLine("Data import path set to {0}.", dataPath);
      
      var instruments = new[] {
         new { Symbol = "AUDNZD", Currency = "NZD", FileExt = ".FXCM.dat"},
         new { Symbol = "AUDSGD", Currency = "SGD", FileExt = ".COMP.dat"},
         new { Symbol = "CHFJPY", Currency = "JPY", FileExt = ".FXCM.dat"},
         new { Symbol = "EURCAD", Currency = "CAD", FileExt = ".FXCM.dat"},
         new { Symbol = "EURNZD", Currency = "NZD", FileExt = ".FXCM.dat"},
         new { Symbol = "EURSGD", Currency = "SGD", FileExt = ".COMP.dat"},
         new { Symbol = "GBPAUD", Currency = "AUD", FileExt = ".FXCM.dat"},
         new { Symbol = "GBPCAD", Currency = "CAD", FileExt = ".FXCM.dat"},
         new { Symbol = "GBPCHF", Currency = "CHF", FileExt = ".FXCM.dat"},
         new { Symbol = "GBPUSD", Currency = "USD", FileExt = ".FXCM.dat"},
         new { Symbol = "NZDCHF", Currency = "CHF", FileExt = ".FXCM.dat"},
         new { Symbol = "USDJPY", Currency = "JPY", FileExt = ".FXCM.dat"}
      };
       
      bool ask = true;
      bool removeExisting = false;
      
      foreach (var instr in instruments) {
         var existing = InstrumentManager.Instruments[instr.Symbol];
         
         if (existing != null)
         {
            if (ask == true) {
               
               string message = string.Format("Instrument {0} already exists. Delete all existing?", instr.Symbol);
               string caption = "Delete existing instruments";
               var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo);
               
               ask = false;
               if (result == System.Windows.Forms.DialogResult.Yes)
                  removeExisting = true;
               else
               {
                  Console.WriteLine("Instrument creation aborted.");
                  break;
               }                  
            }

            if (removeExisting)
            {
               DataManager.DeleteQuoteSeries(existing);
               InstrumentManager.Remove(existing);
               Console.WriteLine("Deleted quote series and removed exiting instrument with symbol {0}.", instr.Symbol);
            }         
         }
         
         Instrument fx = new Instrument(InstrumentType.FX, instr.Symbol);
         
         // grab instrument again to work around bug
         Instrument fxInstr = InstrumentManager.Instruments[instr.Symbol];
         
         if (fxInstr == null) {
            Console.WriteLine("Error retrieving instrument with symbol {0}.", instr.Symbol);
            return;
         }
         
         // set all the necessary properties
         fxInstr.Currency = instr.Currency;
         fxInstr.Exchange = "IDEALPRO";
         Console.WriteLine("Created new instrument with symbol {0}.", instr.Symbol);
         
         var fileName = dataPath + "/" + instr.Symbol + instr.FileExt;
         Console.WriteLine("Reading historical data from file {0}.", fileName);
         
                        // this is an external lib to load data files
         Mdfa.Lib.Data.FMCXRow[] dataRows = Mdfa.Lib.Data.loadFMCX(fileName);
         Console.WriteLine("Loaded {0} data records.", dataRows.Length);
                  
         foreach (var row in dataRows) {
            if (verbose > 0) Console.WriteLine("Time = {0} bid {1} ask {2}", row.Time, row.Bid, row.Ask);
            var quote = new Quote(row.Time, row.Bid, 1, row.Ask, 1);
            DataManager.Add(fxInstr, quote);
         }
         
         var firstObsDate = dataRows[0].Time;
         var lastObsDate = dataRows[dataRows.Length-1].Time;
         Console.WriteLine("Added {0} data records from {1} to {2}.", dataRows.Length, firstObsDate.ToString(), lastObsDate.ToString());
      
         // compressing to bars
         var barSize = 60*15;
         var quoteSeries = DataManager.GetHistoricalQuotes(fxInstr, firstObsDate, lastObsDate);
         DataManager.CompressBars(quoteSeries, QuoteData.Bid, BarType.Tick, barSize);
         Console.WriteLine("Compressed quotes to bar series with bar size {0}", barSize);
      }
      
      Console.WriteLine("Finished importing data");
   }   
}


Top
 Profile  
 
PostPosted: Sat Jul 04, 2015 5:36 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

Quote:
Code:
DataManager.CompressBars(quoteSeries, QuoteData.Bid, BarType.Tick, barSize);


there is a problem.
CompressBars method returns the bar series, but does not save this series into db.

the code should look like:
Code:
  BarSeries barSeries = DataManager.CompressBars(quoteSeries, QuoteData.Bid, BarType.Tick, barSize);

  foreach (Bar bar in barSeries)
  {
    DataManager.Add(instrument, bar);
  }

  DataManager.Flush(); // optional call. it immediately flushes the data from the memory buffer to the disk

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Mon Jul 06, 2015 12:21 pm 
Offline

Joined: Wed Mar 17, 2010 4:55 pm
Posts: 19
Many thanks Anton, works perfectly now.


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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