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

Issue with Barfactory within Substrategy
http://www.smartquant.com/forums/viewtopic.php?f=86&t=14883
Page 1 of 1

Author:  mikembb [ Tue Jan 08, 2019 11:11 pm ]
Post subject:  Issue with Barfactory within Substrategy

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

Author:  skuvv [ Wed Jan 09, 2019 9:48 am ]
Post subject:  Re: Issue with Barfactory within Substrategy

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);
      }   

Author:  mikembb [ Wed Feb 06, 2019 2:58 pm ]
Post subject:  Re: Issue with Barfactory within Substrategy

worked for me then too. My coding error. Cannot recall anymore, what it was.

Author:  mikembb [ Wed Feb 06, 2019 3:04 pm ]
Post subject:  Re: Issue with Barfactory within Substrategy

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?

Author:  skuvv [ Thu Feb 07, 2019 10:14 am ]
Post subject:  Re: Issue with Barfactory within Substrategy

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;

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