Hi, just new to QC and had some questions.
When I set the daily resolution for my indicators, I got different indicator value with minute/daily security resolutions. following is my code:
class MyAlgor(QCAlgorithm):
def Initialize(self):
# configurable params
self.baseFX = 'EUR'
self.quoteFX = 'GBP'
self.atrPeriod = 14
self.fastPeriod = 50
# set brokerage model / account type / cash
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.SetCash(10000)
# start and end dates for the backtest
self.SetTimeZone("UTC")
self.SetStartDate(2020, 7, 1)
self.SetEndDate(2020, 7, 2)
# add currency pair
self.fx = self.baseFX + self.quoteFX
self.AddForex(self.fx, Resolution.Daily, market=Market.Oanda)
self.fxClose = None
# schedule event 60 mins after market open
self.Schedule.On(
self.DateRules.EveryDay(self.fx),
self.TimeRules.AfterMarketOpen(self.fx, 60),
self.EveryDayAfterMarketOpen
)
# add indicators and warmup period
self.atr = self.ATR(
self.fx,
self.atrPeriod,
resolution=Resolution.Daily
)
self.fastEMA = self.EMA(
self.fx,
self.fastPeriod,
resolution=Resolution.Daily
)
self.SetWarmUp(
max(
self.atrPeriod,
self.fastPeriod,
),
resolution=Resolution.Daily
)
def OnData(self, data):
pass
def EveryDayAfterMarketOpen(self):
if self.IsWarmingUp:
return
atr = self.atr.Current.Value
fastEMA = self.fastEMA.Current.Value
self.Debug(f"{self.Time} atr {self.atr.Current.Value:,.4f}")
self.Debug(f"{self.Time} fast ema {self.fastEMA.Current.Value:,.4f}")
when adding security with daily resolution, I got the following values
2020-07-01 05:00:00 atr 0.0060
2020-07-01 05:00:00 fast ema 0.8958
then I changed the security resolution to minute
self.AddForex(self.fx, Resolution.Minute, market=Market.Oanda)
2020-07-02 05:00:00 atr 0.0000
2020-07-02 05:00:00 fast ema 0.9017
just wondering that why I got quite different results even I did not change the resolution of any indicators?
Weiyan chen1
typo fixed:
2020-07-02 05:00:00 atr 0.0000
2020-07-02 05:00:00 fast ema 0.9017
should be
2020-07-01 05:00:00 atr 0.00012020-07-01 05:00:00 fast ema 0.9074
Â
Derek Melchin
Hi Weiyan-chen,
There are two reasons for the differing results.
(1) We do not support named arguments. Therefore,
self.EMA(self.symbol, self.fastPeriod, resolution=Resolution.Daily)
needs to be
self.EMA(self.symbol, self.fastPeriod, Resolution.Daily)
However, there seems to be a bug in LEAN when initializing indicators to a daily resolution while subscribing to different symbol resolutions. I've created a GitHub Issue to have this resolved. Track our progress here.
(2) The daily ending price used to update the indicators seems to change when we use intraday or daily resolution for this forex pair. See the attached backtest logs for reference. I've also referenced this issue in the GitHub Issue linked to above.
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.
Weiyan chen1
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!