Hi all,
I'm new to C# and relatively new to programming in general. I'm trying to build a simple algorithm to backtest a pairs trading idea.
Essentially I want to take two securities (let's say coke and pepsi) and find the ratio of the price of one to the other (I think I got that part down). After that I would like to find the average of that ratio at the close of the last 14 days. I tried using the SMA function but it appears to only work with securities and not with custom variables. I also need to find the 50 day standard deviation for the ratio of the prices of the two stocks. If someone could explain how to do this I would greatly appreciate it. The idea is to short the overpriced stock and buy the cheap stock when the ratio is 3 standard deviations above or below its 14-day average. I think I figured out how to execute the orders using if statements but I can't solve for z score of the ratio because I don't know how to find a 14-day mean or stdev.
Jared Broad
Queue.Enqueue(x); if (Queue.Count > 14) Queue.Dequeue(); var sma = Queue.Sum()/Queue.Count();
We also support Math.Numerics, so any functions you find in there you can use by adding the right "using" statement to the top of the file.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.
James Marshall
James Marshall
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!