# Calculus and the Stock Market

Consider this possibility: A person wishes to follow stock prices (or commodity prices), and buy or sell securities according to market trends and condition throughout the day/week/month. Can calculus be used to follow the trend?

Last edited:

Related General Discussion News on Phys.org
loseyourname
Staff Emeritus
Gold Member
Derivatives whose value depends upon stocks or commodities can be valued in many ways, but the classic first method of valuing a derivative was the Black-Scholes formula for valuing European-style call and put options, which is the solution to a partial differential equation. It's been modified in various ways to deal with America-style options or options on stocks that pay dividends, etc.

I know the field has come a long way since then and is well beyond the Black-Scholes formula at this point, but to be honest, I don't know that much about it. Financial engineering and quantitative finance programs in graduate schools tend to teach stochastic calculus and econometric methods as the primary means of using math to value the crazy new creations they concoct to make money off of price movement.

If you're really just talking about trying to predict future movements in stock prices by following trend lines, though, that's called technical analysis and technical analysts have all kinds of weird voodoo rules regarding what to expect based upon wave oscillations and fractal geometry and what-not, but they're generally the outcasts of the finance world and their craft is considered more like numerology than science. They also tend to have a pretty bad track record.

Derivatives whose value depends upon stocks or commodities can be valued in many ways, but the classic first method of valuing a derivative was the Black-Scholes formula for valuing European-style call and put options, which is the solution to a partial differential equation. It's been modified in various ways to deal with America-style options or options on stocks that pay dividends, etc.

I know the field has come a long way since then and is well beyond the Black-Scholes formula at this point, but to be honest, I don't know that much about it. Financial engineering and quantitative finance programs in graduate schools tend to teach stochastic calculus and econometric methods as the primary means of using math to value the crazy new creations they concoct to make money off of price movement.

If you're really just talking about trying to predict future movements in stock prices by following trend lines, though, that's called technical analysis and technical analysts have all kinds of weird voodoo rules regarding what to expect based upon wave oscillations and fractal geometry and what-not, but they're generally the outcasts of the finance world and their craft is considered more like numerology than science. They also tend to have a pretty bad track record.
Thank you for the reply, that's very interesting. I understand that technical analysis is a "pseudoscience", I was thinking more along the lines of whether or not a daily price chart would be differentiable and if you could somehow use first and second derrivatives to track whether prices are "speeding up" or "slowing down" (inflection points), and executing buy and sell orders accordingly.

loseyourname
Staff Emeritus
Gold Member
You'd probably have to do that graphically. I can't imagine what kind of a function would actually map neatly onto a line chart of price fluctuations, though you could always attempt to derive a regression curve of price against time. Again though, with the number of ups and down in a given day, you could be looking at a 500th order polynomial or something defining the function, with hundreds of inflection points.

In practice, if you're looking for a way to place limit orders that don't get triggered by short-term random fluctuation, you'd just place it outside of whatever you project short-term price variability to be based on historical patterns. That way you'd generate a simple range rather than a function. For instance, if you know from past data that a security price has an average daily standard variation of 10% of its price or something like that, place a stop-loss at 15% or whatever margin of safety you want to avoid being triggered by expected fluctuation.

You'd probably have to do that graphically. I can't imagine what kind of a function would actually map neatly onto a line chart of price fluctuations, though you could always attempt to derive a regression curve of price against time. Again though, with the number of ups and down in a given day, you could be looking at a 500th order polynomial or something defining the function, with hundreds of inflection points.

In practice, if you're looking for a way to place limit orders that don't get triggered by short-term random fluctuation, you'd just place it outside of whatever you project short-term price variability to be based on historical patterns. That way you'd generate a simple range rather than a function. For instance, if you know from past data that a security price has an average daily standard variation of 10% of its price or something like that, place a stop-loss at 15% or whatever margin of safety you want to avoid being triggered by expected fluctuation.
Very, very interesting post! That puts everything into perspective. If things are that complex, do people really make money trading stocks day to day?

wavefunc
Actually, the stock market and other markets are easier to analyze using time series analysis in several time scales simultaneously. And, yes, people do make money in the stock market, and other markets. In my personal experience, FX is the most predictable one.

Actually, the stock market and other markets are easier to analyze using time series analysis in several time scales simultaneously. And, yes, people do make money in the stock market, and other markets. In my personal experience, FX is the most predictable one.
Thanks for replying. I'm interested in getting involved as I do have some risk capital available. Is the time series used to track daily trends, and then jump as trends increase?

wavefunc
You are most welcome. In reality, it is a lot more complicated than you have just suggested.
Typically, our model monitors 5 time scales around the clock to determine its entry/exit prices.

Thanks! What would be the best way for a beginner to learn to take moving averages of, say stock prices throughout the day and determine when to enter?

vanesch
Staff Emeritus
Gold Member
Thank you for the reply, that's very interesting. I understand that technical analysis is a "pseudoscience", I was thinking more along the lines of whether or not a daily price chart would be differentiable and if you could somehow use first and second derrivatives to track whether prices are "speeding up" or "slowing down" (inflection points), and executing buy and sell orders accordingly.
In as far as I see most simple models of stock market motion, one of the hypotheses that goes in all of these models is "market equilibrium" which means that "all the available information is in the current price". This means that the expectation value of the "next future price" is simply the current price ; in other words, the stochastic description of the stock value is a martingale. If you accept this hypothesis, it is strictly impossible to predict the expectation of future movements based on past movements better than to say "it will stay at its current value".
Another way of saying this is that most market models take on the "no arbitrage" hypothesis.

This can eventually not be the case ; if you are a fine market expert, you might know in advance how certain assets might move based upon information that is "not yet in the price" (in other words, that most traders ignore, or ignore how to use, and for which you are the world's only expert, or almost - or because you have inside information ).

Of course you CAN make money on the stock market. If you are willing to take a risk, you should be (on AVERAGE) rewarded for that with a risk premium. Normally, stock with large volatility (large fluctuations) will also grow faster (or crash...). But there's no magic formula that allows you to predict future trends beyond that, for a particular course. The reason is simple: if that formula existed, traders around the world would use it, until the gain margin (the arbitrage) would be small again, which comes exactly down to the statement that the current price already reflects the future expectation (diminished with riskless bond growth).

talk2glenn
Thanks! What would be the best way for a beginner to learn to take moving averages of, say stock prices throughout the day and determine when to enter?
A simple moving average is extremely easy to calculate, and most financial web sites have the tools to generate these for you automatically. For example, a 5-day SMA is the average closing price for the 5 most recent trading days, and is either higher or lower than the current closing price (which leads to the statement, "this stock is currently trading over its 5-day moving average"). However, this is a lagging indicator, and I strongly dissuade its use for determining "entry points" for stock purchases. A moving average is used only to smooth out price fluctuations over relevant terms for data clarity, not to predict market values or price changes.

You should consult with a qualified broker before buying or selling any securities.

I spend alot of time playing with this, mainly because there are a wide range of theories that are flawed, yet being applied daily. And second, I am a disabled vet who has nothing better to do and applied math helps with the nerve damage.

As someone pointed out, using dialy pricing is flawed for one fundamental reason: they are discrete data points in a large set of daily pricing data. Applying these discrete points to a continous function is not sound. Especially in this age of instantanous global trading. Think about it, who cares about the price of a stock at 4 pm in New York if it is continously traded in exchanges all over the globe. Just because the retail investor is limited in access does not mean your average wall street firm is not arbitraging 24 hours a day.

Add to the mix the endless derivatives and synthetic positions availabe for each stock. The stock price and volume are almost meaningless if you do not consider the activity and pricing of all positions available for a stock.

The problem is that most of the theories are based on research and theories formed in the 60's,70's and 80's. Hardly the global realtime markets that we have today.

Everything from portfolio theory to risk artbitrage in the public domain is dated. I doubt the trading systems on wall street use these equations.

Personally I am experimenting with game theory. I have been distracted this summer by my academic studies, but it is interesting.

One experiment. Plot the daily price range as a normal distribution. Do it for a 10, 20 and 40 day range. Do it for a few stocks that are actively traded.

wavefunc
A simple moving average is extremely easy to calculate, and most financial web sites have the tools to generate these for you automatically. For example, a 5-day SMA is the average closing price for the 5 most recent trading days, and is either higher or lower than the current closing price (which leads to the statement, "this stock is currently trading over its 5-day moving average"). However, this is a lagging indicator, and I strongly dissuade its use for determining "entry points" for stock purchases. A moving average is used only to smooth out price fluctuations over relevant terms for data clarity, not to predict market values or price changes.

You should consult with a qualified broker before buying or selling any securities.
OK, but how does your broker know about the entry points? Who does he consult? What makes him/her "qualified"?

wavefunc
I spend alot of time playing with this, mainly because there are a wide range of theories that are flawed, yet being applied daily. And second, I am a disabled vet who has nothing better to do and applied math helps with the nerve damage.

As someone pointed out, using dialy pricing is flawed for one fundamental reason: they are discrete data points in a large set of daily pricing data. Applying these discrete points to a continous function is not sound. Especially in this age of instantanous global trading. Think about it, who cares about the price of a stock at 4 pm in New York if it is continously traded in exchanges all over the globe. Just because the retail investor is limited in access does not mean your average wall street firm is not arbitraging 24 hours a day.

Add to the mix the endless derivatives and synthetic positions availabe for each stock. The stock price and volume are almost meaningless if you do not consider the activity and pricing of all positions available for a stock.

The problem is that most of the theories are based on research and theories formed in the 60's,70's and 80's. Hardly the global realtime markets that we have today.

Everything from portfolio theory to risk artbitrage in the public domain is dated. I doubt the trading systems on wall street use these equations.

Personally I am experimenting with game theory. I have been distracted this summer by my academic studies, but it is interesting.
Creating a profitable trading model is a challenging math problem, yet it has many acceptable solutions.

wavefunc
Thanks! What would be the best way for a beginner to learn to take moving averages of, say stock prices throughout the day and determine when to enter?
Financial markets are merciless to a beginner. Save your risk capital, or let a professional fund manager work with it. Make sure the manager has a good track record. Do not go to brokers.

I posted to this,, hmm didn't show up..

oh well.

The issue with most models is that they do not factor in commission and fees. Which is not an issue for wall street, but is a big factor for the retail investor.

Try buying DIA ( DJIA etf ) and writing options.. an easy 2-3% a month

As for trying to use calculus to predict the future value of the company why not look at the return on investment capital, and the portion earnings that are reinvested into the company.

To go a step further and look at the beta, this should give some sense on how market swings effect the company. Knowing beta and market volatility perhaps some measure of risk could be estimated which could be used to determine an estimate for the risk premium so that the price to earnings could be compared to the interest rate.

As for trying to use calculus to predict the future value of the company why not look at the return on investment capital, and the portion earnings that are reinvested into the company.

To go a step further and look at the beta, this should give some sense on how market swings effect the company. Knowing beta and market volatility perhaps some measure of risk could be estimated which could be used to determine an estimate for the risk premium so that the price to earnings could be compared to the interest rate.
To answer the first part, that relates to valuation of the company, but that does equate into market price.

And yes, that is exactly how valuations are done. The issue with this is that a retail investor has to rely on the analysts for this, because they given guidance by the company. Using historical data does not work for future valuations. Though the macroeconomic data, which is part of this process, is available.

The goal of the retail investor is to buy low, and sell high. Right now there are tons of undervalued companies, sell at a 40% discount to book value. The issue is that wall street drives the market price, and wall street is all about momenteum (sp).

Your second point is actually the issue. In today's global economy what is the risk free interest rate? 0% or 1% as Treasuries are trading? Or is it the German rate? Or for the average investor, the 2 year CD rate, which is insured?

And market volatility, is a one year sampling accurate? Or is a average of 20, 100, and 200 day average volatility correct?

I spend alot of time on your last point. And the volatility rate is a key, and the one year rate that is used in models is not accurate.

To answer the first part, that relates to valuation of the company, but that does equate into market price.

And yes, that is exactly how valuations are done. The issue with this is that a retail investor has to rely on the analysts for this, because they given guidance by the company. Using historical data does not work for future valuations. Though the macroeconomic data, which is part of this process, is available.

The goal of the retail investor is to buy low, and sell high. Right now there are tons of undervalued companies, sell at a 40% discount to book value. The issue is that wall street drives the market price, and wall street is all about momenteum (sp).
Part of me says if the company pays enough dividends (now or in the future) then why does it matter but I guess there are a few possibilities for the under evaulations based on the book value:

-The book value is wrong
-People expect more deflation or a double dip
-The markets are irrational (not efficient)
-People don't have the money to invest
-The money is chasing what they think are better opportunities/bubbles (emerging markets)

Who's buying the treasuries anyway? Is it small scale investors or is it people who can borrow cheap on the short term (such as banks) though deposits.

Are government securities (treasuries) assigned zero risk to the banks under bis calculations regardless of their term even though their value can change significantly if the interest rate changes. Cash equivalents are considered to have terms of three months or less see:
http://en.wikipedia.org/wiki/Cash_and_cash_equivalents
http://www.bestcashcow.com/bond_resources/treasury-bonds.html

However, if the bank can borrow cheaper though deposits then long term yields perhaps it doesn't matter and their is minimal risk.

For instance the passbook savings rate has been under 4% since 1991 but has averaged around 2%.

while the 20 year yield is close to 4% so the bank can be expected to make 2% on this. The reserve requirements in the us are 10% so if we assume all the money is deposted back into the bank the bank could make 10x2% on each dollar M1 is increased by. However, because people hold some cash I believe the multiplier is only about 2 (I'll try and track down my reference). So perhaps to a bank, the risk free rate of return is around 2% for long term investments.

Your second point is actually the issue. In today's global economy what is the risk free interest rate? 0% or 1% as Treasuries are trading? Or is it the German rate? Or for the average investor, the 2 year CD rate, which is insured?

And market volatility, is a one year sampling accurate? Or is a average of 20, 100, and 200 day average volatility correct?

I spend alot of time on your last point. And the volatility rate is a key, and the one year rate that is used in models is not accurate.
I think that volatility is different on different time scales. Additionally statical error in volatility calculations should be included when estimate risks. One could try and characterize the volatility with some kind of noise model (arma in the discrete case) and do either monty carlo simulations or use quazil linear kalman filter methods (linearization via statistical describing functions) in order to estimate the means and standard deviations in our predictions. Because the past cannot be completely relied on for future earnings and returns on capital, a random walk component could be added to the return on capital in the noise model to try and account for future uncertainties.

Last edited:
talk2glenn
OK, but how does your broker know about the entry points? Who does he consult? What makes him/her "qualified"?
If you're asking, how objectively does a broker determine when a market price is undervalued and/or overvalued, the answer is he cannot.

In classical market theory (the theory practiced by professional firms and enforced by the SEC), the current market price is by definition the true and correct valuation for the firm, given its material public financial condition. The price should be neither higher, nor lower. Technical analysis is an amateur, non-professional field that exists in newsletters and other private publishings which, thanks to the 1st amendment, are able to escape some of the broad reach of the SEC. But as pointed out, it is more akin to numerology than statistics (or astrology than astronomy, if you prefer). Its advocates believe that market prices are imperfect reflections of some "true value", and that you can divine this value through the application of some arcane, complex, and often tempting function.

At its simplest, there are seasonal technical theories, the most common of which says to sell into the summer and buy into the winter. It is true that, averaged over significant periods, this kind of hypothesis is statistically observable. It is most certainly not true that there is a causal connection between the price behavior and the time of year; rather, there were coincidental economic circumstances that justified the historic delta P (think of the timing of earnings reports).

A more "accepted" technical metric is the Bollinger Band. This is just a pair of curves that are plotted two standard deviations above and below the simple moving average, and reflect theoretical high and low trading ranges for a stock price along that average. That last part is critical; if a stock is moving outside its upper range on the Band, an imprecise technical analysis would tell you this is a sell signal. A more precise analysis would tell you that the moving average reflects past price trends; the price has probably escaped that range because of some later change in economic circumstances. Therefore a better use of the Bollinger Band is to signal changing market and economic conditions, not to set arbitrary entry and exit price points.

The trouble is, stock valuation is a subjective business. Price chart analysis is useful for telling you the observed trading range for stocks or indexes, given the economic circumstances of the time. That is, the S&P 500 might be expected to return between six and ten percent per anum, during periods of economic growth and growth in investment capital, with some expected volatility, variance, and moving average. The hard part is knowing whether we are currently in such a period, and therefore that kind of behavior can again be reasonably expected. Professional investors use there expectations about changing market and economic conditions to anticipate corresponding changes in growth and revenue patterns for particular companies and sectors, and buy and sell accordingly (using technical analysis to predict returns if their expectations turn out to be accurate) - but this is a reflection of their own opinion, hopefully based on some superior access to information thanks to their having more time and resources than the average amateur investor. It is by definition not an objective, "mathematically precise" game.

Part of me says if the company pays enough dividends (now or in the future) then why does it matter but I guess there are a few possibilities for the under evaulations based on the book value:

-The book value is wrong
-People expect more deflation or a double dip
-The markets are irrational (not efficient)
-People don't have the money to invest
-The money is chasing what they think are better opportunities/bubbles (emerging markets)

Who's buying the treasuries anyway? Is it small scale investors or is it people who can borrow cheap on the short term (such as banks) though deposits.

Are government securities (treasuries) assigned zero risk to the banks under bis calculations regardless of their term even though their value can change significantly if the interest rate changes. Cash equivalents are considered to have terms of three months or less see:
http://en.wikipedia.org/wiki/Cash_and_cash_equivalents
http://www.bestcashcow.com/bond_resources/treasury-bonds.html

However, if the bank can borrow cheaper though deposits then long term yields perhaps it doesn't matter and their is minimal risk.

For instance the passbook savings rate has been under 4% since 1991 but has averaged around 2%.

while the 20 year yield is close to 4% so the bank can be expected to make 2% on this. The reserve requirements in the us are 10% so if we assume all the money is deposted back into the bank the bank could make 10x2% on each dollar M1 is increased by. However, because people hold some cash I believe the multiplier is only about 2 (I'll try and track down my reference). So perhaps to a bank, the risk free rate of return is around 2% for long term investments.

I think that volatility is different on different time scales. Additionally statical error in volatility calculations should be included when estimate risks. One could try and characterize the volatility with some kind of noise model (arma in the discrete case) and do either monty carlo simulations or use quazil linear kalman filter methods (linearization via statistical describing functions) in order to estimate the means and standard deviations in our predictions. Because the past cannot be completely relied on for future earnings and returns on capital, a random walk component could be added to the return on capital in the noise model to try and account for future uncertainties.
I didn't do the quoting correctly. Yes you identified several factors, but there is one the average person can grab and run with, and that is market ineffiency. Sorry my spelling is horrible. The market has a herd mentality, and one widely used trading patterns is based upon jumping into the herd after it moves. ( which is why the best deals are under 5.00, stocks that are real beaten up, because most mutual funds cannot buy stocks under 5.00 and the herd has not overvalued them yet ).

There is no such thing as a double dip, that implies there was ever a sign of recovery, and there was not. The government calculation of economic stats using creative seasonal adjustments is not a recovery. But this is a whole debate in itself. And the talking head economists on tv perpetuating the myth of a "recovery" is shameful.

One issue with the market during this slump is that it is not valuation based. It makes sense, but this is an excellent time to buy discounted equity.

The issue with treasuries is that GAAP forces companies to use them in risk and valuation models. Not that investors will buy them or not. My point is that individuals and some trading firms are not pinned to the GAAP and do not have to use the CAPM for valuations.
Risk and valuation is in the eye of the beholder.

You can actually use volatility as a prediction tool. I don't like how it is used in most models, as a discrete value. Volatility is a continous variable and that is the flaw with most models, they use a very distored volatility variable.

Here is the direction I go. First, the total value of trading in any given stock is the value of the equity trading, and the value of the derivatives traded. ( very simplified explination ). And with the open interest you can start to predict the future volatility as the time moves closer to the options expiration. Since large traders can and will take advantage of pricing disrpencies during the week of expiration.

A good read concerning the statistical errors on pricing is a book by Mandelbrot.

One more point. The "market" is a broad term, and using the S&P as an indicator is problematic. When the market dumped in 2008, they dropped large caps that took hits. I have an issue with that. Citibank is still around, and it's price is reflective of the market. So what if it dropped 99%. That is the point of a market indicator.

If you're really just talking about trying to predict future movements in stock prices by following trend lines, though, that's called technical analysis and technical analysts have all kinds of weird voodoo rules regarding what to expect based upon wave oscillations and fractal geometry and what-not, but they're generally the outcasts of the finance world and their craft is considered more like numerology than science. They also tend to have a pretty bad track record.
The following video summarizes one type of this fractal geometry based on the Fibonacci ratio. It sounds a bit like voodoo to me but I'll with hold judgment as perhaps their is something behind it:

Her are some parers on trading base on the Fibonacci ratio:

http://theforexbooks.com/index.php/Fibonacci-E-Books/View-category.html

Last edited by a moderator:
They also tend to have a pretty bad track record.
Really? I read a paper that claimed to disprove the efficient market hypothesis by way of demonstrating that above market returns could be gained over a sufficient period of time using technical analysis. Unfortunately, this was a while ago and I forgot the link. I think it was in the wikipedia references list of the Technical Analysis page.

Last edited:
Of course you CAN make money on the stock market. If you are willing to take a risk, you should be (on AVERAGE) rewarded for that with a risk premium.
Yes, a risk premium for systematic risk. According to modern portfolio theory, inefficient portfolios will still have uncompensated risk due to lack of diversification, which the holder is not being compensated  for.

vanesch said:
Normally, stock with large volatility (large fluctuations) will also grow faster (or crash...).
This is putative in modern portfolio theory - CAPM, markowitz problems, factor models, etc. Although, have a look at Prof Haugen's paper on www.quantitativeinvestment.com - purports to empirically demonstrate that highest returns originate from low priced, blue chip, low volatitility stock.

Last edited: