Any idea on how to fix this, still new to this platform.
Runtime Error: 'EURJPY' wasn't found in the Slice 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("EURJPY") (Open Stacktrace)
Garret Fields
I am trying to pass the tick data for three currency pairs to the event handler. I've added this to my initialization:
AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick, true);
AddSecurity(SecurityType.Forex, "EURJPY", Resolution.Tick, true);
AddSecurity(SecurityType.Forex, "USDJPY", Resolution.Tick, true);
Gurumeher Sawhney
It would be easier to solve this issue if there was an algorithm attached. The securities are added in the correct manner when running a simple subscription test the data is being correctly fed into OnData(). I suggest using data.ContainsKey("EURJPY") in order to determine when this issue exists. Logging and debugging are helpful tools for situations like this.
Garret Fields
Hi, thanks for the reply. I have sorted out this issue but unfortunately have run in to another issue. All I'm trying to do is perform some simple mathematical operations on the exchange rates. So for example, how would I subtract the value of two different exchange rates. At the moment, all I can find in the documentation to call the tick data is data["EURJPY"] but of course you cannot do something like data["EURJPY"]-data["EURUSD"] or data["EURJPY"-"EURUSD"] because these are strings and lists. But what I am trying to do is simply define a placeholder like...
double differencePrice = data["EURJPY"]-data["EURUSD"] (of course I know you cannot do this)
I have in the initialization it set to tick data, and so on each tick I need it to store this value (something similar actually) so that I can perform mathematical operations on it. To crystalize what I'm trying to do:
Each time there is a new tick, I want to assign the difference to a variable for later use in the algo.
THanks
SLPAdvisory
I believe you can do var Difference = data["EURJPY"].Close - data["EURUSD"].Close;
Garret Fields
This is what happens:
namespace QuantConnect
{
/*
* OANDA/QuantConnect Basic Template:
* Fundamentals to using a QuantConnect algorithm.
*
* You can view the QCAlgorithm base class on Github:
* https://github.com/QuantConnect/Lean/tree/master/Algorithm
*/
public class BasicTemplateAlgorithm : QCAlgorithm
{
//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
// Code Automatically Generated
// Date range for your backtest
// In live trading these are ignored.
SetStartDate(2017, 1, 1);
SetEndDate(2018, 1, 1);
// Set cash allocation for backtest
// In live trading this is ignored and your real account is used.
SetCash(5000);
// Specify the OANDA Brokerage: This gives lets us know the fee models & data.
SetBrokerageModel(BrokerageName.OandaBrokerage);
//Add as many securities as you like. All the data will be passed into the event handler:
AddSecurity(SecurityType.Forex, "EURUSD", Resolution.Tick, true);
AddSecurity(SecurityType.Forex, "EURJPY", Resolution.Tick, true);
AddSecurity(SecurityType.Forex, "USDJPY", Resolution.Tick, true);
}
// Event handler for the price events
public override void OnData(Slice data)
{
if (!data.ContainsKey("EURJPY")) return;
if (!data.ContainsKey("EURUSD")) return;
if (!data.ContainsKey("USDJPY")) return;
double TheoreticalUSDJPY = data["EURJPY"].Close/data["EURUSD"].Close;
double TheoreticalEURUSD = data["EURJPY"].Close/data["USDJPY"].Close;
double TheoreticalEURJPY = data["EURUSD"].Close*data["USDJPY"].Close;
double MispricingUSDJPY = TheoreticalUSDJPY-data["USDJPY"].Close;
double MispricingEURUSD = TheoreticalEURUSD-data["EURUSD"].Close;
double MispricingEURJPY = TheoreticalEURJPY-data["EURJPY"].Close;
Debug(MispricingUSDJPY);
}
}
}
and i get the error:
Runtime Error: 'System.Collections.Generic.List<QuantConnect.Data.Market.Tick>' does not contain a definition for 'Close' (Open Stacktrace)
Garret Fields
Ok, I got it to work, but I had to use the seconds resolution instead of the "tick". If you find any ways to use the tick data that would be awesome, thanks again for all input/replys.
Garret Fields
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!