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

How to pre-load historical data to a strategy
http://www.smartquant.com/forums/viewtopic.php?f=64&t=14994
Page 1 of 1

Author:  zbxxxx [ Sun Mar 08, 2020 2:28 pm ]
Post subject:  How to pre-load historical data to a strategy

Hi,

I've just downloaded data from IQFeed as bars.
This the output from data viewer :

Data Series , Object Count , First Date Time , Last Date Time
Bar Range 60 , 1,835,079 , 01/02/2012 00:00:00 , 03/06/2020 16:03:00

Now I've followed the code in post viewtopic.php?f=64&t=6227
(please see code below)

I get no results from the function DataManager.GetHistoricalBars(Instrument , datetime1, datetime2, BarType.Time, 60)
However, it does print the bars in "OnBar"

Does the DB treat these downloaded bars differently to Saved Bars? If so, is there a way of accessing downloaded bars in this manner?


Thanks

-------------------------------------------------------------------------------------------------------------------
My Strategy :

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

DateTime datetime1;
DateTime datetime2;

protected override void OnStrategyStart()
{
datetime2 = new DateTime(2013, 12, 18); ;
datetime1 = datetime2.AddDays(-2);

Console.WriteLine(datetime1.ToString());
Console.WriteLine(datetime2.ToString());


foreach (Bar bar in DataManager.GetHistoricalBars(Instrument , datetime1, datetime2, BarType.Time, 60))
{
Console.WriteLine(bar);
Bars.Add(bar);
}
Console.WriteLine("cnt = " + Bars.Count.ToString());
}
protected override void OnBid(Instrument instrument, Bid bid) { Console.WriteLine(bid); }
protected override void OnAsk(Instrument instrument, Ask ask) { Console.WriteLine(ask); }
//protected override void OnTrade(Instrument instrument, Trade trade) { Console.WriteLine(trade); }
protected override void OnBar(Instrument instrument, Bar bar)
{
Console.WriteLine(bar);
//DataManager.Save(bar);
}
}

----------------------------------------------------------------------------------------------------------------------------
My Scenario :

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

public override void Run()
{
string instName = "XG#";
strategy = new MyStrategy(framework, "Backtest");
Initialize();
//strategy.AddInstrument("MSFT");

Instrument instrument = InstrumentManager.Instruments[instName];
strategy.AddInstrument(instName);
DataSimulator.DateTime1 = new DateTime(2013, 12, 15);
DataSimulator.DateTime2 = new DateTime(2013, 12, 20);
DataSimulator.SubscribeBid = false;
DataSimulator.SubscribeAsk = false;
DataSimulator.SubscribeTrade = true;
DataSimulator.SubscribeBar = true;

BarFactory.Add(instName, BarType.Time, 60);

StartStrategy();
}
}

Author:  zbxxxx [ Sun Mar 08, 2020 11:51 pm ]
Post subject:  Re: How to pre-load historical data to a strategy

Forgot to mention downloaded bars from IQ Feed are 1m bars ("Bar Range 60") ..

Author:  skuvv [ Tue Mar 10, 2020 10:11 am ]
Post subject:  Re: How to pre-load historical data to a strategy

Hello,
1)the simplest way to understand what is happening is to request historical market data via menu Data/Import/Historical.
You will get data or a message corresponding to the problem.
2)GetHistoricalBars (or other historical data) do not correlate with OnBar (or other live data).
The bars retrieved using GetHistoricalBars are not saving in DB without you.

Additionally, I recommend to try common instruments such as AAPL, MSFT.

Author:  zbxxxx [ Tue Mar 10, 2020 1:29 pm ]
Post subject:  Re: How to pre-load historical data to a strategy

I think I understand .. what you're saying is that data I download that's being used for backtesting (historic ticks) is not considered to be part of the "database" .. I should physically store this data using "Save" to be able to load it using the API GetHistoricalData. Would that be correct?

Author:  skuvv [ Wed Mar 18, 2020 11:02 am ]
Post subject:  Re: How to pre-load historical data to a strategy

zbxxxx wrote:
I think I understand .. what you're saying is that data I download that's being used for backtesting (historic ticks) is not considered to be part of the "database" .. I should physically store this data using "Save" to be able to load it using the API GetHistoricalData. Would that be correct?

Yes, after downloading the data remains in memory, then you can save it in the database (using DataManager.Save()) or use somehow.

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