PyQuant News 🐍
PyQuant News 🐍

@pyquantnews

11 Tweets 5 reads Mar 08, 2024
Nobody taught me how to backtest a trading strategy.
So I read all the books and blogs.
Then, I distilled what I learned into a simple step-by-step guide.
But unlike a 300-page book, this won't take you 1 month to read (or cost you $150).
Here it is in 2 minutes (free):
But first, what’s a backtest?
• Tests trading ideas against historic market data
• Is used to check the robustness of trading strategies
• Is a simulation of how a strategy might have performed in the market
Let’s backtest a successful trading strategy with VectorBT:
Fund managers report their holdings every month. They don’t want to tell investors that they lost money the latest meme stock. So they will sell the meme stocks and buy higher quality assets, like bonds.
Let’s see if we can make money from this.
We’re going to use the ETF TLT as a proxy for bonds. We’ll use VectorBT to get 10 years of data in 1 line of code. But first the imports.
VectorBT has a built in data downloader. We’ll download the data and grab the closing prices.
This code creates pandas Series of the same shape as the Series with our closing prices. Next we’ll generate the trading signals based on the day of the month.
We expect there to be positive returns, on average, toward the end of the month.
We expect to see negative returns, on average, toward the beginning of the month.
Fund managers dump their high quality assets and go back to buying meme stocks.
VectorBT makes it simple to run sophisticated backtests.
Here we assume trades at the closing prices.
Once we run the backtest, we get a nice summary of the results.
The results are promising. Over 5,060 trading days, the strategy trades 483 times.
It has total returns of 502% compared to a buy and hold of TLT with a 112% return.
The strategy has a reasonable max drawdown of 21%, a win rate of 59%, and Sharpe ratio of 1.1.
VectorBT makes it easy to optimize strategies in a rigorous way using walk forward optimization.
You’ll want to avoid overfitting so you can run a walk forward optimization to make sure the out of sample results are statistically signifiant.
Everything you need to start using Python for algorithmic trading (FREE).
Here's what you get:
• ChatGPT prompting frameworks
• Real quant code to backtest strategies
• Step-by-step code to automate trades
• And loads more...
7 days. Big results.
pythonforquantfinancemasterclass.com

Loading suggestions...