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.