This is a python-based backtesting engine for evaluating stock trading strategies, using historical price data from Yahoo Finance and displaying it in user-friendly graphs. Additionally presents metrics like the % of days in a trade, the Buy and Hold returns of the period, how many trades were made, etc.
- Fetches historical data from Yahoo Finance
- Implements various algorithmic trading strategies
- Simulates capital growth and calculates total returns
- Visualizes signals and price action
- CLI Interaction for selecting strategies and stocks
A simple strategy which buys a stock at a specific date (the start date) and sells it at another specified date (the end date). It's useful for testing other strategies.
This strategy combines a short-term moving average with a long-term moving average. If the short-term moving average is greater than the long-term moving average, this indicates a bullish market, so we buy. If the short-term average is less, we sell.
This is a widley used trading strategy. We once again take two moving averages, a long and a short, and take the moving average of those two moving averages, this gives us the MACD line. Then we take a moving average of the MACD line, this is the signal line.
We can measure if the MACD line is above the Signal line, we want to be in a buy position, if the opposite is true, we want to be in a sell position.
An adjustment of the MACD strategy which includes more trend indicators, such as only buying if the MACD line is negative (undervalued) and the stock is above a 200 day EMA (Uptrend). Often too cautious to be profitable, but good at reducing losses in downtrending markets.
A further adjustment of the cautious MACD which attempts in increase the agressivness of the algorithm. Very profitable in bull markets but very vulnerable in bear markets. Increases the aggression by only selling when the downwards momentum is significant and below the 200 day EMA.
pip install yfinance pandas matplotlib python main.py
Then follow the terminal prompts to input a strategy and run the backtest.
- Python
- Pandas
- Matplotlib
- Algorithmic trading strategy implementation
- Backtesting Methodologies
- Technical Indicators (MA, EMA, MACD, ETC.)
- Historical Market Analysis
- Quantitative Research Methods
- Portfolio Simulation and Capital Compounding
- Signal Generation and Position Management
- Trading Strategies