%matplotlib inline
# Imports
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Jupyter")
from QuantConnect import *
from QuantConnect.Jupyter import *
from datetime import datetime
import matplotlib.pyplot as plt

user_id = 0
api_access_token = ""

# Create an instance
aa = AlgorithmAnalysis(user_id, api_access_token)

"""
Explanation: Algorithm Analysis notebook
Start AlgorithmAnalysis

Add the references and imports
Create a AlgorithmAnalysis instance

Find your user id and api access token at https://www.quantconnect.com/account
End of explanation
"""


aa.ListProjects().head(10)   # List the 10 last modified projects

"""
Explanation: List projects
It may take a few seconds if you have a lot of projects
End of explanation
"""


aa.ListBacktests(628051)

"""
Explanation: List backtests
Lists all backtest from a given project
It may take a few seconds if you have a lot of projects
End of explanation
"""


aa.GetOrders(628051, "4fdd334f2a04c0197342b6870bcc93d1")

"""
Explanation: Read out the orders of a specific backtest
End of explanation
"""


aa.GetProfitLoss(628051, "f2f9b85264e5edd4c9ea957a314ec573").cumsum().plot()

"""
Explanation: Read out the P/L of a specific backtest
Use DataFrame cumsum method to compute the cumulative returs and plot
End of explanation
"""


