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

AddInstrument after DataProvider = SellSideStrategy error
http://www.smartquant.com/forums/viewtopic.php?f=60&t=14960
Page 1 of 1

Author:  ambl [ Mon Sep 30, 2019 7:56 am ]
Post subject:  AddInstrument after DataProvider = SellSideStrategy error

I am inheriting from Strategy NOT InstrumentStrategy.

Calling Strategy.AddInstrument after DataProvider has been set to a SellSideStrategy produces the follwing exception in StrategyManager.StartStrategy.

System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at SmartQuant.StrategyManager.RegisterMarketDataRequest(IDataProvider dataProvider, InstrumentList instrumentList)
at SmartQuant.Strategy.IyAIcbAxSQ(Instrument , IDataProvider )
at SmartQuant.Strategy.HFVIbfPbhv(Subscription )
at SmartQuant.Strategy.PV4EBvLfD13()
at SmartQuant.StrategyManager.StartStrategy(Strategy strategy, StrategyMode mode)
at StrategyTests.RollerTests.TestScenario.Run() in C:\home\source\csharp\lib\Murphys\StrategyTests\RollerTests.cs:line 118
at StrategyTests.RollerTests.RollSellSide() in C:\home\source\csharp\lib\Murphys\StrategyTests\RollerTests.cs:line 93
at StrategyTests.RollerTests.Run() in C:\home\source\csharp\lib\Murphys\StrategyTests\RollerTests.cs:line 39

I have tested 5 cases:

(1)
To reproduce the exception:

// This produces the error when StrategyManager.StartStrategy is called
public class MyStrategy : Strategy
{
public SellSideStrategy sellSide;

public MyStrategy(Framework framework, string name) : base(framework, name)
{

sellSide = new SellSideStrategy(framework, "SellSide");
DataProvider = sellSide;
AddInstrument(InstrumentManager.Instruments["USDCAD"]);

} // throws exception

}

(2)
Aslo reproduces the exception:

// adding the instrument with specifying the DataProvider=sellSide also produces the exception
public MyStrategy(Framework framework, string name) : base(framework, name)
{

sellSide = new SellSideStrategy(framework, "SellSide");
// DataProvider = sellSide;
AddInstrument(InstrumentManager.Instruments["USDCAD"], sellSide);

} // throws exception

(3)

// If we swap the order of setting DataProvider and AddInstrument the error is bypassed:
public MyStrategy(Framework framework, string name) : base(framework, name)
{

sellSide = new SellSideStrategy(framework, "SellSide");
AddInstrument(InstrumentManager.Instruments["USDCAD"]);
DataProvider = sellSide;

} // works
(4)

// adding the instrument with specifying the DataProvider=DataSimulator avoids the error
public MyStrategy(Framework framework, string name) : base(framework, name)
{

sellSide = new SellSideStrategy(framework, "SellSide");
DataProvider = sellSide;
AddInstrument(InstrumentManager.Instruments["USDCAD"], DataSimulator);

} // works

(5)

// Setting DataProvider of the instrument to SellSideStrategy also throws exception:
public MyStrategy(Framework framework, string name) : base(framework, name)
{

sellSide = new SellSideStrategy(framework, "SellSide");
Instrument instrument = InstrumentManager.Instruments["USDCAD"];
instrument.DataProvider = sellSide;
AddInstrument(instrument);

} // throws exception

From the results of these test cases it is clear to me that adding an instrument with DataProvider=SellSideStrategy is broken. Please let me know if you agree this is an bug and if it will be fixed.

Author:  skuvv [ Mon Sep 30, 2019 1:02 pm ]
Post subject:  Re: AddInstrument after DataProvider = SellSideStrategy erro

Hi, thanks for details.
1-5) error fixed,
I also recommend using AddStrategy()
Code:
         SellSideStrategy sellSide = new SellSideStrategy(framework, "SellSide");
         
         GetRootStrategy().AddStrategy(sellSide);

         DataProvider = sellSide;
         
         AddInstrument(InstrumentManager.Instruments["IBM"]);


Update will be available on next release of OQ2014.

Author:  ambl [ Mon Sep 30, 2019 1:41 pm ]
Post subject:  Re: AddInstrument after DataProvider = SellSideStrategy erro

Great, Thankyou.

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