Back

Adding Spread to FX/CFD Data

Hey QC Community,

We've been working hard at QuantConnect to make sure that the historical data you have available for backtesting is accurate. Over the coming weeks, we will be rolling out new data for new securities, as well as upgrades and patches to our existing data set.

We are pleased to announce the first round of upgrades to our data. Starting now, we’ve released updated quote data for FXCM forex data, OANDA forex data and OANDA Cfd data.  This is a major upgrade to our existing data. You now have access to bid/ask spreads for all Forex and CFD data at every resolution. This data is available for backtesting and download via the QuantConnect data library.

These updates should not require any code changes but may result in slightly poorer performance as the trades will incorporate real spread. We are excited to see how the community incorporates this data into your algorithms.

Update Backtest








Congratulations Andrew Hart and also for all QC staff! Must be a huge load of work.

Now some practical questions:

  1. Is the data ready to use right now in the Algorithm lab?
  2. Will the data I already have in my repository be updated automatically or should I make the checkout again?
  3. How the indicators will be updated? I mean, which price (ask/bid) will be used?

Can't wait to try the new data!

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.


Is the data ready to use right now in the Algorithm lab?

> Yes; its already in place. We flipped it over to the new data last night :)

Will the data I already have in my repository be updated automatically or should I make the checkout again?

> Its already in your repository; no need to checkout again. But you will need to download it again.

How the indicators will be updated? I mean, which price (ask/bid) will be used?

1. In LEAN we fake out tradebars (midpoints of the quotes); so all of the existing algorithms OnTradeBars will work.

2. Indicators have been using fake quote bars (bid/ask the same - built from tradebars) for about 3 months now. It took a while to do the full reprocess.

3. You'll notice placing a long/short trade at the same moment in time will now give you 2 different fill prices. Long market orders will be filled at the asking price; short will be filled at the bid. This is handled automatically by the fill models.

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.


Hey JayJayD 

Just building on what Jared wrote.

You can access the QuoteBar data in your algorithm's OnData() method like so.

public override void OnData(Slice data)
{
Debug(data.QuoteBars[_symbol].Ask.Open.ToString());
Debug(data.QuoteBars[_symbol].Ask.High.ToString());
Debug(data.QuoteBars[_symbol].Ask.Low.ToString());
Debug(data.QuoteBars[_symbol].Ask.Close.ToString());

Debug(data.QuoteBars[_symbol].Bid.Open.ToString());
Debug(data.QuoteBars[_symbol].Bid.High.ToString());
Debug(data.QuoteBars[_symbol].Bid.Low.ToString());
Debug(data.QuoteBars[_symbol].Bid.Close.ToString());
}

 

1

Reality Check

Last Friday I shared this algorithm using

AddForex(ticker, market: Market.Oanda);
SetBrokerageModel(BrokerageName.OandaBrokerage);

So, I’ll use that one as base case.

Please check this table*, as Andrew told, the performance with QuoteBars the performance is poorer, and not by a small amount. With same broker, the Net Profit fall from 82% to less than 30% (a 60% less!), the Sharpe Ratio is a 50% smaller, same with almost all indicators.

However, what seems more important to me is the difference in the results between both brokers!

The Net Profit and the Compounding Annual Return are 60% bigger with FXCM, the Sharpe Ratio is 45% higher. Even when the Total Fees are an 11% more expensive with FXCM.

Pretty interesting insights, and I don’t remember who nor when, but someone told in the forums that Oanda is quite expensive.

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.


Interesting thank you JJ - I re-ran your algorithm with OANDA and noticed its reporting fees which should be $0 (OANDA only charges spread). We'll look into why this is and post back here.

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.


It looks like fees are charged only if you call SetBrokerageModel after AddForex, for now if you swap the two lines above fees are zero as expected.

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.


Stefano Raggi, if SetBrokerageModel is above AddForex the Oanda fees are zero, but the FXCM rises 123%! Check this table.

Even with such difference in the fees, the FXCM is still better than Oanda.

 

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 assume this was FX/CFD only, not US equities right? :)

0

:D I wish. LEAN now fully supports quote data -- for any asset class -- so its just a matter of raising $100k to purchase it.

We could crowdfund that and add it to the website if there was enough demand...

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.


Hey everyone,

I've noticed that QC only has data from FXCM/Oanda, and I assume that's for a reason but..

Can we get Interactive brokers FX/CFD data? I would like to trade through them, since their FX commissions are *singificantly* lower, but I'd also like an accurate backtesting model.

I figured since QC supports the brokerage connection, why not get the data too :)

 

 

 

0

Interactive Brokers FX requires high minimums now which put it out of the reach of most retail clients. We won't add it as there aren't enough users who can benefit.

The `SetBrokerageModel(Brokerages.BrokerageName.InteractiveBrokersBrokerage);` is for the fee models only. 

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 Broad ,

based on above comment, can I assume fee modeling should work for FX data (eg FXCM) using IB as brokerage in backtesting? I am searching as to why I always receive 0.00 fees with IB and positive fees using FXCM. What am I missing here? Regarding slippage - is it that there are slippage models with FXCM/Oanda, but not IB then?

Thanks for any hints...

0


Few clients use IB-FX (due to new limits) so this slipped through cracks but it currently defaults to $0; we'll fix that. For now you can use the below code which will be how we'll handle it when its ready. 

Securities["EURUSD"].FeeModel = new InteractiveBrokersFeeModel(decimal monthlyForexTradeAmountInUSDollars = 0, decimal monthlyOptionsTradeAmountInContracts = 0);

You can see this model here:

https://github.com/QuantConnect/Lean/blob/master/Common/Orders/Fees/InteractiveBrokersFeeModel.cs

FXCM is working as expected -- they have a low fee + spread.

OANDA only has a spread -- so it shows up as $0 fee.

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 for that. Will try using it in python

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