I am using lean-cli to do research using US30CFD but can't manage to get the data into my notebook. I managed with SPY following the documentation examples but if I switch to any other symbol it doesn't work. Any help on why is this happening is appreciated. This is the code and the error:
sym = qb.AddCfd("US30USD")
# Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution
h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily)
# Plot closing prices from "US30USD"
h1.loc[ticker]["close"].plot()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2896 try:
-> 2897 return self._engine.get_loc(key)
2898 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'US30USD 5Q'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-69-103814bb4515> in <module>
5
6 # Plot closing prices from "US30USD"
----> 7 h1.loc[ticker]["close"].plot()
none in g(*args, **kwargs)
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexing.py in __getitem__(self, key)
1422
1423 maybe_callable = com.apply_if_callable(key, self.obj)
-> 1424 return self._getitem_axis(maybe_callable, axis=axis)
1425
1426 def _is_scalar_access(self, key: Tuple):
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1848 # fall thru to straight lookup
1849 self._validate_key(key, axis)
-> 1850 return self._get_label(key, axis=axis)
1851
1852
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
158 raise IndexingError("no slices here, handle elsewhere")
159
--> 160 return self.obj._xs(label, axis=axis)
161
162 def _get_loc(self, key: int, axis: int):
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
3733 index = self.index
3734 if isinstance(index, MultiIndex):
-> 3735 loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
3736 else:
3737 loc = self.index.get_loc(key)
none in g(*args, **kwargs)
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/multi.py in get_loc_level(self, key, level, drop_level)
2854 return indexer, maybe_droplevels(indexer, ilevels, drop_level)
2855 else:
-> 2856 indexer = self._get_level_indexer(key, level=level)
2857 return indexer, maybe_droplevels(indexer, [level], drop_level)
2858
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _get_level_indexer(self, key, level, indexer)
2937 else:
2938
-> 2939 code = level_index.get_loc(key)
2940
2941 if level > 0 or self.lexsort_depth == 0:
none in g(*args, **kwargs)
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 return self._engine.get_loc(key)
2898 except KeyError:
-> 2899 return self._engine.get_loc(self._maybe_cast_indexer(key))
2900 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2901 if indexer.ndim > 1 or indexer.size > 1:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'US30USD 5Q'
Derek Melchin
Hi Gustavo,
Only a small sample of the data is available for use locally by default. To get access to more CFD data, we can either add it to our QC account from the Data Explorer or we can use the cloud research environment. The CFD data in our Data Explorer is free. After adding data to our QC account, the data can be downloaded locally by using the CLI. Refer to the docs here.
Best,
Derek Melchin
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.
Gustavo Zarruk
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!