Back

Multiple custom data import -portfolio creation

Hi,

I have successfully implemented CustomDataNIFTYAlgorithm exemple. No problem with that.

But I am bit lost on how to work with data at portfolio level (temporal sync - day or month sync).

For example, after creating my 'portfolio'

public override void Initialize(){

xxxxx

AddData<Stock1>("Stock1");

AddData<Stock2>("Stock2");

etc...

}

 I would like to implement this pseudo code on scheduled base (day or month sync)

public override void OnEndOfDay()
{
bars_stock1= RetrieveHistory("Stock1", xdays);

bars_stock2= RetrieveHistory("Stock1", xdays);

score1=calculte_MetricXX(bars_stock1); // Custom score , what you want (ROC, quantiles...)

score2=calculte_MetricYY(bars_stock1); // Custom score , what you want

CompareScoreAndSelectXBestScore();

BuyXBetterScore();

}

I don't know how to RetrieveHistory (and correctly synchronized). I am just interessed in  close price (or adjusted close).

In advance thank's for your help.

 

 

 

 

    

Update Backtest








Please checkout the docs, under the Historical Data section:

IEnumerable<TradeBar> bars = History("SPY", 14);

In the Custom Data case, specifically the NIFTY case, you will use:

IEnumerable<Nifty> niftyHistory = History<Nifty>("NIFTY", 10);

The results from both historical data requests can be out of sync, since, by default, AddData does not asks for fill data forward. You can check for match of Time values:

var niftyTime = niftyHistory.Select(x => x.Time);
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.  I am doing wrong since it is not working.

I put 2 breakpoints:

First hit OnData: looks OK

2nd hit: OnEndofDay: bars contains no data (_Count=0)

( I have hit more than 10 times OnEndofDay to be sure )

 

Final  Equity graph looks Ok ( VTI buy&Hold)

0

I have also tried to request without success in OnData method

I can only retrieve one bar (the current bar , ie local data variable)

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