Thanks for the tut. One question, is there a way to get portfolio metrics calculated on a list of actual transactions? Like a csv with date, ticker, buy/sell, price, quantity...
Thanks for the video, I cut and pasted your Strategy file from github into Jupyter notebook and here is what i am getting: TypeError: string indices must be integers Any ideas, how to fix this? thanks!
This probably doesn't work well in a notebook. So I would use something like PyCharm or VS Code. For the error it looks like Yahoo has changed their API (again) and the datareader hasn't caught up. Replace data reader with yfinance: import yfinance as yf then instead of pdr.get_data_yahoo(... use yf.download(... I will update the code. You will probably need to install yfinance
Thanks for sharing. However, I got a question: In your gold fast slow strategy, you short gld when fast below slow and records the negative daily return. Say day 1 the stock goes up 10%, day 2 goes up 10% agian, then long position is (1+10%)*(1+10*) that's correct however, if I short, then my cumulative return is not (1-10%)*(1-10%) it should be somethinglike (1-10%)* (1-12%) I found a lot of tutorials do it this way while I think is wrong, can you shed some light? Thanks!
So you should actually use the natural log of .9 to get the correct answer. You are right the traditional percent change learned in school only works for a single day. Percent change is always more optimistic than the LN, or instantaneous rate of return.
@@MattMacarty thanks! and I think in the last example, the strategy cumulative returns graph is shifted downwards (by the cumulate return of the first 21 days) because strategy starts 21 days later. So the strategy-benchmark comparison is not truly fair as it covers a different time period. I think also the calculation of the slow and fast mean by dataframe.rolling() needs to be shifted by 1, because now the strategy for the current day is calculated based on the closing price from that same day, making the algorithm clairvoyant. (e.g. when the 'fast' mean approaches 1 day the returns increase)