17 votes

Calculating Bollinger Band Correctly

In Pandas 0.19.2++: ...
user avatar
12 votes

Theoretical justification for technical analysis

The answer to your question about the theoretical justification for technical analysis depends on the price series being analyzed. There is some evidence for a few technical indicators to have ...
user avatar
  • 2,740
11 votes

Calculating Bollinger Band Correctly

...
user avatar
  • 171
9 votes

Calculating Bollinger Band Correctly

I believe that the answers given here are incorrect as they return the sample standard deviation while the the population measure is the correct calculation for Bollinger Bands. The bands usign the ...
user avatar
  • 91
9 votes
Accepted

Half life of Exponetial Weighted Moving Average

The Exponentially Weighted Moving Average (EWMA for short) is characterized my the size of the lookback window $N$ and the decay parameter $\lambda$. The corresponding volatility forecast is then ...
user avatar
  • 1,386
8 votes

What is the difference between squared returns and variance?

Usually the formula for the sample variance of a stock is given by: \begin{equation} Var(R_{i}) = E (R_t - E(R_t))^2 \end{equation} If you are using daily data to compute the variance then the ...
user avatar
  • 6,665
7 votes

Theoretical justification for technical analysis

Really great question. Having studied finance academically, in an academic setting, you will always be told that technical analysis is non-sense. In the world of pure academics, the efficient market ...
user avatar
  • 4,951
6 votes

Is there a non-recursive way of calculating the exponential moving average?

The point of the recursive formula is that you can easily calculate the current EWMA if you have last period's EWMA. Equivalently, you can calculate all the weights directly and sum them that way. $$ ...
user avatar
  • 741
5 votes
Accepted

Why the diff of signal is called positions and what does it mean in backtesting?

My understanding, in that context, is that signal indicates that you want to hold a share (signal is 1) or hold no shares (signal is zero). Therefore taking the diff will tell you if you want to buy (...
user avatar
  • 4,217
5 votes

Unsmoothing of returns

Did you try solving for $w_k$? $$\bar{r}_t = \sum_{k=0}^p w_k r_{t-k}$$ $$\bar R = W R$$ Since you probably have $t>>k$, you can solve for $W$ using OLS $$\bar R = W R +\varepsilon$$ -- ...
user avatar
5 votes
Accepted

Is there a non-recursive way of calculating the exponential moving average?

I've been waiting for someone to ask this question since every published method with which I am familiar propose weights which converge to $1$ only when the numbers of terms goes to infininity. This ...
user avatar
5 votes

Theoretical justification for technical analysis

The theoretical justification for technical analysis (TA) is less about market (in)efficiency; and more about prices as a signal of sentiment and positioning biases, that are neither always neutral ...
user avatar
  • 4,886
4 votes
Accepted

Unsmoothing of returns

Thanks @Aksakal for suggesting Kalman Filter. Here I provide more details. We will view it as a state-space model: $$ \begin{split} z_t &= A_t z_{t-1} + B_t u_t + \epsilon_t, \\ y_t &= C_t ...
user avatar
  • 273
4 votes
Accepted

Aren't Technical Indicators calculated on Adjusted Close Price?

As can be seen from this example from Yahoo!Finance this should not happen (click on "+ The adjusted close"): https://help.yahoo.com/kb/finance/SLN2311.html?impressions=true Another more complete ...
user avatar
  • 26.7k
4 votes

Workflow in algorithmic strategies

"What are more appropriate way to test it with real-world data? Also, can you suggest the next steps to make it more realistic?" Pick a tradable instrument (e.g. SPY rather than S&P500), ...
user avatar
  • 2,076
3 votes
Accepted

Derivation (or proof) of commonly used formula showing relationship between time and smoothing factor in exponential smoothing

The current data point is said to have age 0, the previous has age 1, and so on going backwards. For a straight N period moving average of the form $\frac{1}{N}(x_t+x_{t-1}+\cdots+x_{t-N+1})$ it is ...
user avatar
  • 9,077
3 votes
Accepted

Where to get historical equity data?

Recently I came across interesting platform. https://www.quantopian.com/ they offer exactly what you need and for free. Basically, you code your algo in python, they provide data using api and ...
user avatar
3 votes
Accepted

How to get the the final % return in backtesting?

Note: Assuming you're a bit of a beginner trying to learn the ropes of how this whole process works at a high level, I can definitely make a couple recommendations (if I'm interpreting that wrong then ...
user avatar
3 votes
Accepted

Technical Indicators reference

The TA_lib Technical Analysis library here has open source code for numerous indicators.
user avatar
3 votes
Accepted

What is the difference between a moving average crossover and a moving average of returns?

Moving averages of prices are closely related to moving averages of price differences. In particular, if the price is a cumulative sum of historical price differences, $$ p_t = \sum_{j=0} \delta p_{t-...
user avatar
  • 5,603
3 votes
Accepted

Pricing an Asian style forward contract with early exercise feature

Welcome to Quant SE. Unfortunately there is no closed form formula for computing the american contract value $\max_{\tau}E^P\left[e^{-r\tau}(A_{\tau} - K)\right]$, so you have to resort to an american ...
user avatar
3 votes

Detect trend of an index

Questions: 1=> Does anyone have a suggestion to determine a trend correctly. My answer is in general and an opinion. Hong Kong Stock Exchange is third largest market behind Tokyo and Shanghai and ...
user avatar
  • 460
3 votes
Accepted

Exponential Moving Average Data Set Average Age

Bridging the gap between equation 2 and 3: Let us use the fact that the infinite series $\sum_{k=0}^\infty k \cdot \beta^k$ has a closed-form solution given by (see this post for proof): $$\sum_{k=0}^\...
user avatar
  • 3,263
2 votes

Technical Indicators reference

The Technical Analysis of Financial markets is considered as a milestone of the matter. I suggest to read that before starting to test your strategy. It explains well the use of each indicator, ...
user avatar
  • 2,438
2 votes

Technical Indicators reference

A very good reference can be found here: http://www.asiapacfinance.com/trading-strategies/technicalindicators
user avatar
  • 26.7k
2 votes
Accepted

Online algorithm for selecting smoothing parameter?

First of all, I do not believe the "optimal smoothing" of an estimator (like the mean or the variance) and the "regression case" are the same. The smoothing of an existing estimator (like mean or ...
user avatar
  • 10.5k
2 votes

Calculating Bollinger Band Correctly

Try to plot the rolling mean against your quotes for SP and see if it makes sense. Although you line of code to compute the rolling mean is correct, there might be something wrong in the data that you ...
user avatar
  • 169
2 votes

How to optimize return in a moving average crossover algorithm

It is unlikely that you could beat the market in the long-term with such a simple strategy. But, since you ask about optimization (not real trading), all you have to do to is run the optimization ...
user avatar
  • 271
2 votes
Accepted

Simple Moving Average Backtest: Cumulative Return too high

The moving average is determined as of the close of a particular day. Then to calculate the P&L you have to multiply today's state (1 or -1) by TOMORROWs return, instead you are using todays! So ...
user avatar
  • 9,077
2 votes

Where to get historical equity data?

I have used https://www.tickdata.com/ and https://www.quantgo.com/ I enjoy the simplistic nature of obtaining data that they use, so for someone new to quantitative finance like you, I recommend that ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible