0

I was going through the first answer on How do I calculate a trendline for a graph?. The answer says

Given that the trendline is straight, find the slope by choosing any two points and calculating:

(A) slope = (y1-y2)/(x1-x2)

Then you need to find the offset for the line. The line is specified by the equation:

(B) y = offset + slope*x

So you need to solve for offset. Pick any point on the line, and solve for offset:

(C) offset = y/(slope*x)

I'm pathetic in Math. So I need some help to understand the equation in programming term. Lets say I have stock data containing Date, Open, High Low, Close and Volume. If I am not wrong I have to calculate X Axis first as per this answer Calculate a trendline when the x-axis uses dates I could use mysql query to calculate X1-X2( which I am assuming difference between First and Last Date). And for Y axis Last Low Price - First Low Price (Still Assuming). But in next stage I'm stuck. How would I calculate x or offset and on third y? Can someone please help me to understand it?

Community
  • 1
  • 1
DAKSH
  • 460
  • 1
  • 5
  • 22
  • I also found a math equation [link](http://math.stackexchange.com/questions/204020/what-is-the-equation-used-to-calculate-a-linear-trendline) however as I explained I'm no good in math. – DAKSH Nov 17 '16 at 17:35
  • Smells like `teen homework` – RiggsFolly Nov 17 '16 at 17:36
  • @RiggsFolly Lol no. I work in Customer Service industry. When I get time I try to learn some programming. That's kind of addiction to me. – DAKSH Nov 17 '16 at 17:39
  • @RiggsFolly I studied commerce that's why :/ – DAKSH Nov 17 '16 at 17:43
  • Do you want a line that fits only the first and the last data point or do you want to fit a line to all of the data points? – evan.oman Nov 17 '16 at 20:33
  • @evan058 I just need a straight line which fits first and last point. – DAKSH Nov 17 '16 at 21:58

0 Answers0