Im out of ideas regarding how to find out which crypto currencies which have performed a) best b) worst for each week.
i have gathered all relevant currencies in the df dataframe, now i want to know which currencies performed the best and worst las week.
Does anyone have any ideas?
Douglas Stridsberg
Hey, looks like you're 95% of the way there.. Just query the last row of the dataframe and sort its values in descending order.
Davidii111
Thanks.Â
last_week = df.iloc[-1].sort_values(ascending=False)
Â
Davidii111
I am trying to put this code in my algo.
https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_82ba8301d26fbe9d4ea2e8f77df98ae0.htmlÂ
Gives me this error:
59 | 10:09:16:
BacktestingRealTimeHandler.Run(): There was an error in a scheduled event WeekStart: 12. The error was KeyError : 'the label [BTCUSD] is not in the [index]'
60 | 10:09:16:
Request for future history modified to end now.
61 | 10:09:25:
Runtime Error: In Scheduled Event 'WeekStart: 12', Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception. To prevent the exception, ensure that the BTCUSD key exist in the collection and/or that collection is not empty. KeyError : 'the label [BTCUSD] is not in the [index]' (Open Stacktrace)
62 | 10:09:26:
Algorithm Id:(82ba8301d26fbe9d4ea2e8f77df98ae0) completed in 10.53 seconds at 0k data points per second. Processing total of 442 data points.
63 | 10:09:27:
Backtest deployed in 24.707 seconds
64 | 10:09:28:
Your log was successfully created and can be retrieved from: https://www.quantconnect.com/backtest/45575/2466760/82ba8301d26fbe9d4ea2e8f77df98ae0-log.txt
65 | 10:09:54:
API Error Message: Insights not found
Â
Why is it working in research but not in algo?
Davidii111
Ok, i got the algo running and also learned how to attach it here, sorry for my reply above.
It seems like the self.History requests is not working very well.
# Working h1 = self.History(tickers, timedelta(30), Resolution.Daily) # Not working h2 = self.History(self.Securities.Keys, start, end, Resolution.Daily) h3 = self.History(timedelta(30), Resolution.Daily)
Why does not h2 and h3 work?
Davidii111
Any experts around?
Jack Simonson
Hi David,
The reason H3 isn't working is that there is no Symbol specified for the history request. Adding the Symbols requested is why H1 works and not H3. As for H2, the reason that isn't working is due to the fact that the history request is for current/future data according to the algorithm. Historical data can only be requested for periods before and up-to-the-time at which the algorithm makes the history request. I've attached a backtest below that demonstrates how these different history requests work and will change as the algorithm moves forward in time.
Halldor Andersen
Hi David.
Jack is correct but I'll give you my two cents on it as well.
1. The reason why h2 does not work:In the method Initialize() you set the start date and the end date:
# In Inititalize()
self.SetStartDate(2018, 10, 1) # Set Start Date
self.SetEndDate(2018, 12, 31) # Set End Date
In rebalance() you define the same start and end date for the history call as in the method Initialize():
# In rebalance()
start = datetime(2018, 10, 1)
end = datetime(2018, 12, 31)
It is only possible to retrieve history for past dates at each point in time when running a backtest. If you shift the start and end date by one year, using previous year instead:
# In rebalance()
start = datetime(2017, 10, 1)
end = datetime(2017, 12, 31)
Then, the DataFrame is no longer empty. I've attached a backtest where I demonstrate the above, using your code as a template.
2. The reason why h3 does not work: The History() method requires symbol specification as an input, using either a list, which will return a DataFrame or by using a symbol string, which will return a TradeBar. This difference is the reason why h1 works and h3 does not work.
Check out this documentation on Historical Data for further information.
Davidii111
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!