Hello,
Q1) I run the algorithm on daily time frame and put a 16 hours of prediction Interval. The expiry time gets a value of 16:00 tomorrow, although the day ends at 19:00. Why does expiry assume the day ends at 23:59:59? Are the time zone in backtesting increments and the expiry calculation time zone different?
https://www.quantconnect.com/backtest/56893/2024477/eb73594ea98477e25d0cfeff74fabe99-log.txt
Q2) When the insight is added on Friday, the expiry time gets assigned 14:00 next Monday. I assume 2 hours is subtracted because market opens at GMT 22:00 on Sunday. There is a little, problem here. Although the day is just 2 hours, the portfolio construction model sends the targets to the execution coming from Friday's insights. (I tried to have a model that sends targets of the insights until expiration). Then although my insight expire 16 market-hours later, the behaviour is like that it expires 2 days later. Hence, I have a target on Monday that should have been expired 1-2 days ago at weekend.
Best,
Atacan
Jack Simonson
Hi Atacan,
To answer your first question, the insight expiry time is calculated by taking the generated time and then adding the period. Since Forex markets are open 24-hours per day for Monday-Thursday (00:00 UTC - 23:59:59 UTC), 00:00 UTC - 17:00 UTC Fridays, closed Saturdays, and 17:00 UTC - 23:59:59 UTC on Sunday. As such, the insights are generated at 00:00 UTC and so they will expire at 16:00 UTC. You can find more information in the documentation here.
The answer to your second question is that the insight generation is done at 00:00 UTC on Saturday, but since the market open is actualy 17:00 UTC on Sunday, then the 16 hour period means that the insight will expire at 14:00 UTC Monday.
Jake Mitchell
I am trying to develop an alpha that emits insights for certain timeframes (H, D, W, M, Y) on every bar (hourly data, so each timeframe emits an insight per hour for its respective period).
I hadn't noticed that a lot of the insights' "close-at" timestamp were off by a lot due to this very issue. I was setting the insight period to be the time delta between the algo's time and the expected final timestamp.
For those of us who know the actual timestamp we want to predict for, how should we go about determining the period to pass into the insight initializer?
Alexandre Catarino
Hi Jake,
The Insight constructor has an overload with a date/time argument that can be used to determine the exact time of insight expiration:
insight = Insight.Price("IBM", datetime(2020, 5, 27, 10, 0, 0), InsightDirection.Up)
For the sake of completeness, we can also use the Expiry helper:
insight = Insight.Price("IBM", Expiry.EndOfMonth, InsightDirection.Up)
and the Resolution + bar count:
# 5 hourly-bar periods. Different of 5 hours, since exclude the period the market is closed insight = Insight.Price("IBM", Resolution.Hour, 5, InsightDirection.Up)
Jake Mitchell
Thanks Alexandre, that helped. One more thing regarding insights...the magnitude. Should it be an absolute value or should it have a sign? None of the tutorials/documentation explicitly mention it and so I can only conclude by my own logical reasoning that it should be absolute; though I've read elsewhere in the community to use negative values when the expected value is lower. When I use negative values, my insights report shows negative score...which doesn't make sense. Also going off of Jack's example using stdev I should also conclude to use absolute values.
Derek Melchin
Hi Jake,
The insight magnitude should be signed. We demonstrate this in the attached backtest. We short AAPL for the first 20 minutes on 5-22-2020. The price of AAPL decreases during this time. When assigning a magnitude of 0.3, the magnitude score is 0. When assigning a magnitude of -0.3, the magnitude score is positive.
Can you attach a backtest which produces a negative magnitude score? This may be a bug.
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.
Jake Mitchell
Hi Derek,
I've submitted a support ticket regarding this. Basically the magnitude score stays above 0% in the Alpha window during/after backtesting, but it's all over the place (positive and negative) in the list of insights after backtesting completes.
Jake Mitchell
Also, what does the insight base its original price value on? I project my values based on the current close, but I checked the insights report and the values seem to be different from the close of a given period (Reference value).
Alexandre Catarino
Hi Jake Mitchell ,
Sorry about the wait.
In the Insights Tab, the column labeled with "Magnitude Score" should read "Magnitude". It's a bug that we will fix as soon as possible.
The way how magnitude score is calculated is pretty simple. Here is the formula:
var delta = currentValue - startingValue; var percentChange = delta / startingValue; var predictedPercentChange = insight.Magnitude.Value; var score = (double) percentChange / predictedPercentChange;
Negative scores are set to zero.
We can download the insight information by clicking on the link at the Insight Tab. Here is one serialized Insight object:
"id": "5d10d1d2f7cb4c87af04a8333595daac", "group-id": null, "source-model": "ConstantAlphaModel(Price,Up,00:20:00,-0.025)", "generated-time": 1381519860, "created-time": 1381519860, "close-time": 1381521060, "symbol": "SPY R735QTJ8XC9X", "ticker": "SPY", "type": "price", "reference": 149.416419536, "reference-final": 149.188007794, "direction": "up", "period": 1200, "magnitude": -0.025, "confidence": null, "weight": null, "score-final": true, "score-magnitude": 0.0611, "score-direction": 0, "estimated-value": -1275.3073
Using the formula, we have:
delta = 149.188007794 - 149.416419536 = -0.22841174200002; percentChange = -0.22841174200002 / 149.416419536 = -0.001528692380056578 predictedPercentChange = -0.025; score = -0.001528692380056578 / -0.025 = 0.06114769520226311; "score-magnitude": 0.0611,
The original reference price value is set by the algorithm after the insight is emitted by AlphaModel.Update with Security.Price as well as the final reference when the insight expires.Â
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!