How can we code to backtest our strategy?

3 Views
Tamara Nikolaeva
Answered 6 months, 3 weeks ago
<p id="isPasted">We are going to use this “macd_norm” column to determine how much stock to buy. The thinking is that when the short moving average crosses the long moving average it indicates the stock is increasing in value and we should buy. When the macd_norm is negative, we can short or sell the stock.</p><p>Backtesting code</p><p>Let’s start with $1000.</p><p>To backtest our code, we will create a new column in our dataframe called “position” which is the exact same as our indicator, “macd_norm”. This indicates how many shares we will buy or sell. To visualize our stock trades better, I’ll …</p>
2 Views