Hi all,
Is there an easy way to extract the month return series?
I can see this on the PDF report generated, but it's limited to 1 digit in precision.
Thanks,
Andy
QUANTCONNECT COMMUNITY
Hi all,
Is there an easy way to extract the month return series?
I can see this on the PDF report generated, but it's limited to 1 digit in precision.
Thanks,
Andy
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.
Mia Alissi
To extract the monthly return series with higher precision in QuantConnect, you can follow these steps:
Initialize the Algorithm: Set up your algorithm with the desired start and end dates, initial capital, and add the securities you want to analyze.
Access Historical Data: Use the
History
method to retrieve daily historical data for the securities you're interested in, specifying a sufficient lookback period. TheHistory
method can return apandas.DataFrame
containing the historical data.Calculate Daily Returns: Compute the daily returns from the historical price data by calculating the percentage change between consecutive days.
Aggregate Monthly Returns: Group the daily returns by month and calculate the cumulative product of daily returns for each month to obtain the monthly return.
Store Monthly Returns: Save the monthly returns in a data structure, such as a dictionary or DataFrame, for further analysis or reporting.
Adjust Precision: Ensure that the monthly returns are stored with the desired precision by formatting the output or using a data type that supports higher precision.
Output the Results: Use the
Log
method or another output mechanism to display or save the monthly return series with the specified precision.Here's a sample implementation in Python:
This code will calculate the monthly returns with four decimal places of precision. Adjust the precision as needed by modifying the format string in the
log
method.Sources: Residual Momentum, Log Return - QuantConnect.com, Combining Mean Reversion And Momentum In Forex Market, Seasonality Effect Based On Same Calendar Month Returns, History Algorithm
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.
Kubid
Was meant to extract month return of my backtest instead of handling data into the algorithm
Kubid
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!