folder_path = Path().absolute().joinpath("Data/Stock prices CSV") nifty_path = Path().absolute().joinpath("Data/price_Data/Nifty Index.csv") nifty_data = my_funcs.reading_price_data_from_csv(nifty_path) universal_dates = nifty_data.index monthly_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="M") annual_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="Y") price_data = my_funcs.import_all_price_data_from_csv_files(folder_path) symbols = price_data.keys() initial_capital = 1000000 trading_cost = 0.0000 trade_summary_data = pd.DataFrame(columns=[ "Total Trades", "Profit Factor", "Total Profit", "Average Profit", "Max Profit", "Min Profit", "Average Duration", "Hit Ratio", "Profitability", "Max DD in Trade", "Max Profit in Trade", "Max Loss in Trade", "Max Recovery in Trade", "Max DD Duration in Trade" ]) trades_table = {} trades_12m_rolling_summary = {}
portfolio_start_date = datetime.datetime(2010, 12, 1) portfolio_end_date = datetime.datetime(2022, 2, 28) nifty_data = my_funcs.reading_price_data_from_csv(nifty_price_data_path) universal_dates = nifty_data.index[ (nifty_data.index > portfolio_start_date) & (nifty_data.index <= portfolio_end_date)] monthly_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="M") annual_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="Y") cash_price_data = my_funcs.import_all_price_data_from_csv_files( cash_data_folder_path) cash_symbol_data_list = pd.Series(cash_price_data.keys()) futures_1_price_data = my_funcs.import_all_price_data_from_csv_files( futures_1_data_folder_path) futures_1_symbol_data_list = pd.Series(futures_1_price_data.keys()) expiry_days = pd.read_csv(expiry_days_path) expiry_days = pd.to_datetime(expiry_days["Expiry days"]) expiry_days = expiry_days[expiry_days.between(portfolio_start_date, portfolio_end_date)] universe_stocks = pd.read_csv(universe_stocks_path) buy_portfolio, sell_portfolio, daily_universe_portfolios, daily_universe = creating_portfolio( cash_price_data, nifty_data, universe_stocks, expiry_days, universal_dates)
portfolio_strategy = "SML" current_folder_path = Path().absolute().joinpath("Data") data_folder_path_cash = Path().absolute().joinpath("Data/Cash prices CSV") data_folder_path_futures2 = Path().absolute().joinpath( "Data/New Futures prices series2 CSV") nifty_price_data_path = Path().absolute().joinpath( "Data/Price_Data/Nz1 Index.csv") expiry_days_path = current_folder_path / "Expiry days.csv" buy_trade_file = current_folder_path / "Portfolio_construction/SML/SML_buy_trades.csv" sell_trade_file = current_folder_path / "Portfolio_construction/SML/SML_sell_trades.csv" nifty_data = my_funcs.reading_price_data_from_csv(nifty_price_data_path) universal_dates = nifty_data.index price_data = my_funcs.import_all_price_data_from_csv_files( data_folder_path_cash) price_data_futures2 = my_funcs.import_all_price_data_from_csv_files( data_folder_path_futures2) symbols_data = price_data.keys() monthly_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="M") annual_index = pd.date_range(universal_dates[0], universal_dates[-1], freq="Y") buy_trades = pd.read_csv(buy_trade_file) buy_trades.set_index("Dates", inplace=True) buy_trades.index = pd.to_datetime(buy_trades.index)