Hi,
I'm retrieving historical price data for an asset and calculating the cumulative returns for 60 minutes following a series of events (specified by date and time). Now, I'd like to plot all these cumulative returns together, or even just one of them, using a simple line plot. However, I'm having trouble doing this.
Can anyone help me on this?
Thanks in advance!
Mia Alissi
Sure, I can help you with that. Here's a simple way to plot line charts using the
pandas
library in Python. This example assumes that you have a pandas DataFramehistory
with historical price data.First, you need to calculate the cumulative returns. You can do this using the
pct_change()
andcumprod()
methods in pandas. Here's an example:Then, you can plot the cumulative returns using the
plot()
method:Finally, you can display the plot using
plt.show()
:This will create a line plot of the cumulative returns for your asset. You can repeat this process for each series of events you want to plot.
Please note that this is a simplified example and you might need to adjust the code to fit your specific needs. For example, you might need to filter your historical data to only include the 60 minutes following each event.
For more information on how to work with data and plot charts in the QuantConnect Research environment, you can refer to the QuantConnect documentation.
I hope this helps! Let me know if you have any other questions.
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.
Amalia Fischbein
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!