SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Jul 14, 2020 8:03 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jul 16, 2019 2:39 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 236
Hi,

Can you guys show me how to import data that comes in this format programmatically for use in a strategy,

I have looked at the docs but cant get it to work/stream through dataManager:

datetime,tradePrice,tradeSize,direction,bidPrice,bidSize,askPrice,askSize
2014-11-20 21:48:30.961225000,NaN,NaN,NaN,76.15,10,76.17,1
2014-11-20 21:48:30.961225000,NaN,NaN,NaN,76.15,10,76.17,2
2014-11-20 21:48:32.691721000,NaN,NaN,NaN,76.16,1,76.17,2
2014-11-20 21:48:32.691721000,76.17,1,0,NaN,NaN,NaN,NaN
2014-11-20 21:48:32.691721000,76.17,1,0,NaN,NaN,NaN,NaN

Thanks


Top
 Profile  
 
PostPosted: Wed Jul 17, 2019 9:31 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Hello azuric,
I think it will be easier to check part of the string for "NaN":

Code:
string[] parts = line.Split(',');
if (parts[1] != "NaN") //parse trade
if (parts[4] != "NaN") //parse bid
if (parts[6] != "NaN") //parse ask


Top
 Profile  
 
PostPosted: Thu Jul 18, 2019 5:39 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 236
Thats fine but is there an example script of importing it in from an external folder programmatically. I cant get the example in the docs to work.


Top
 Profile  
 
PostPosted: Wed Aug 07, 2019 11:31 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 571
Example for scenario:

Code:
public override void Run()
        {
         Instrument instrument = InstrumentManager["AAPL2"];
         string filepath = "F:\\dataSample.txt";
         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] != "NaN") //parse trade
               {
                  double tradePrice = double.Parse(parts[1]);
                  int tradeSize = int.Parse(parts[2]);
                  
                  Trade trade = new Trade(dt, 0, instrument.Id, tradePrice, tradeSize);
                  
                  DataManager.Save(trade);
               }
                  
               if (parts[4] != "NaN") //parse bid
               {
                  double bidPrice = double.Parse(parts[4]);
                  int bidSize = int.Parse(parts[5]);
                  
                  Bid bid = new Bid(dt, 0, instrument.Id, bidPrice, bidSize);
                  
                  DataManager.Save(bid);
               }
               
               if (parts[6] != "NaN") //parse ask
               {
                  double askPrice = double.Parse(parts[6]);
                  int askSize = int.Parse(parts[7]);
                  
                  Ask ask = new Ask(dt, 0, instrument.Id, askPrice, askSize);
                  
                  DataManager.Save(ask);
               }
            }
         }
         
         Console.WriteLine("Finishedd");
        }


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