This is the third in my series updating Sentdex's Tutorial for Quantopian 2. It covers parts 8-11 of Sentdex's Tutorial.
If you attempted this part of the tutorial recently, it probably gave you a handful of headaches- I know it gave me a few.
First, I was not able to use the fetcher for the link that he provided- it would stall out every time. So I had to download the data and upload it to my dropbox. I made three different batch sizes: small (about 3 months of data), medium (about a year of data) and large (the full amount that Sentdex uses in the video). Still, I could only get the small and medium to load. If you figure out what's going on please let me know.
Note, if you want to do something similar yourself, take a look at the docs- but you're free to just use the urls posted in the backtest.
Second, two securities were missing from the security list that Sentdex used despite the
set_symbol_lookup_date being set to the same date he used. The symbols were 'ACE' and 'MHFI' and are excluded in the security list below.
Thirdly, and most importantly- Sentdex is wrong about the
Position object. If you are short the asset,
Position.amount will be a negative number. If you want to prove this to yourself, I suggest you set the
initialize and uncomment the
log.info call in
my_record_vars. You will see your proof in the logs.
If your a Quantopian employee- maybe this should be made explicit in the documents even though I know it is very intuitive.
And finally a few things that have been covered before-
- I update
for stock in datato the correct new syntax of
- I update
data[stock].mavg(days)to the correct new syntax of
- I clean up the order logic syntax to be much cleaner
And finally, I am 95% certain he incorrectly uses the
stop_orderlogic. (see my explanation in my post on the second algorithm)
Note, the order logic is much more complicated than the first two algorithms because there are separate, distinct rules for each of entering longs, exiting longs, entering shorts, and exiting shorts. If you have trouble following along in the code, don't hesitate to ask.
|Returns||1 Month||3 Month||6 Month||12 Month|
|Alpha||1 Month||3 Month||6 Month||12 Month|
|Beta||1 Month||3 Month||6 Month||12 Month|
|Sharpe||1 Month||3 Month||6 Month||12 Month|
|Sortino||1 Month||3 Month||6 Month||12 Month|
|Volatility||1 Month||3 Month||6 Month||12 Month|
|Max Drawdown||1 Month||3 Month||6 Month||12 Month|