Stock trading analytics and optimization with PyFolio and R's PerformanceAnalytics (blog post)
-
I've written a new blog post on using backtrader. In this article, I discuss performance analytics using backtrader
Analyzer
s, writing customAnalyzer
s, using R PerformanceAnalytics functions in backtraderAnalyzer
s, and PyFolio. I also took my walk forward analysis code and turned it into a function, for easier use.I would love to hear feedback.
-
I attempted to use another analyzer,
AnnualReturn
, which computes annualized return metrics, but unfortunately it does not seem to work.This analyzer should be removed. It was the 1st ever implementation and was never really reworked because
TimeReturn
(which allows customization of thetimeframe
independently of the data's actualtimeframe
) took over.Noted.
class VaR(bt.Analyzer): """ Computes the value at risk metric for the whole account using the strategy, based on the R package PerformanceAnalytics VaR function """ ...
Here the proposal would be to create an
Indicator
first and then use the indicator inside the analyzer. The advantage is that you can plug the indicator directly into theStrategy
, in anObserver
or in anAnalyzer
.This is how it is actually done with the non-public
ValueAtRisk
indicator which is used for the management of the Morningstar - Backtrader FundIt's not a must, not a canonical way. It' simply handy.
For some reason, create_full_tear_sheet() does not seem to be aware of other symbols being traded than Nvidia (NVDA). I have no idea why.
PyFolio
is a moving target. You may in any case try:create_position_tear_sheet
rather thancreate_full...
I recently read a response to a Quora question, written by Prof. Ben Y. Zhao at the University of Chicago that rattled me.
Don't let yourself be bothered by someone who probably only speaks about one single thing at every social event and who only sees peers in those with a PhD an his level of focus in a single topic. This may be wrong and he may be the soul of every party, run marathons every weekend and attend charity events on Tuesdays. Even in that case, don't let yourself be bothered.
Long story short, time is an even scarcer commodity now than it used to be for me. I’m worried about my academic success if I keep burning time like this. It also doesn’t seem like any of my new content “sticks” (it doesn’t bump up what you might call my “latent” viewership rate).
Thus, I’m planning on this being my last “long-form” article for some time
Time is scarce everywhere. Shorter posts will free up some time and you'll probably keep on enjoying your own posting.
-
@backtrader said in Stock trading analytics and optimization with PyFolio and R's PerformanceAnalytics (blog post):
This analyzer should be removed. It was the 1st ever implementation and was never really reworked because
TimeReturn
(which allows customization of thetimeframe
independently of the data's actualtimeframe
) took over.Noted.
Here the proposal would be to create an
Indicator
first and then use the indicator inside the analyzer. The advantage is that you can plug the indicator directly into theStrategy
, in anObserver
or in anAnalyzer
.I knew there had to be a better way than what I was doing. Thanks!
Don't let yourself be bothered by someone who probably only speaks about one single thing at every social event and who only sees peers in those with a PhD an his level of focus in a single topic. This may be wrong and he may be the soul of every party, run marathons every weekend and attend charity events on Tuesdays. Even in that case, don't let yourself be bothered.
Time is scarce everywhere. Shorter posts will free up some time and you'll probably keep on enjoying your own posting.
Thanks for the words of encouragement! I'm going to try to keep up the blog but not make an effort to be regular about my posts. That is too much of a commitment. Anyway, I appreciate the thought.