SmartQuant Discussion
http://www.smartquant.com/forums/

Custom DataObject
http://www.smartquant.com/forums/viewtopic.php?f=86&t=15015
Page 1 of 1

Author:  azuric [ Tue Feb 09, 2021 1:15 am ]
Post subject:  Custom DataObject

How do you add a custom data object programmatically?

is this example correct?

Code:
    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;
        }
    }


Code:
      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);
               }
            }
         }
         Console.WriteLine("Finished");
         strategy = new MyStrategy(framework, "Backtest");

         Initialize();

         StartStrategy();
      }


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

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/