Back

[Feature] History and Warmup

Hey all!

I'm here to publicly announce a feature that we've all been waiting for, history and warmup! With these new features you can request historical data from any point in the algorithm. You can also specify a warm up period where we'll pump historical data through the algorithm to get it into a ready state. This is great for live trading when you have some indicators that may take weeks, months, or even years to reach a ready state. Now that same algorithm can be ready to start trading within minutes of deploying!

Here's a link to all the History and Warmup API methods on the base algorithm class.

Have a look at the simple history demo algorithm I put together for you guys. Feel free to ask questions!
Update Backtest






The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.



Hi Michael,

The History functionality is very useful.
While trying to use it, I met some difficulty in getting minute bar history while subscribing to per tick data. Please see the code attached.
Is it because we can only get history for subscribed resolution?

Also want to ask if the history function is available for indicators? What can I do to get the previous RSI value formed by the previous bars?

Thanks a lot!

Jianwei
0


History function should work on any resolution you've requested, I'll look into it with Mike to find out why its not working. In the future please post bug reports to https://www.quantconnect.com/support

History returns an array of data and you can use this to manually warm up your indicators, or you can also use "SetWarmup(timespan)" to pump data through the OnData and indicator update methods like normal. SetWarmup sets a period before the start date and starts pumping in data early, then it also does the same in live mode.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Will do next time.
Thank you.
0

Hey, the tick bug has been recently fixed and will be available with the next deploy, thanks to @StefanoRaggi for the fix!
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thank you! Looking forward to the release
0

How does the History call behave when you're running in Live mode? I assume the same?
0

In live mode custom data uses exactly the same code, so it should behave 100% the same. Non custom data (ticks/trade bars) will make a request over the internet for the requested historical data, so it may take just a little bit longer depending on the size of the request and how frequently you would like to do it.

Other than the potential delay inherent in running in a live environment, they should behave the same!
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This is awesome! I've been having trouble implementing it in my forex, GBP/USD, algo. Does it work with forex data? Is there any significant changes to the code?
0

Hey Timothy, it works with any data type. Please post an example algorithm so we can help you further.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


its saying there is an error with the foreach(var tradeBar in History) line
// Set Warmup
int warmupPeriod = emaMultiple*emaSlow;
var history = History(Symbol, warmupPeriod);
foreach (var tradeBar in history)
{
fast.Update(tradeBar.EndTime, tradeBar.Close);
slow.Update(tradeBar.EndTime, tradeBar.Close);
confirmation.Update(tradeBar.EndTime, tradeBar.Close);
}
0

I believe its all working fine Tim. Please share a whole algorithm if you think there's a specific error.
See backtest attached demonstrating EURUSD history.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


I appreciate the help however Im hesitant to post my algo for privacy reasons. Does this error mean anything to anyone?

Runtime Error: This is a forward only indicator: EMA150(GBPUSD_min) Input: 2015-10-23 00:22:00Z Previous: 2015-10-27 19:01:00Z (Open Stacktrace)
0

Hey Timothy, without the code it's hard to be sure, but it looks like you're feeding in multiple data streams to the same indicator. Possibly passing history to an indicator AND using the warm up feature? This error is a warning saying that you're passing past data into an indicator. In this case, you've passed data into the EMA_150(GBPUSD_min) indicator up until 2015.10.27 19:01:00Z, but then you tried to pass data from 2015.10.23 00:22:00Z - So the indicator throws an exception since you're not feeding it a continuous stream of data and would give spurious results.

If you're concerned about privacy, it's typically fairly easy to clone the algorithm and remove and intellectual property you'd like to keep private. I hope this description of the problem helps. If you're still having issues, try to reproduce it in an algorithm you're willing to share.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Oh this is fantastic. Thanks Michael!
0

Hi,
When I try to run Jared's example above I get:

Runtime Error: 'EURUSD' wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("EURUSD") (Open Stacktrace)

Could you please check what is going on? I got similar error running another forex example and this issue seems to be a recent one. Thanks.
0

Its always good practice to read the stack trace (by clicking the link in the error message). The error is that the benchmark feed (SPY) is getting through to the OnData method, and is fixed by the line mentioned in the error message:
if (!data.ContainsKey("EURUSD")) return;

Or you can set a custom benchmark so your statistics are relative to EURUSD (after AddSecurity):
SetBenchmark("EURUSD");
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Jared,

Quick question: if I have coarse universe resolution set to "Minute", and I need to warmup the universe, say, for 5 days (which is 1950 tradeable minutes), would I need to do the following:

SetWarmup(1950)

or is this function expecting "days" as the period, as the universe only rotates daily?

Thanks!

0

Hey Stephen, how are you trying to use warm up exactly? Warm up runs exactly once right after initialization. If you're using universe selection and didn't manually add securities then there's nothing to 'warm-up'. If you need to get data for securities added via universe selection, have a peek at the history api.

To answer your question, the periods in there is specific to each security. For example, say I have VXX minute and SPY daily and SetWarmup(100), this will get me 100 minutes points for VXX and 100 daily points for SPY. This history function behaves the same way, so you could request the last 100 data points of history for all securities using something like the following:var slices = History(100);Slices here is an IEnumerable<Slice>

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Michael,

Sorry I wasn't clear earlier; I'm trying to use SetWarmup to warm up the indicators I use in my coarse universe filter (similar to the SelectionData class you implemented in the Cross EMA coarse universe example algorithm). Else, live trading the program takes several days to actually start crunching.

I think I may be using SetWarmup incorrectly, and may need to use history as you suggest. I'm getting the feeling that all warmup is, is running the program for a predefined period prior to the official start date. This is VERY useful for backtesting, but I'm guessing it doesn't translate to live trading very well. :-P

0

Sadly universe selection is not currently involved in the warm up period. On the first invocation of the coarse selection function you could gather all of the symbols and make one massive history request for it using the history overload that accepts symbols and a period count. Warm up does work in live trading, but only for securities that have already been added to the algorithm. In universe selection, you're scanning securities that have not been added, and so warm up won't know to get data for these guys.

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Ah I see. Could this not be done within the CustomSecurityInitializer? Or does each individual security in the universe get initialized over and over again with each universe rotation?

0

I was thinking something like this, where the code is copy-pasted from the EMA cross example algorithm. All I've added are lines 37-42. But I'm not certain this would work, as I'm given the error: "An object reference is required for the non-static field, method, or property, QCAlgorithm.History(Symbol, int, Resolution)."

I'm guess this is because SelectionData in this example has no interface with QCAlgorithm?

using System;
using System.Collections.Concurrent;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;

namespace QuantConnect
{
///


/// In this algorithm we demonstrate how to perform some technical analysis as
/// part of your coarse fundamental universe selection
///

public class EmaCrossUniverseSelectionAlgorithm : QCAlgorithm
{
// tolerance to prevent bouncing
const decimal Tolerance = 0.01m;
private const int Count = 10;
// use Buffer+Count to leave a little in cash
private const decimal TargetPercent = 0.1m;
private SecurityChanges _changes = SecurityChanges.None;
// holds our coarse fundamental indicators by symbol
private readonly ConcurrentDictionary _averages = new ConcurrentDictionary();


// class used to improve readability of the coarse selection function
private class SelectionData
{
public readonly ExponentialMovingAverage Fast;
public readonly ExponentialMovingAverage Slow;

public SelectionData(string symbol)
{
Fast = new ExponentialMovingAverage(100);
Slow = new ExponentialMovingAverage(300);

var history = History(symbol, 350);
foreach (var tradeBar in history)
{
Fast.Update(tradeBar.EndTime, tradeBar.Close);
Slow.Update(tradeBar.EndTime, tradeBar.Close);
}

}

// computes an object score of how much large the fast is than the slow
public decimal ScaledDelta
{
get { return (Fast - Slow)/((Fast + Slow)/2m); }
}

// updates the EMA50 and EMA100 indicators, returning true when they're both ready
public bool Update(DateTime time, decimal value)
{
return Fast.Update(time, value) && Slow.Update(time, value);
}
}

///
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
///

public override void Initialize()
{
UniverseSettings.Leverage = 2.0m;
UniverseSettings.Resolution = Resolution.Daily;

SetStartDate(2010, 01, 01);
SetEndDate(2012, 01, 01);
SetCash(100*1000);

SetBrokerageModel(BrokerageName.TradierBrokerage);
SetSecurityInitializer(new CustomSecurityInitializer(BrokerageModel, DataNormalizationMode.Raw));

AddUniverse(coarse =>
{
return (from cf in coarse
// grab th SelectionData instance for this symbol
let avg = _averages.GetOrAdd(cf.Symbol, sym => new SelectionData(cf.Symbol))
// Update returns true when the indicators are ready, so don't accept until they are
where avg.Update(cf.EndTime, cf.Price)
// only pick symbols who have their 50 day ema over their 100 day ema
where avg.Fast > avg.Slow*(1 + Tolerance)
// prefer symbols with a larger delta by percentage between the two averages
orderby avg.ScaledDelta descending
// we only need to return the symbol and return 'Count' symbols
select cf.Symbol).Take(Count);
});
}

///
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
///

/// TradeBars dictionary object keyed by symbol containing the stock data
public void OnData(TradeBars data)
{
if (_changes == SecurityChanges.None) return;

// liquidate securities removed from our universe
foreach (var security in _changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol);
}
}

// we'll simply go long each security we added to the universe
foreach (var security in _changes.AddedSecurities)
{
SetHoldings(security.Symbol, TargetPercent);
}
}

///
/// Event fired each time the we add/remove securities from the data feed
///

/// Object containing AddedSecurities and RemovedSecurities
public override void OnSecuritiesChanged(SecurityChanges changes)
{
_changes = changes;
}
}
}

0

A very important point here is that data that comes through the universe selection functions may not have corresponding security objects. That is to say, it's just the data accompanied by a symbol which defines the security's identifier, but not the security itself (including models, price, ect...). So a custom ISecurityInitializer is great for modifying a security once it's been selected by the universe, but won't do anything for data with no matching security in the universe selection data.

Another concern with doing these types of history calls one at a time is it can take a long time, so it would be best to collect all of the symbols and make a request on the first selection.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


RE: Error

The error you're receiving is because the History function is a method on your algorithm instance and you're trying to invoke it from another class. You could modify the constructor to accept an instance of QCAlgorithm and then call algorithm.History(symbol, 350);. Here's the updated constructor: public SelectionData(QCAlgorithm algorithm, string symbol)
{
Fast = new ExponentialMovingAverage(100);
Slow = new ExponentialMovingAverage(300);

var history = algorithm.History(symbol, 350);
foreach (var tradeBar in history)
{
Fast.Update(tradeBar.EndTime, tradeBar.Close);
Slow.Update(tradeBar.EndTime, tradeBar.Close);
}
}



EDIT: While this should work as we want it to, it may be very slow on the first coarse selection since it will be making about ~7000 unique history requests.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Gotcha, thanks very much for the help. So I attempted the above with the following code (where, for the QCAlgorithm object, I pass in "this" within the coarse universe Linq statement), but it ended up not making any trades (flatlining) throughout the entire trade period. If it's not too much to ask, could i perhaps email you the pid to investigate when you have the time? I'm unfortunately unable to request log output of the universe to debug on my end, as it would overload your system quite quickly! :-)

public SelectionData(QCAlgorithm algorithm, string symbol, int window)
{
SMAMetric = new SimpleMovingAverage(window);
RollingMetric = new RollingWindow(window);

var history = algorithm.History(symbol, 21, Resolution.Daily); // 21 days
foreach (var tradeBar in history)
{
Update(tradeBar.EndTime, tradeBar.Close); // Method within SelectionData class to update SMAMetric
}
}

0

I recommend trying to run a very simple algorithm when trying new things out. I would start a new project and paste in the SelectionData class. Use a very simple coarse selector, just to prove the SelectionData part is working. The key to debugging systems like this is to work in small pieces :) If you can't get the trimmed down algorithm to work, post it here and I'll take a look. In the meantime, you can email me the pid and I'll see if I can take a look at it this evening for you.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Great idea :-) I'll attempt a simpler study before I bother you with a PID

0

Hey Michael,

Just a quick update; I managed to find some time to take a look into this further. Unfortunately I'm not so bright at this sort of thing, so I apologize in advance.

Attached is a "pared down" coarse universe algorithm that should (I think) log the initialization of every symbol, then log each time that symbol was updated via history.

So far, it's returning the following line each day for all four months of the backtest:

Initializing: A RPTMYV3VC57P

So two problems I see:

1.) The symbol is indecipherable, so I'm fairly certain I'm trying to implicitly ".ToString()" the wrong entity
2.) The update isn't logging, which indicates the history is empty. I believe this to be related to point #1, as we could be passing bogus symbol strings to the algorithm to go find history for.

Hope I'm not too far off base with these assumptions :-P

0


Ok so in the previous example, I was not handling the Symbol very well (passing it around like it was a string, etc.). I corrected it in the code below.

Unfortunately, I'm not able to get much further, as Debug/Log statements that are too iterative are blocked from view (and rightly so, I suppose, else it would flood the system). As a result, I can't see what is going on inside. I DO see that the very first asset is being initialized ($A) for every day, but past that point its a guess.

It's weird, though; every day it initializes $A. I thought the universe is initialized just once at the first day of the backtest. It looks like it's re-initializing each day.

Very confused here...

0


I also just tried to be a little creative by putting Quit() statements in the SelectionData so I could see at least SOMETHING but no luck. The algorithm completely bypassed the Quit() and kept on running as if it didn't even see it...

0

I think I figured it out! Michael, do you think you could validate my findings?

Attached is the quintessential EMA Cross algorithm with some modifications. I note two things:

1.) The queuing time is indeed a few minutes long because it needs to parse a lot of additional data before starting (as expected).
2.) The algorithm begins trading immediately on the first day (awesome!).

Thanks!

0


Awesome algorithm Stephen thanks for sharing. Even though the fees are pretty exorbitant those profits are great.

0

Thanks Travis! It's actually just the EMA Cross example algorithm that they include in the LEAN+ engine, modified to be able to handle history/warmup.

Before this point, I don't think there was a "canned" function to handle warmup in a coarse universe. The modifications in this algo should allow you to do that now :-)

0

So i have this little problem using warmup. I record the closing prices with rollingwindow:

if (b.Time.Hour==15 && b.Time.Minute == 59)
{
    history.Add(b);
    Debug(">>LASTMIN>> " + Time.ToString() +" " + b.Close + " " + history[0].Close + " " + history[1].Close); 
}

And the output would be like this: (algo start date 05/05/2016)

>>LASTMIN>> 05/03/2016 16:00:00 16.52500000000 16.52500000000 15.81000000000>>LASTMIN>> 05/04/2016 16:00:00 16.72500000000 16.72500000000 16.52500000000Algorithm finished warming up.>>LASTMIN>> 05/05/2016 09:30:01 16.3900 16.3900 16.72500000000

So it is recording the opening price as closing price, how can this be? On some start dates this does't happen

0

Hi Rob, If you're using fill forward data, on second resolution (or there's no trades in the first minute for your security), you'll get the price from yesterday filled forward until the first tick of the day. Alot of stocks have surprising gaps at open where there may be no trades for several seconds or minutes.

Please share an algorithm for us to be able to further assist.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Sorry, bad description of the problem from me. The problem is that right after warmup the 

if (b.Time.Hour==15 && b.Time.Minute == 59)

statement is ignored and data is recorded at 09:30:01-09:30:59 and on (and i use minute resolution) Any ideas?

0

forgot to attach algo

0


Hi all,

I am struggeling to get my indicators warmed up. I store indicator data in a dictionary where each symbol has the indicator data stored. 

Using the SetWarmUp method, the algo is warming up but the indicators are not becoming ready until the time has passed, ie SetWarmUp is not pumping data into my indicators. See the log of attached backtest.

Any suggestions are much appreciated!

0


  Hi Thomas there is nothing wrong with your algorithm, the issue is a bug in LEAN and a fix has been submitted for review here:

https://github.com/QuantConnect/Lean/pull/1561
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks Stefano!! SetWarmUp works now as expected

0

Can someone explain to me why this version of CoarseSelect does not load the data for a month delay. I realize it is because the history for the sma_small is defined at 30 days. But I thought that if I placed the history function inside a class that gets fetched by the CoarseSelectionFunction this would permit the warmup to occur prior to launching the first period's data.. I tried to emulate Stephen c# function above but obviously missed something.

 

Appreciate any input.

0


Hi Serge,

i only took a look for 5 minutes.... could you please point the direction or mark the codeline with an X where the problem occurs. THE HISTORY method you created does not get called that is why i dont understand what does not work to warm up. :) :)

take a look at this example. its a more advanced class for the new framework algo but it warms up indicators when a security is new maybe it helps

Line: 126  symbolData.WarmUpIndicators(history.loc[ticker])

 

https://github.com/QuantConnect/Lean/blob/871e99d9960ed25a1db40a0c9469f2f246c8a638/Algorithm.Framework/Portfolio/MeanVarianceOptimizationPortfolioConstructionModel.py
0

Michael,

 

You of course are right there is no History call. My final algo will have a History  called to populate some of the SymbolData attributes, but I did not include it in this sample framework. What confused me in this sample algo is that my universe gets populated with qualifying values once 30 days have passed, corresponding to my 30 day sma functionality. 

I was not sure why. I first thought the sma indicator was doing some kind of magic and spitting out 30 days of results when I fed its "Update" method today's time and price values, EVEN IF IT HAD NOT RECEIVED 30 DAYS OF PRIOR DATA POINTS.. Obviously that cannot be. So I guess the Update method is  failing or returning an empty set - so the returned variable  is evaluating to False until such time as i have passed 30 days of data, and then it returns true. The code link you have sent to me is very useful, and I think I'll be able to get it to work. Essentially, every time the Universe is changed (OnSecuritiesChanged) and a new Security is detected that is not in our SymbolData dictionary, I should first register thei indicator within the main algorithm instance (calling SymbolData's RegisterIndicators function) then run a history search appropriate to the indicator , and pass that to the DataSymbol's WarmupIndicators function, which updates the indicator values for each row of the history tuple you pass it .Did I get that right?If I misunderstood let me know. Otherwise I will try to get this to work and will post the finished code here to pay it forward.Thanks
 
 
0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed