SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Dec 13, 2019 4:24 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Oct 01, 2019 4:07 pm 
Offline

Joined: Wed Aug 07, 2019 7:49 am
Posts: 20
I have made a simple test IDataProvider which inherits from Strategy and wraps the DataSimulator so that I can edit bids/asks and re-emit them, however when I try set Strategy.DataProvider = TestDataProvider it does not set. See the code and output below.


public class TestDataProvider : Strategy, IDataProvider
{
public new ProviderStatus Status => DataProvider.Status;

public bool IsConnecting => DataProvider.IsConnecting;

public bool IsConnected => DataProvider.IsConnected;

public bool IsDisconnecting => DataProvider.IsDisconnecting;

public bool IsDisconnected => DataProvider.IsDisconnected;

byte IProvider.Id { get => (byte)Id; set { } }

public TestDataProvider(Framework framework, string name)
: base(framework, name)
{
}
protected override void OnAsk(Instrument instrument, Ask ask)
{
// edit tick and emit
framework.EventManager.OnEvent(new Ask(ask) { ProviderId = (byte)Id });
}
protected override void OnAsk(Instrument instrument, Bid bid)
{
// edit tick and emit
framework.EventManager.OnEvent(new Bid (bid) { ProviderId = (byte)Id });
}
public void Subscribe(Instrument instrument)
{
DataProvider.Subscribe(instrument);
}

public void Subscribe(InstrumentList instrument)
{
DataProvider.Subscribe(instrument);
}

public void Unsubscribe(Instrument instrument)
{
DataProvider.Unsubscribe(instrument);
}

public void Unsubscribe(InstrumentList instrument)
{
DataProvider.Unsubscribe(instrument);
}

public void Connect()
{
DataProvider.Connect();
}

public bool Connect(int timeout)
{
return DataProvider.Connect(timeout);
}

public void Disconnect()
{
DataProvider.Disconnect();
}
}

public partial class MyScenario : Scenario
{
public MyScenario(Framework framework)
: base(framework)
{
}

public override void Run()
{
strategy = new MyStrategy(framework, "Backtest");
TestDataProvider testDataProvider = new TestDataProvider(framework, "TestDataProvider");

Console.WriteLine($"strategy.DataProvider:: Expected: default, Actual: {strategy.DataProvider}");
strategy.DataProvider = null;
Console.WriteLine($"strategy.DataProvider:: Expected: null, Actual: {strategy.DataProvider}");
strategy.DataProvider = testDataProvider;
Console.WriteLine($"strategy.DataProvider:: Expected: TestDataProvider, Actual: {strategy.DataProvider}");

StartStrategy();
}
}

Outputs:
strategy.DataProvider:: Expected: default, Actual: provider id = 1 DataSimulator (Default data simulator) http://www.smartquant.com strategy.DataProvider:: Expected: null, Actual: provider id = 1 DataSimulator (Default data simulator) http://www.smartquant.com strategy.DataProvider:: Expected: TestDataProvider, Actual: provider id = 1 DataSimulator (Default data simulator) http://www.smartquant.com

Whats going on here? Am I missing something?


Top
 Profile  
 
PostPosted: Wed Oct 02, 2019 10:07 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
Hi,
here is a bit more complex situation.
strategy.DataProvider depends on several things and can show provider after start of strategy, eg OnStrategyStart event.


Top
 Profile  
 
PostPosted: Wed Oct 02, 2019 3:05 pm 
Offline

Joined: Wed Aug 07, 2019 7:49 am
Posts: 20
I dont quite understand what you're saying. If I set DataProvider after the strategy has started then it will work?

like so:

protected override void OnStrategyStart()
{
DataProvider = MyCustomDataProvider;
Console.WriteLine($"DataProvider: {DataProvider}");
}
This prints:
DataProvider: provider id = 1 DataSimulator (Default data simulator) www.smartquant.com
which indicates that it is still not being set even after the strategy has started...


Top
 Profile  
 
PostPosted: Wed Oct 02, 2019 5:36 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
Which StrategyMode do you use?


Top
 Profile  
 
PostPosted: Thu Oct 03, 2019 8:51 am 
Offline

Joined: Wed Aug 07, 2019 7:49 am
Posts: 20
Backtest


Top
 Profile  
 
PostPosted: Thu Oct 03, 2019 9:49 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
For simulation mode, strategy will return DataSimulator or SellSide based strategies.
Realtime provider not supposed for this mode.
Thus, if you want to create the simulation data provider, you can implement IDataSimulator interface.
In case when you want pre-process market data from other providers(DataSimulator in Backtest or Realtime providers in Live) you can choose SellSide strategy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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