Question on np.apply_along_axis

Back

I looked at Alex Muci's Adaptive Volitily position sizing algo and wanted to see if I could capture R Squared calcuations in a dataframe, for a 21 day lookback period for whatever symbols I might have along with whatever else data I may want to capture in a dataframe.

I  used: 

rsq = np.apply_along_axis(self.rsquared, 1, arr, self.x)

I want to be sure I understand what np.apply_along_axis its doing, rsquared is the fuction that  takes two equal lenth series as parameters, I found some notes on the internet that indicate "1" should tell rsquared to look at each row of my array 'arr' which contains a series of prices, depending on the number of symbols with 21 price points, and self.x contains a list of numbers 0-20 value. It seems to itterating over the arr and producing a new list with the R squared values. I am not sure I understand what "1" is doing. I guess it has to be working if its giving a result and not throwing an error. I just do not feel like I fully understand how np.apply_along_axis is working with the '1' parameter.

Also is there a more efficent way to get thes calculated values into an exsiting dataframe.

 

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.


 

Hi Steven,

Please see NumPy’s documentation on apply_along_axis. As for a more efficient way of getting the data into a DataFrame, we suggest looking into the pandas documentation. One change that can be implemented however is to change

Enterdata['rsq'] = rsq.tolist()

to

Enterdata['rsq'] = rsq


This change can be seen in the attached backtest.

Best,
Shile Wen

1

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.


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