SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 23, 2019 5:49 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Jan 08, 2019 11:11 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 260
Dear Team,

I seem to have a problem with the Barfactory for my substrategies in this setup:

I have a portfolio strategy which has two substrategies.

Once I start OQ2014 and my strategy – it loads the portfolio strategy and from within that, I setup my two substrategies with
Code:
this.AddStrategy(s);


The barfactory for one of the substrategies gets started right away (and works fine), but for the other, I do not need to barfactory for a few hours after I start.

Now, when I set an reminder from which I start this:
Code:
BarFactory.Add(Instrument, BarType.Time, BarSize.Minute);

I get all sort of
Quote:
System.NullReferenceExceptions
.

See below.
So, it seems to me, that I cannot have a substratgy start its Barfactory either there is some mandatory steps that I need to do, for the barfactory to work at init time.

Any idea would be welcome.

Mike

Quote:
EventManager::OnException Exception occured in EventHandler - id = 28 Error code = 354 Requested market data is not subscribed.HSI JAN'19/DEEP - System.NullReferenceException: Object reference not set to an instance of an object.
at OpenQuant.MyStrategy.OnProviderError(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.StrategyManager.NvLbeZGRlY(ProviderError )
at SmartQuant.EventManager.IfHrNiEnOk(Event )
at SmartQuant.EventManager.OnEvent(Event e)
source EventHandler exception: at OpenQuant.MyStrategy.OnProviderError(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.StrategyManager.NvLbeZGRlY(ProviderError )
at SmartQuant.EventManager.IfHrNiEnOk(Event )
at SmartQuant.EventManager.OnEvent(Event e) System.NullReferenceException: Object reference not set to an instance of an object.
at OpenQuant.MyStrategy.OnProviderError(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.Strategy.OQUtsMwVdu0(ProviderError error)
at SmartQuant.StrategyManager.NvLbeZGRlY(ProviderError )
at SmartQuant.EventManager.IfHrNiEnOk(Event )
at SmartQuant.EventManager.OnEvent(Event e) ev.TypeId 21


Top
 Profile  
 
PostPosted: Wed Jan 09, 2019 9:48 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 536
Hello,
Please specify:
1)Version of OQ2014
2)Type of the strategy
3)Is the instrument subscribed before adding to BarFactory?

Following code works fine for SMACrossover:

Code:
      bool isReminderSet;
      
      protected override void OnTrade(SmartQuant.Instrument instrument, SmartQuant.Trade trade)
      {
         if (!isReminderSet)
         {
            isReminderSet = true;
            
            AddReminder(Clock.DateTime.AddHours(1));
         }
      }   
      
      protected override void OnReminder(DateTime dateTime, object data)
      {
         BarFactory.Add(Instrument, BarType.Time, BarSize.Minute);
      }   


Top
 Profile  
 
PostPosted: Wed Feb 06, 2019 2:58 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 260
worked for me then too. My coding error. Cannot recall anymore, what it was.


Top
 Profile  
 
PostPosted: Wed Feb 06, 2019 3:04 pm 
Offline

Joined: Tue Oct 13, 2009 12:19 pm
Posts: 260
Though, now I run into something else:

I have 1 min bar data for each instrument. Now, when I want to make 10 min data out of it, the events only fire for the 1 min data, which is stored in OQ, but not the data which I expect Barfactory to build.

This is my code of my scenario:

Code:
#
        private long barSize = 600;

   public Backtest(Framework framework)
         : base(framework)      {      }

        private string baseCurrency = "USD";

        public override void Run()
      {
            StrategyManager.Mode = StrategyMode.Backtest;

            framework.EventManager.Clear();
            StrategyManager.Global.Clear();

            Instrument instrument1 = InstrumentManager.Instruments["ES_"];

         strategy = new MyStrategy(framework, "AllocationStrategy");

            strategy.AddInstrument(instrument1);

            BarFactory.Clear();
            BarFactory.Add(instrument1, BarType.Time, barSize, BarInput.Bar);

            DataSimulator.SubscribeBar = true;
            DataSimulator.DateTime1 = new DateTime(2017, 04, 01);
       DataSimulator.DateTime2 = new DateTime(2019,3, 31);
 
            ExecutionSimulator.Connect();
            if (ExecutionSimulator == null)
                Console.WriteLine("ExecutionSimulator == null");

            if (ExecutionSimulator.CommissionProvider == null)
            {
                Console.WriteLine("CommissionProvider == null");
                ExecutionSimulator.CommissionProvider = new CommissionProvider();
            }

            ExecutionSimulator.CommissionProvider.Type = CommissionType.PerShare;
            ExecutionSimulator.CommissionProvider.Commission = 2.01;

            ExecutionSimulator.FillOnBar = true; //otherwise it will only fill on trade.. which we do not have...
            ExecutionSimulator.FillAtLimitPrice = true;
            ExecutionSimulator.FillAtStopPrice = true;

            strategy.Init(); //mainly to setup accounts and therelike. so that we could add an account value here..
            strategy.Portfolio.Account.CurrencyId = CurrencyId.GetId(baseCurrency);
            strategy.Portfolio.Account.Deposit(1e6);
            StartStrategy();
      }


Any idea?


Top
 Profile  
 
PostPosted: Thu Feb 07, 2019 10:14 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 536
For using BarInput.Bar you should define input bars as below:
Code:
         BarFactoryItem item = BarFactory.Add(instrument1, BarType.Time, barSize, BarInput.Bar);
         
         item.InputBarSize = 60; // size from database
         item.InputBarType = BarType.Time; // type from database
         


Additionally, set reminder order in scenario:
Code:
framework.EventBus.ReminderOrder = ReminderOrder.After;


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