Further improvement

The model can be generalized a bit, in the following way:

$R''(t)=\alpha \left ( \dfrac{t}{T}\right)^\beta(P(t)-0.5)+\gamma R'(t)$

Based on this model, the constants $\alpha,\beta,\gamma$ that offer the best fit could be found, in order to improve a bit the performance of the model.

Does a good January for the stock market imply a good year, and viceversa?

There is a saying in Wall Street, that says that whatever happens to the stock market in January will determine the rest of the year. That is, a good January will imply a good year for the stock market, and viceversa.

In this post, I will try to show if there actually is any truth to this. Continue reading

MonteCarlo and Arima for stock selection

A few days ago, in this post, I talked about how ARIMA models could be used to forecast the S&P 500 index, and use this information in order to buy or sell the index every day, if the algorithm predicts an increase or decrease in the price, respectively.

In this post, I will go a step further. The idea of the trading algorithm will be the following:

• Given a day, for each stock of a certain index, select the best ARIMA model for this stock.
• Then, simulate different possible trajectories of the price of this stock.
• Now, estimate the probability of the stock going up, dividing the number of trajectories that actually increased their price, by the total number of trajectories. This way of estimating probabilities is called Monte Carlo method.
• Now, since this process was repeated for a big number of stocks, we may sort them appropiately. If $p_i$ is the probability of a price rise for stock $i$, this stock would be a good candidate to buy if $p_i$ was close to 1. However, if it is close to 0, it would also be a good candidate, but for short selling. Thus, we pick the stock such that $|p_i-0.5|$ is the maximum.
• Now, once we have calculated the stock where the maximum is attained, we go long or short depending if the probability was greater or less than 0.5.

Once I have explained how the algorithm will work Continue reading

Trading strategy for the S&P 500 index based on ARIMA models

ARIMA models are a family of models for time series that are used to forecast future behaviour. It can be (and it is) used in finance, and in particular in trading. In this post I will try to show a specific use for a trading strategy based on these models, and it will be applied to the S&P 500 index.

ARIMA models are denoted by ARIMA(p,d,q), where:

• p is the order of the autorregresive factor.
• d is the order of differenciation, in order to obtain a stationary time series.
• q is the order of the moving-average.

R will be used to implement this strategy. In particular, the timeSeries, quantmod and forecast libraries will be used Continue reading

Differential equation that models the support and resistance strategy

Support and resistance indicators are widely used in technical analysis. What I tried to do is to model this strategy using a suitable differential equation, in order to test it with historical data.

A simple model could be the following:

$S'(t)=\gamma_t \displaystyle{\min_{s\in[0, N]} }\left ( |S'(t-s)|^\alpha + |S(t-s)-S(t)|^\beta \right )$