diff --git a/examples/Backtesting_Momentum_Trading_Strategy.ipynb b/examples/Backtesting_Momentum_Trading_Strategy.ipynb
new file mode 100644
index 000000000000..f67624e3f4c4
--- /dev/null
+++ b/examples/Backtesting_Momentum_Trading_Strategy.ipynb
@@ -0,0 +1,585 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": []
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# **Backtesting Momentum Trading Strategies using OpenBB**\n",
+ "\n",
+ "This notebook demonstrates how to perform backtesting of a momentum trading strategy using historical stock price data from OpenBB. A momentum trading strategy involves buying or selling assets based on recent price movements. In this notebook, we will:\n",
+ "- Fetch Historical Stock Data using OpenBB.\n",
+ "- Apply a Momentum Strategy based on moving averages.\n",
+ "- Simulate Trades to backtest the strategy.\n",
+ "- Analyze Performance by comparing the strategy’s returns to a buy-and-hold strategy.\n",
+ "\n",
+ "The goal of the analysis is to test the effectiveness of a momentum-based trading strategy over time and to see how it performs in comparison to a simple buy-and-hold approach.\n",
+ "\n",
+ "Author:
\n",
+ "[Sanchit Mahajan](https://github.com/SanchitMahajan236)\n",
+ "\n",
+ "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1FCMR2oFACCP-YciCcvN5qRnh1r1GypzV?usp=sharing)"
+ ],
+ "metadata": {
+ "id": "K_fd_9baXaH9"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "!pip install openbb -q"
+ ],
+ "metadata": {
+ "id": "9SiXPtRwW_lo"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt\n",
+ "from openbb import obb"
+ ],
+ "metadata": {
+ "id": "J7B1R7s10Bsa"
+ },
+ "execution_count": 3,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "symbols = ['AAPL', 'GOOG', 'MSFT', 'NVDA']\n",
+ "start_date = '2015-01-01'\n",
+ "initial_capital = 10000\n",
+ "short_window = 40\n",
+ "long_window = 100\n",
+ "dataframes = []\n",
+ "\n",
+ "for symbol in symbols:\n",
+ " try:\n",
+ " data = obb.equity.price.historical(\n",
+ " symbol=symbol,\n",
+ " start_date=start_date,\n",
+ " provider=\"yfinance\"\n",
+ " ).to_df()\n",
+ " data['Symbol'] = symbol\n",
+ " dataframes.append(data)\n",
+ " except Exception as e:\n",
+ " print(f\"Failed to fetch data for {symbol}: {str(e)}\")\n",
+ "\n",
+ "combined_data = pd.concat(dataframes)\n",
+ "combined_data = combined_data.reset_index()\n",
+ "\n",
+ "combined_data.head()"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 206
+ },
+ "id": "MrRw8lT_zD11",
+ "outputId": "c5a1b53a-d41c-4c1e-de3b-8acf9aa5c8a1"
+ },
+ "execution_count": 4,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " date open high low close volume \\\n",
+ "0 2015-01-02 27.847500 27.860001 26.837500 27.332500 212818400 \n",
+ "1 2015-01-05 27.072500 27.162500 26.352501 26.562500 257142000 \n",
+ "2 2015-01-06 26.635000 26.857500 26.157499 26.565001 263188400 \n",
+ "3 2015-01-07 26.799999 27.049999 26.674999 26.937500 160423600 \n",
+ "4 2015-01-08 27.307501 28.037500 27.174999 27.972500 237458000 \n",
+ "\n",
+ " split_ratio dividend Symbol \n",
+ "0 0.0 0.0 AAPL \n",
+ "1 0.0 0.0 AAPL \n",
+ "2 0.0 0.0 AAPL \n",
+ "3 0.0 0.0 AAPL \n",
+ "4 0.0 0.0 AAPL "
+ ],
+ "text/html": [
+ "\n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " date | \n",
+ " open | \n",
+ " high | \n",
+ " low | \n",
+ " close | \n",
+ " volume | \n",
+ " split_ratio | \n",
+ " dividend | \n",
+ " Symbol | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 2015-01-02 | \n",
+ " 27.847500 | \n",
+ " 27.860001 | \n",
+ " 26.837500 | \n",
+ " 27.332500 | \n",
+ " 212818400 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " AAPL | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2015-01-05 | \n",
+ " 27.072500 | \n",
+ " 27.162500 | \n",
+ " 26.352501 | \n",
+ " 26.562500 | \n",
+ " 257142000 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " AAPL | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 2015-01-06 | \n",
+ " 26.635000 | \n",
+ " 26.857500 | \n",
+ " 26.157499 | \n",
+ " 26.565001 | \n",
+ " 263188400 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " AAPL | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 2015-01-07 | \n",
+ " 26.799999 | \n",
+ " 27.049999 | \n",
+ " 26.674999 | \n",
+ " 26.937500 | \n",
+ " 160423600 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " AAPL | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2015-01-08 | \n",
+ " 27.307501 | \n",
+ " 28.037500 | \n",
+ " 27.174999 | \n",
+ " 27.972500 | \n",
+ " 237458000 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " AAPL | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "combined_data",
+ "summary": "{\n \"name\": \"combined_data\",\n \"rows\": 9856,\n \"fields\": [\n {\n \"column\": \"date\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": \"2015-01-02\",\n \"max\": \"2024-10-16\",\n \"num_unique_values\": 2464,\n \"samples\": [\n \"2015-06-12\",\n \"2023-12-19\",\n \"2017-10-05\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"open\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 92.76439322887242,\n \"min\": 0.48124998807907104,\n \"max\": 467.0,\n \"num_unique_values\": 9171,\n \"samples\": [\n 161.75999450683594,\n 101.62999725341797,\n 3.7697501182556152\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"high\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 93.61558323171464,\n \"min\": 0.48750001192092896,\n \"max\": 468.3500061035156,\n \"num_unique_values\": 9148,\n \"samples\": [\n 0.6179999709129333,\n 176.02999877929688,\n 41.04349899291992\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"low\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 91.85238328285335,\n \"min\": 0.47350001335144043,\n \"max\": 464.4599914550781,\n \"num_unique_values\": 9219,\n \"samples\": [\n 20.202999114990234,\n 123.8499984741211,\n 28.077499389648438\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"close\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 92.77367356312365,\n \"min\": 0.47850000858306885,\n \"max\": 467.55999755859375,\n \"num_unique_values\": 9239,\n \"samples\": [\n 53.8650016784668,\n 119.83999633789062,\n 93.4625015258789\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"volume\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 225130975,\n \"min\": 6936000,\n \"max\": 3692928000,\n \"num_unique_values\": 9729,\n \"samples\": [\n 70475600,\n 433330000,\n 33122800\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"split_ratio\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.2325276707469507,\n \"min\": 0.0,\n \"max\": 20.0,\n \"num_unique_values\": 5,\n \"samples\": [\n 4.0,\n 10.0,\n 1.0027455\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"dividend\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.03543284237105775,\n \"min\": 0.0,\n \"max\": 0.75,\n \"num_unique_values\": 30,\n \"samples\": [\n 0.00375,\n 0.39,\n 0.002125\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Symbol\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 4,\n \"samples\": [\n \"GOOG\",\n \"NVDA\",\n \"AAPL\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 4
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def momentum_strategy(data, short_window, long_window):\n",
+ " data['Short MA'] = data['close'].rolling(window=short_window, min_periods=1).mean()\n",
+ " data['Long MA'] = data['close'].rolling(window=long_window, min_periods=1).mean()\n",
+ "\n",
+ " data['Signal'] = 0\n",
+ " signal_values = np.where(\n",
+ " data['Short MA'][short_window:] > data['Long MA'][short_window:], 1, -1\n",
+ " )\n",
+ " data.loc[data.index[short_window:], 'Signal'] = signal_values\n",
+ " data['Position'] = data['Signal'].shift(1)\n",
+ "\n",
+ " return data\n",
+ "\n",
+ "def backtest(data, initial_capital):\n",
+ " data['Daily Return'] = data['close'].pct_change()\n",
+ " data['Strategy Return'] = data['Position'] * data['Daily Return']\n",
+ " data['Cumulative Market Return'] = (1 + data['Daily Return']).cumprod()\n",
+ " data['Cumulative Strategy Return'] = (1 + data['Strategy Return']).cumprod()\n",
+ " data['Portfolio Value'] = initial_capital * data['Cumulative Strategy Return']\n",
+ "\n",
+ " return data\n",
+ "\n",
+ "def visualize_backtest(data, symbol):\n",
+ " plt.figure(figsize=(12, 7))\n",
+ "\n",
+ " plt.plot(data['date'], data['Cumulative Market Return'], label='Market Return (Buy & Hold)', color='blue')\n",
+ " plt.plot(data['date'], data['Cumulative Strategy Return'], label='Momentum Strategy Return', color='green')\n",
+ "\n",
+ " plt.title(f'{symbol} Backtest: Momentum Strategy vs Buy & Hold', fontsize=16, fontweight='bold')\n",
+ " plt.xlabel('Date', fontsize=12)\n",
+ " plt.ylabel('Cumulative Return', fontsize=12)\n",
+ " plt.xticks(rotation=45)\n",
+ "\n",
+ " plt.legend()\n",
+ " plt.show()\n",
+ "\n",
+ "for symbol in symbols:\n",
+ " stock_data = combined_data[combined_data['Symbol'] == symbol].copy()\n",
+ "\n",
+ " stock_data = momentum_strategy(stock_data, short_window, long_window)\n",
+ " stock_data = backtest(stock_data, initial_capital)\n",
+ "\n",
+ " visualize_backtest(stock_data, symbol)\n",
+ "\n",
+ " final_portfolio_value = stock_data['Portfolio Value'].iloc[-1]\n",
+ " print(f\"Final portfolio value for {symbol}: ${final_portfolio_value:.2f}\")\n",
+ "\n",
+ " total_market_return = stock_data['Cumulative Market Return'].iloc[-1] - 1\n",
+ " total_strategy_return = stock_data['Cumulative Strategy Return'].iloc[-1] - 1\n",
+ " print(f\"Total market return for {symbol}: {total_market_return * 100:.2f}%\")\n",
+ " print(f\"Total strategy return for {symbol}: {total_strategy_return * 100:.2f}%\")\n",
+ " print(\"=\"*40)\n"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 1000
+ },
+ "id": "ioPlJc67zJuY",
+ "outputId": "c759c73c-35d6-4baa-9865-f013464efc14"
+ },
+ "execution_count": 10,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "