SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Aug 15, 2020 1:10 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Jul 14, 2020 8:40 pm 
Offline

Joined: Thu Jul 09, 2020 6:23 pm
Posts: 3
I have futures daily historical data in csv format, with some custom fields in addition to OHLC. How do I go about importing such data so my custom fields can be accessible in OnBar method? I could do a dictionary based lookup keyed off of date, but wondering if there is a cleaner/faster way.

Thanks for your help.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2020 10:02 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 577
ssgonell wrote:
I have futures daily historical data in csv format, with some custom fields in addition to OHLC. How do I go about importing such data so my custom fields can be accessible in OnBar method? I could do a dictionary based lookup keyed off of date, but wondering if there is a cleaner/faster way.

Thanks for your help.

Hello,
Bar has the property named Fields. You can store any data inside Fields, eg:
Code:
bar[0] = "some text";
bar[1] = 123.123;


Top
 Profile  
 
PostPosted: Fri Jul 17, 2020 7:31 pm 
Offline

Joined: Thu Jul 09, 2020 6:23 pm
Posts: 3
So if we populate history programmatically and use bar["some-key"] = value and save data to .quant file, does it get persisted? Will I be able to access it as bar["some-key"] when loaded from the file next time?

Also, do you have any documentation that is more developer focused?

Thank you!


Top
 Profile  
 
PostPosted: Mon Jul 20, 2020 10:04 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 577
skuvv wrote:
So if we populate history programmatically and use bar["some-key"] = value and save data to .quant file, does it get persisted? Will I be able to access it as bar["some-key"] when loaded from the file next time?

Yes, it will be persistent.
Bar has two indexers, bar[int] and bar[string]. In case of string you should set this field each run of Framework before working with it:
Bar.AddField("some-key", index).
I think it will better to use constants instead of strings, eg:
Code:
    public class Fields
    {
        public const int Key1 = 2;
        public const int Key2 = 3;
    }

And somewhere in strategy:
Code:
var key1Value = bar[Fields.Key1];
var key2Value = bar[Fields.Key2];


Top
 Profile  
 
PostPosted: Tue Jul 21, 2020 7:48 pm 
Offline

Joined: Thu Jul 09, 2020 6:23 pm
Posts: 3
I have attempted something like this to load daily bars with custom fields:

Code:
            var instrument = new Instrument(InstrumentType.Index, "SPX", "Custom Daily", CurrencyId.USD);
            InstrumentManager.Add(instrument);
            var series = DataManager.AddDataSeries(instrument, 0, BarType.Time, BarSize.Day);
            var data = GetCustomData();
            foreach (var entry in data) {
                var bar = new Bar(entry.Date, entry.Date.AddDays(1), instrument.Id, BarType.Time, BarSize.Day,
                    entry.Open, entry.High, entry.Low, entry.Last, entry.Volume);
                // add custom fields here
                bar[CustomFields.Field1] = entry.Field1;
                bar[CustomFields.Field2] = entry.Field2;
                series.Add(bar);
                Console.WriteLine($"Adding bar: {bar}");
            }
            DataManager.Save(instrument, series, SaveMode.Add);


First, this returned null for series.
var series = DataManager.AddDataSeries(instrument, 0, BarType.Time, BarSize.Day);

Then, tried adding this:
InstrumentManager.Add(instrument);

Now I see this error on OQ startup followed by a crash:
System.FormatException: 'Input string was not in a correct format.'


Top
 Profile  
 
PostPosted: Wed Jul 22, 2020 11:11 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 577
ssgonell wrote:
First, this returned null for series.
var series = DataManager.AddDataSeries(instrument, 0, BarType.Time, BarSize.Day);

0 is wrong value, it should be DataObjectType.Bar for bars.

DataManager.AddDataSeries method is currently bugged and will be fixed in the next release.
You can work without handling DataSeries:

Code:
      Instrument instrument = InstrumentManager["SPX"];
         
         if (instrument == null)
         {
            instrument = new Instrument(InstrumentType.Index, "SPX", "Custom Daily", CurrencyId.USD);
            InstrumentManager.Add(instrument);
         }
         
         var bar = new Bar(DateTime.Now, DateTime.Now.AddDays(1), instrument.Id, BarType.Time, BarSize.Day,
            100, 102, 100, 101, 100500);
         // add custom fields here
         bar[101] = "some value";
         bar[102] = 123;
         
         Console.WriteLine($"Adding bar: {bar}");
         
         DataManager.Save(instrument, bar, SaveMode.Add);


Additionally, do not use
Code:
 DataManager.Save(instrument, series, SaveMode.Add);

in the current context(series), because it makes duplicates of the object in the series.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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