Back

Extract daily P&L from a backtest

Hi,

Is there a way to extract the daily P&L of a backtest and paste it in excel ?

Thanks

Chris

Update Backtest







Hi Chris, you can do this locally. Just download the result JSON file from the overview tab, parse the JSON file into your local python environment, extract the strategy P&L and the benchmark P&L then write the dataframe to a csv file. The JSON file should be in the same folder as the .py file.

import json
import pandas as pd
with open("your_result.json") as data_file:
data = json.load(data_file)

if "Strategy Equity" in data["Charts"] and "Benchmark" in data["Charts"]:
strategySeries = data["Charts"]["Strategy Equity"]["Series"]["Equity"]["Values"]
benchmarkSeries = data["Charts"]["Benchmark"]["Series"]["Benchmark"]["Values"]

df_strategy = pd.DataFrame(strategySeries).set_index('x')
df_benchmark = pd.DataFrame(benchmarkSeries).set_index('x')

strategy = df_strategy.set_index(pd.to_datetime(df_strategy.index, unit='s'))
benchmark = df_benchmark.set_index(pd.to_datetime(df_benchmark.index, unit='s'))

strategy.to_csv(“strategy.csv")
benchmark.to_csv(“benchmark.csv")
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thank you Jing.

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed