Пример #1
0
    def output_results(self):
        # Closes off the Backtest.csv file so it can be 
        # read via Pandas without problems
        self.backtest_file.close()
        
        in_filename = "backtest.csv"
        out_filename = "equity.csv" 
        in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename)
        out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename)

        # Create equity curve dataframe
        df = pd.read_csv(in_file, index_col=0)
        df.dropna(inplace=True)
        df["Total"] = df.sum(axis=1)
        df["Returns"] = df["Total"].pct_change()
        df["Equity"] = (1.0+df["Returns"]).cumprod()
        
        # Create drawdown statistics
        drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"])
        df["Drawdown"] = drawdown
        df.to_csv(out_file, index=True)
        
        print("Simulation complete and results exported to %s" % out_filename)
        print("Generating summary stats.")

        sharpe_ratio = self.create_sharpe_ratio(df["Returns"], periods = 1)
        stats = [("Total Return", "%0.2f%%" % \
                    ((df["Equity"][-1] - 1.0) * 100.0)),
                 ("cagr", "%0.2f%%" % 0.0),
                 ("Sharpe Ratio", "%0.2f" % sharpe_ratio),
                 ("Max Drawdown", "%0.2f%%" % (max_dd * 100.0)),
                 ("Drawdown Duration", "%d" % dd_duration)]
        return stats
Пример #2
0
    def output_results(self):
        # Closes off the Backtest.csv file so it can be 
        # read via Pandas without problems
        ts = time.time()
        self.backtest_file.close()
        
        in_filename = "backtest.csv"
        out_filename = "equity.csv" 
        in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename)
        out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename)

        # Create equity curve dataframe
        df = pd.read_csv(in_file, index_col=0)
        df.dropna(inplace=True)
        df["Total"] = df.sum(axis=1)
        df["Returns"] = df["Total"].pct_change()
        df["Equity"] = (1.0+df["Returns"]).cumprod()
        
        # Create drawdown statistics
        drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"])
        df["Drawdown"] = drawdown
        df.to_csv(out_file, index=True)
        create_perf_plot(df)
        elapsed = time.time() - ts
        
        print("Simulation complete and results exported to %s in %3.2fs" % (out_filename, elapsed))
Пример #3
0
    def output_results(self):
        # Closes off the Backtest.csv file so it can be 
        # read via Pandas without problems
        self.backtest_file.close()
        
        in_filename = "backtest.csv"
        out_filename = "equity.csv" 
        in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename)
        out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename)

        # Create equity curve dataframe
        df = pd.read_csv(in_file, index_col=0)
        df.dropna(inplace=True)
        df["Total"] = df.sum(axis=1)
        df["Returns"] = df["Total"].pct_change()
        df["Equity"] = (1.0+df["Returns"]).cumprod()
        
        # Create drawdown statistics
        drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"])
        df["Drawdown"] = drawdown
        df.to_csv(out_file, index=True)
        
        print("Simulation complete and results exported to %s" % out_filename)
Пример #4
0
In this case it simply works off the "backtest.csv" file that
is produced from a backtest.py run.
"""


import os

import pandas as pd

from qsforex.performance.performance import create_drawdowns
from qsforex.settings import OUTPUT_RESULTS_DIR


if __name__ == "__main__":
    in_filename = "backtest.csv"
    out_filename = "equity.csv" 
    in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename)
    out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename)

    # Create equity curve dataframe
    df = pd.read_csv(in_file, index_col=0)
    df.dropna(inplace=True)
    df["Total"] = df.sum(axis=1)
    df["Returns"] = df["Total"].pct_change()
    df["Equity"] = (1.0+df["Returns"]).cumprod()

    # Create drawdown statistics
    drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"])
    df["Drawdown"] = drawdown
    df.to_csv(out_file, index=True)
Пример #5
0
This is a small helper script written to help debug issues
with performance calculation, that avoids having to re-run
the full backtest.

In this case it simply works off the "backtest.csv" file that
is produced from a backtest.py run.
"""

import os
import pandas as pd
from qsforex.performance.performance import create_drawdowns
from qsforex.settings import OUTPUT_RESULTS_DIR

if __name__ == "__main__":
    in_filename = "backtest.csv"
    out_filename = "equity.csv"
    in_file = os.path.join(OUTPUT_RESULTS_DIR, in_filename)
    out_file = os.path.join(OUTPUT_RESULTS_DIR, out_filename)

    # Create equity curve dataframe
    df = pd.read_csv(in_file, index_col=0)
    df.dropna(inplace=True)
    df["Total"] = df.sum(axis=1)
    df["Returns"] = df["Total"].pct_change()
    df["Equity"] = (1.0 + df["Returns"]).cumprod()

    # Create drawdown statistics
    drawdown, max_dd, dd_duration = create_drawdowns(df["Equity"])
    df["Drawdown"] = drawdown
    df.to_csv(out_file, index=True)