I am having issues to access to quotes from "custom data". Suppose that the `Reader` method has the following content:
def Reader(self, config, line, date, isLiveMode):
local_data = LocalVix()
local_data.Symbol = config.Symbol
local_data.Time = parser.parse(data[self._index['date']])
local_data.EndTime = local_data.Time + timedelta(minutes=1)
local_data.Value = 1
local_data['Close'] = 1
local_data['Open'] = 2
local_data['High'] = 3
local_data['Low'] = 4
local_data['Volume'] 100
return local_data
This demo code works: on OnData(self, data), I can access to the quotes throught data object. Nevertheless I have two issues:
1) I cannot access to the quotes throught self.Securities. The object within self.Securities has the content of local_data.Value. In general I have no problem to access throught the "data" object, but if I access via the scheduler, that object is not present.
The work-arround I have found is access throught self.History. The problem is, despite it is a work-around, self.History is very slow in comparison with accessing self.Securities
2) I had issues setting local_data.Time and local_data.EndTime. Debugging I discover both are the same object (have the same memory pointed). So I cannot set both. I can set one or the other.
Thanks.
Jing Wu
Hi Gabriel, our Quandl custom data implementation assumes that there is a column with the "close" name.
In the CBOE/VIX data, there is a "vix close" column instead. This question is discussed in this post
Gabriel Moncarz
Hi Jing. I guess there was a misunderstanding with my question. I was not using the Quandl module. In fact, to simplify, the quotes are hardcoded in the code and works well. The problem is that despite the data object contains the correct quotes, the self.Securities object doesn't. I need to have the quotes in self.Securities for two reasons; 1) Consistency and 2) Because the data object is not accessable from the Scheduler method.
I would appreciate your help. Thanks.
Jing Wu
If you want to access the data object outside of OnData(self, data), you could set the data object as a global variable and use the self.data in schedule event action function.
OnData(self, data):
self.data = data
Gabriel Moncarz
Thanks Jing. Your answer is right, but hope you understand I want to avoid that code being executed all minutes needlessly.
I guess there is not a way to update self.Securities quote content with the output of the custom data `Reader` method?
Jing Wu
You could. When you trying to use self.Securities to request the price what is the error? could you attach the backtest?
Gabriel Moncarz
This is an example to ilustrate my issue. You can see that calling self.History, I can get the historical quotes, but self.Securities() doesn't contain the open, high and low quotes.
The reason I need to avoid self.History, is because it is very slow and make my backtest hard to run.
Once again, thank you for helping me.
Alexandre Catarino
You can access the last data in the Security object with the GetLastData method:
vix_data = self.Securities['VIX'].GetLastData()
and the attributes can be found by their keys (like they were defined in Reader method):
self.Log('Close=%.2f - Open=%.2f - High=%.02f - Low=%.02f' % ( vix_data['Close'], vix_data['Open'], vix_data['High'], vix_data['Low'], ) )
Note that for OnData, we make this attribute assignment under the hood:
data['Open'] -> data.Open data['Cape'] -> data.Cape data['whatever'] -> data.whatever
Gabriel Moncarz
Hey Alexandre. You answer me very accuratelly. Thanks to you and Jing for the support. In the last months I am learning your API and I have a lot of questions. Your support is incredible usefull for me. Thanks.
Just to avoid asking question innecesarelly next time, how should I find by myself that this specific method exists? I haven't seen any reference to `GetLastData` method in Docs or in Algorithms.Python. Should I look in another place?
Thanks again.
Jing Wu
You could search on this page.
'GetLastData' is one of the public methods of 'Security' Class members.
Gabriel Moncarz
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!