Beispiel #1
0
        pnl_series_annual[symbol] = pnl_series[symbol].resample("Y").sum()
        #pnl_series_annual[symbol]["DD"], *_ = pg.DD_sum(pnl_series_annual[symbol]["PNL"].cumsum(), 1)

    #trades_table_csv = my_funcs.convert_datetime(trades_table)
    #trades_table_csv.to_csv("Trade Data.csv", index=True)

    #DD_distribution=pd.DataFrame(DD_distribution)
    pnl_series = pd.DataFrame(pnl_series, index=universal_dates)
    pnl_series.fillna(0, inplace=True)

    pnl_series_monthly = pd.DataFrame(pnl_series_monthly, index=monthly_index)
    pnl_series_monthly.fillna(0, inplace=True)
    pnl_series_annual = pd.DataFrame(pnl_series_annual, index=annual_index)
    pnl_series_annual.fillna(0, inplace=True)

    #trades_table_csv.name = "trades_table_csv"
    trade_summary_data.name = "trade_summary_data"
    pnl_series.name = "pnl_series"
    pnl_series_monthly.name = "pnl_series_monthly"
    pnl_series_annual.name = "pnl_series_annual"
    #DD_distribution.name = "DD_distribution"

    to_be_saved_as_csv = [
        trade_summary_data, pnl_series, pnl_series_monthly, pnl_series_annual
    ]

    output_folder = system_name + "/" + underlying

    #my_funcs.csv_creation(to_be_saved_as_csv, "Results/"+output_folder)
    my_funcs.excel_creation(to_be_saved_as_csv, "Results/" + output_folder,
                            underlying)
    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)

    buy_portfolio.name = "Buy Portfolio"
    sell_portfolio.name = "Sell Portfolio"
    daily_universe.name = "Daily Returns"
    daily_universe_portfolios.name = "Daily Universe"

    to_be_saved_as_file = [
        buy_portfolio, sell_portfolio, daily_universe,
        daily_universe_portfolios
    ]
    my_funcs.excel_creation(to_be_saved_as_file, "Portfolio Results/DailyMR",
                            "DailyMR Results")
                                 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, monthly_universe_portfolios, RSC_universe = creating_portfolio(
        cash_price_data, universe_stocks, expiry_days, universal_dates, 10)

    buy_portfolio.name = "Buy Portfolio"
    sell_portfolio.name = "Sell Portfolio"
    RSC_universe.name = "RSC reversion"
    monthly_universe_portfolios.name = "Monthly Universe"

    to_be_saved_as_file = [
        buy_portfolio, sell_portfolio, RSC_universe,
        monthly_universe_portfolios
    ]
    my_funcs.excel_creation(to_be_saved_as_file,
                            "Portfolio Results/RSC reversion", "RSC_Nifty")
        index="Trade ID")

    pnl_series_monthly = pd.DataFrame(columns=["PNL", "DD"])
    pnl_series_annual = pd.DataFrame(columns=["PNL", "DD"])

    pnl_series_monthly["PNL"] = pnl_series["Cumulative PNL%"].resample(
        "M").sum()
    pnl_series_monthly["DD"], *_ = pg.DD_sum(
        pnl_series_monthly["PNL"].cumsum(), 1)

    pnl_series_monthly["_rolling_12m"] = pnl_series_monthly["PNL"].rolling(
        12).sum()
    pnl_series_monthly["_rolling_12m"].fillna(0, inplace=True)

    pnl_series_annual["PNL"] = pnl_series["Cumulative PNL%"].resample(
        "Y").sum()
    pnl_series_annual["DD"], *_ = pg.DD_sum(pnl_series_annual["PNL"].cumsum(),
                                            1)

    pnl_series_monthly.name = "Monthly PNL"
    pnl_series.name = "PNL Series New"
    DD_distribution.name = "DD Data"
    trade_data.name = "Sample Trade Data"

    to_be_saved_as_csv = [
        pnl_series_monthly, pnl_series, DD_distribution, trade_data
    ]

    my_funcs.excel_creation(to_be_saved_as_csv, underlying_name, "trial.xlsx")
    my_funcs.csv_creation(to_be_saved_as_csv, underlying_name)
            trade_register = creating_individual_trade_db.creating_individual_trade_db(
                trade_list_to_pass)

            pnl_series_1, _ = pg.pnl_timeseries_multiple_strategy_trade(
                trade_register, price_data, universal_dates, baseamount)

            pnl_series_strategy[strategy] = pnl_series_1["Daily PNL"]
            gross_exposure_strategy[strategy] = pnl_series_1["Gross Exposure"]
            net_exposure_strategy[strategy] = pnl_series_1["EOD Net Exposure"]

        pnl_series_strategy["Total"] = pnl_series_strategy.sum(axis=1)
        pnl_series_strategy.loc["Total"] = pnl_series_strategy.sum(axis=0)

        gross_exposure_strategy["Total"] = gross_exposure_strategy.sum(axis=1)
        net_exposure_strategy["Total"] = net_exposure_strategy.sum(axis=1)

        pnl_series[account] = [
            pnl_series_strategy, gross_exposure_strategy, net_exposure_strategy
        ]

    for account in account_list:
        pnl_series[account][0].name = "PNL Series " + account
        pnl_series[account][1].name = "Gross exposure Series " + account
        pnl_series[account][2].name = "Net exposure Series " + account
        to_be_saved_as_csv = [
            pnl_series[account][0], pnl_series[account][1],
            pnl_series[account][2]
        ]

        my_funcs.excel_creation(to_be_saved_as_csv, "Pro_Alpha_PNL", account)
    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, monthly_universe_portfolios, RSI_universe = creating_portfolio(
        cash_price_data,
        universe_stocks,
        expiry_days,
        universal_dates,
        period=90)

    buy_portfolio.name = "Buy Portfolio"
    sell_portfolio.name = "Sell Portfolio"
    RSI_universe.name = "D90_vol"
    monthly_universe_portfolios.name = "Monthly Universe"

    to_be_saved_as_file = [
        buy_portfolio, sell_portfolio, RSI_universe,
        monthly_universe_portfolios
    ]
    my_funcs.excel_creation(to_be_saved_as_file, "Portfolio Results/D90_Vol",
                            "D90_volatility_Nifty")
    pnl_series_monthly_rolling_12m = pnl_series_monthly["PNL"].rolling(
        12).sum()
    pnl_series_monthly_rolling_12m.fillna(0, inplace=True)

    pnl_series_annual["PNL"] = pnl_series["%PNL"].resample("Y").sum()
    pnl_series_annual["DD"], *_ = pg.DD_sum(pnl_series_annual["PNL"].cumsum(),
                                            1)

    trades_table_csv = my_funcs.convert_datetime(trades_table)

    price_signal.name = "price_signal"
    trades_table_csv.name = "trades_table"
    trade_summary_data.name = "trade_summary_data"
    pnl_series.name = "pnl_series"
    pnl_series_monthly.name = "pnl_series_monthly"
    pnl_series_annual.name = "pnl_series_annual"
    DD_distribution.name = "DD_distribution"
    trades_12m_rolling_summary.name = "Rolling 12 month analysis"
    walk_forward_annual_summary.name = "Walk forward analysis"

    Dataframes_to_be_saved_as_csv = [
        price_signal, trades_table, trade_summary_data, pnl_series,
        pnl_series_monthly, pnl_series_annual, DD_distribution,
        trades_12m_rolling_summary, walk_forward_annual_summary
    ]

    #my_funcs.csv_creation(Dataframes_to_be_saved_as_csv, underlying_name)
    my_funcs.excel_creation(Dataframes_to_be_saved_as_csv, underlying_name,
                            symbol)
    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, monthly_universe_portfolios, sign_momentum_universe = creating_portfolio(
        cash_price_data, universe_stocks, expiry_days, universal_dates)

    buy_portfolio.name = "Buy Portfolio"
    sell_portfolio.name = "Sell Portfolio"
    sign_momentum_universe.name = "sign momentum returns"
    monthly_universe_portfolios.name = "Monthly Universe"

    to_be_saved_as_file = [
        buy_portfolio, sell_portfolio, sign_momentum_universe,
        monthly_universe_portfolios
    ]
    my_funcs.excel_creation(to_be_saved_as_file,
                            "Portfolio Results/sign Momentum",
                            "sign_Momentum_Nifty")
Beispiel #9
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)
    universe_sector_data = pd.read_csv(universe_sector_path)
    sectors = ["IT", "Energy", "Financial", "Pharma", "Consumer"]

    buy_portfolio, sell_portfolio = creating_portfolio(
        cash_price_data, nifty_data, universe_stocks, expiry_days,
        universal_dates, universe_sector_data, sectors)

    buy_portfolio.name = "Buy Portfolio"
    sell_portfolio.name = "Sell Portfolio"

    to_be_saved_as_file = [buy_portfolio, sell_portfolio]
    my_funcs.excel_creation(to_be_saved_as_file,
                            "Portfolio Results/Sector Neutral",
                            "Sector Neutral Results")