SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Nov 21, 2017 11:20 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Sep 27, 2016 4:00 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hello,

I followed the "How to Work with Multiple Time Frames" section of your FAQ to use Bars from multiple time frames at once.

What would I do differently to use multiple bar types at once?
For instance how would I use the following all at the same time?

-600 second regular Bars
-300 second Middle bars
-200 Tick bars

Thanks


Top
 Profile  
 
PostPosted: Tue Sep 27, 2016 9:15 am 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6778
Well, just add items with different bar types to the BarFactory... BarFactory.Add(instrument, BarType.Time, barSize);

Regards,
Anton


Top
 Profile  
 
PostPosted: Tue Sep 27, 2016 12:59 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
I understand how to add them to the Scenario.cs file.
Just not sure how to add them in the MyStrategy.cs file after they have been added to the Scenario.cs file.

For instance, I see how the following code (from the FAQs) is used in the MyStrategy.cs file to add regular time based bars. Just not sure what changes I would make if adding Tick bars and Mid bars.

Code:
 if (bar.Size == 60)
      bars1min.Add(bar);
 if (bar.Size == 300)
     bars5min.Add(bar);


Top
 Profile  
 
PostPosted: Tue Sep 27, 2016 7:09 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6778
if (bar.Type == BarType.Time)
...


Top
 Profile  
 
PostPosted: Thu Sep 29, 2016 12:02 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Thanks!
That answers my question.


Top
 Profile  
 
PostPosted: Tue Feb 07, 2017 1:59 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
How does this work when using Bid bars?

I tried if (bar.Input == BarInput.Bid) but it wouldn’t compile.


Top
 Profile  
 
PostPosted: Thu Feb 09, 2017 2:29 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Any thoughts/hints regarding on this?:)

I tested and confirmed I'm subscribing to Bid bars properly in the scenariorio file via using BarInput.Bid in the Scenario file (while at the same time subscribing to Ask bars properly in the scenario file via using BarInput.Ask in the Scenario file).

The confusion is with the Strategy file.


Top
 Profile  
 
PostPosted: Fri Feb 10, 2017 10:01 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 383
Currently you can use BarSize and BarType for identification your bars.
If you want use same BarSize and BarType with different BarInput you can use following trick:

Imagine that your instrument is AAPL, BarSize = 300, BarType = Time.
And you want use Trade and Middle bars.
You can create copy of instrument(AAPL copy),
add it in scenario to InstrumentManager, to strategy and to BarFactory as usually.
Next you can determine what bar by using InstrumentId.


Top
 Profile  
 
PostPosted: Fri Feb 10, 2017 1:41 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6778
Perhaps we can add BarInput as bar field but this will make bar odject heavier, which in turn will make things a bit slower and more memory consuming...

Regards,
Anton


Top
 Profile  
 
PostPosted: Sat Feb 11, 2017 12:55 am 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hi Anton,
Would it make things slower and more memory consuming all the time? Or just when I'm using the BarInput as a bar field in a strategy file?

if it will slow things down all the time perhaps there is a way you can make it so that one can turn the feature on and off programmatically and/or via the GUI? Similar to how one can choose whether or not to subscribe to market depth data.

Hi Skuvv,

I tried the trick you mentioned via the following code. Full solution file is also attached if you need to take a closer look (see Backtest2 for scenario and MyStrategy2 for strategy). The Bid Bars and Ask bars it made showed the same data (see attached 1.jpg).

Any idea what the issue is? Perhaps I misunderstood the trick you mentioned?

Scenario file code
Code:
         Instrument instrument1 = InstrumentManager.Instruments["AAPL"];
         Instrument instrument2 = InstrumentManager.Instruments["AAPL"];

         strategy = new MyStrategy2(framework, "SMACrossover2");

         (strategy as MyStrategy2).Instrument1 = instrument1;
         (strategy as MyStrategy2).Instrument2 = instrument2;
         
         strategy.AddInstrument(instrument1);
         strategy.AddInstrument(instrument2);

         DataSimulator.DateTime1 = new DateTime(2011, 07, 01);
         DataSimulator.DateTime2 = new DateTime(2019, 07, 09);

         BarFactory.Clear();
         
         BarFactory.Add(instrument1, BarType.Time, 60, BarInput.Bid);
         BarFactory.Add(instrument2, BarType.Time, 60, BarInput.Ask);


Strategy file code
Code:
    public class MyStrategy2 : Strategy
    {
        public Instrument Instrument1;
        public Instrument Instrument2;
      private BarSeries bidBars;
      private BarSeries askBars;
      
      public Group bidBarsGroup;
      private Group askBarsGroup;
      

        public MyStrategy2(Framework framework, string name)
            : base (framework, name)
        {
        }

        protected override void OnStrategyStart()
        {
         bidBars = new BarSeries();
         askBars = new BarSeries();
         AddGroups();
        }
      
      protected override void OnBar(Instrument instrument, Bar bar)
      {
         
         if (instrument == Instrument1
            && bar.Type == BarType.Time
            && bar.Size == 60)
   
         {
            bidBars.Add(bar);
            Log(bar.Close , bidBarsGroup); // new part
            
         }
         
         if (instrument == Instrument2
            && bar.Type == BarType.Time
            && bar.Size == 60)
   
         {
            askBars.Add(bar);
            
            Log(bar.Close , askBarsGroup); // new part
            
         }
      }



Attachments:
1.JPG
1.JPG [ 67.58 KiB | Viewed 1672 times ]
Bar Input Test.zip [20.79 KiB]
Downloaded 34 times
Top
 Profile  
 
PostPosted: Sat Feb 11, 2017 2:19 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6778
Hi,

if you add a field (another byte = Bar.InputSize) to a bar object, obviousely it is there all the time and every bar will eat more memory and you will need to spend time reading/writing this field to the database even if you don't use it.

Perhaps it's possible to use Bar.Fields ObjectTable to store this additional field...

Regards,
Anton


Top
 Profile  
 
PostPosted: Tue Feb 14, 2017 8:16 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Thanks Anton.
Hey Skuvv, any thoughts on my last post regarding the Trick you mentioned?


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:41 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 383
M101 wrote:
Thanks Anton.
Hey Skuvv, any thoughts on my last post regarding the Trick you mentioned?

In you scenario you have:
Code:
         Instrument instrument1 = InstrumentManager.Instruments["AAPL"];
         Instrument instrument2 = InstrumentManager.Instruments["AAPL"];

Which means that instrument1 = instrument2,
at result both rules will be triggered regardless of instrument:
Code:
         if (instrument == Instrument1
            && bar.Type == BarType.Time
            && bar.Size == 60)
   
         {
            bidBars.Add(bar);
            Log(bar.Close , bidBarsGroup);
            
         }
         
         if (instrument == Instrument2
            && bar.Type == BarType.Time
            && bar.Size == 60)
   
         {
            askBars.Add(bar);
            
            Log(bar.Close , askBarsGroup);
            
         }


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 7:03 pm 
Offline

Joined: Thu Sep 17, 2015 5:52 am
Posts: 133
Hi skuvv, I thought what I did in the scenario file is what you meant by the quote below.
Can you please elaborate a little more on what you meant by the quote below?

Quote:
You can create copy of instrument(AAPL copy),
add it in scenario to InstrumentManager


Thanks.


Top
 Profile  
 
PostPosted: Fri Feb 17, 2017 10:36 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 383
M101 wrote:
Hi skuvv, I thought what I did in the scenario file is what you meant by the quote below.
Can you please elaborate a little more on what you meant by the quote below?

Quote:
You can create copy of instrument(AAPL copy),
add it in scenario to InstrumentManager


Thanks.

Backtesting:
In this case copy means that you will have two independent instruments.
And second instrument should have copy of all data(export from instrument1 - import to instrument2).

Realtime:
In this case you don't need make a copy of data because it comes from provider,
you need only setup AltId for all instruments to use them with provider.

Additionally it can be done other way,
you can create copy of incoming tick(for instrument2) when it comes to instrument1's strategy.
And send new tick to framework, at result it will come to instrument2's strategy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

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