# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
from backtesting import Backtest, Strategy
from backtesting.lib import crossover
from backtesting.test import SMA

# +
symbol=input("Enter your company name: ")
df=pd.read_csv(r'C:/Users/Hp/stock analysis/nse_company_datail/'+symbol+".csv")
df.rename(columns = {'Open Price': 'Open', 'High Price': 'High',
                       'Low Price':'Low','Close Price':'Close',
                       'Total Traded Quantity':'Volume'}, inplace =True)
df.index = pd.DatetimeIndex(df['Date'])
class SmaCross(Strategy):
    n1 = 9
    n2 = 26

    def init(self):
        close = self.data.Close
        self.sma1 = self.I(SMA, close, self.n1)
        self.sma2 = self.I(SMA, close, self.n2)

    def next(self):
        if crossover(self.sma1, self.sma2):
            self.buy()
        elif crossover(self.sma2, self.sma1):
            self.sell()


bt = Backtest(df, SmaCross,
              cash=10000, commission=.002,
              exclusive_orders=True)

output = bt.run()
bt.plot()
# -



StarcoderdataJupyterScriptsDedupFiltered