SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Jan 28, 2023 3:33 pm

All times are UTC + 3 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Custom DataObject
PostPosted: Tue Feb 09, 2021 1:15 am 

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 244
How do you add a custom data object programmatically?

is this example correct?

    public class Full : DataObject
        public double price;
        public double size;
        public double bidPrice;
        public double askPrice;
        public double bidSize;
        public double askSize;
        public double direction;
        public bool isTrade;

        public Full(DateTime dateTime, double price, double size, double bidPrice, double bidSize, double askPrice, double askSize, bool isTrade, double direction) : base(dateTime)
            this.dateTime = dateTime;
            this.price = price;
            this.size = size;
            this.bidPrice = bidPrice;
            this.bidSize = bidSize;
            this.askPrice = askPrice;
            this.askSize = askSize;
            this.direction = direction;
            this.isTrade = isTrade;

      public override void Run()
         Instrument instrument = InstrumentManager["ESFull"];
         string filepath = @"C:\Users\apatel\Documents\ES\Full\full.csv";

         using (System.IO.StreamReader sr = new System.IO.StreamReader(filepath))
            sr.ReadLine(); //header

            while (sr.Peek() >= 0)
               string[] parts = sr.ReadLine().Split(',');

               //reducing fraction part to be able use in formatter
               string dt_ = parts[0].Substring(0, parts[0].Length - 2);

               DateTime dt = DateTime.ParseExact(dt_, "yyyy-MM-dd HH:mm:ss.fffffff", null);

               if (parts[1] != "") //parse trade
                  double tradePrice = double.Parse(parts[1]);
                  int tradeSize = (int)double.Parse(parts[2]);
                  sbyte direction = (sbyte)double.Parse(parts[7]);

                  Full full = new Full(dt, tradePrice, tradeSize, double.NaN, double.NaN, double.NaN, double.NaN, true, direction);

                  DataManager.Save(instrument, full, SaveMode.Add);
               if (parts[3] != "" && parts[5] != "") //parse bid
                  double bidPrice = double.Parse(parts[3]);
                  int bidSize = (int)double.Parse(parts[4]);
                  double askPrice = double.Parse(parts[5]);
                  int askSize = (int)double.Parse(parts[6]);

                  Full full = new Full(dt, double.NaN, double.NaN, bidPrice, bidSize, askPrice, askSize, false, double.NaN);

                  DataManager.Save(instrument, full, SaveMode.Add);
         strategy = new MyStrategy(framework, "Backtest");



Once you have loaded it how do you get the subscribe to custom data events in the simulator?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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:  
Powered by phpBB® Forum Software © phpBB Group