DR Ernest Chan

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

Dr.

Ernest Chan

 As I wrote in Algorithmic Trading, using log prices result in hedge ratio of market
values, raw prices result in ratio of shares.
 similar results
 Dear Ernie,
In your post about calculating the half life of the spread you talk about linear
regression of the daily change of the spread versus the spread itself. 
so if yt is my daily spread at time t,am i correct in doing the following
regression.Where C is the regression symbols? 

yt - y(t-1) c y(t-1)
 Hi JPS,
Yes, your regression is correct.
Ernie
 Dear Arnie,
I have two stocks which are cointegrated as per the Johansen co integration
test.An on running the VECM i check the residuals of the regression.My
observations are as follows.
1. There is no serial correlation among the residuals
2. There is HETEROSCEDACITY in the residuals
3.The residuals are not normally distributed.
Is this model acceptable?
is there any way of removing heteroscedacity in VECM?
 Hi JPS,
To avoid non-constant variance, try log prices instead of prices. But I don't see
why heteroscedacity is a problem for creating a profitable trading model. We also
don't particularly care if the residues are normal.
Ernie
 HI Ernie,
Thanks a lot for the clarifications.I was reading your blog about creating more
efficient pairs using combination of more stocks.My query regarding creating
combo of such type (for example a combination of stocks taken from index to be
combined with the index itself) is as follows.
1.Do these stocks individually need to be cointrgrated with the index
2.Do these stocks individually need to br Cointegrated with each other also
in other words what I am conjecturimg can we have two stocks which are not
cointegrated on one to one basis become conitegrsted when combined with a
third stock in a combination of three stocks.
 Hi JPS,
For the index arbitrage strategy between stocks and an index instrument, the
stocks individually should cointegrate with the index, but not necessarily with
each other.
Ernie
 Dear Ernie,
While going through some literature for Unit Root testing( which I implement on
the stock price time series ,I came across PPURootTest ( The phillip Perron Unit
Root Test) that also checks for the Structural breaks in the data.The NUll of the
test is that the Series has the unit root ( at Level) with a structural break at a
particular date which I interpret as that accepting the Null Hypothesis means the
Series is Non Stationary at Level and the data has a structural break at a
particular date at a specified date suggested by the test.But What to do with the
information about the structural break ?
 Hi JPS,
Yes, failure to reject null hypothesis means the price series may be non-
stationary. You need to find out a fundamental reason if possible for the
structural break, then you may learn how to devise a trading strategy that would
avoid its effects. For example, if the break is due to a central bank interest rate
announcement, maybe you can liquidate before such scheduled announcements.

Ernie

 Hi geegaw,
Thanks for your suggestion. It is an interesting idea. However, the ultimate performance
measure for trading a pair is the Sharpe ratio, regardless of holding period.
Ernie

 Zscore
  is simply the value of a spread divided by its standard deviation.
Ernie
 Dear Ernie ,
In the Book Quantitative Trading you have mentioned (while calculating sharp ratio) that in the
dollar neutral strategy there is no need to subtract the risk free return since the portfolio is self-
financing. But in some markets for example Indian Stock Markets the short selling of equities is
allowed only for intraday trades. So whatever long short strategy one needs to follow necessarily
has to be using futures. What should be the approach of calculating sharp ration in that case? 

Hi JPS,
If you can only hedge a long stock position with short future position, then you do need to subtract
the risk free rate when computing Sharpe ratio.
Ernie 
  JPS Rajput said...
 Dear Ernie,
I have a mean reverting spread in the form say for example ln(X)-0.7654*ln(Y)+3.41, where X and
Y are two scrips.
Can Sharp Ration for such a spread can be calculated and if Yes then How?Please suggest
As I was going through the book Quantitative Trading I came across the spread of the form A-B
whose calculation is very beautifully explained.
 Wednesday, May 27, 2015 at 3:09:00 PM EDT
  Ernie Chan said...
 Hi JPS,
It doesn't make sense to compute Sharpe ratio for a spread. You should only compute Sharpe
ratio on the returns of a strategy or a portfolio.
Ernie
 Wednesday, May 27, 2015 at 4:52:00 PM EDT


  JPS Rajput said...
 Hi Ernie,
Thanks a lot for the clarification.My next question is then what performance
parameter/parameters ( if any) can one use to grade the performances of the Spreads if not the
SHARPE RATIO
 Thursday, May 28, 2015 at 3:42:00 AM EDT
  Ernie Chan said...
 Hi JPS,
A spread as such does not have performance. It is a trading strategy on a spread that has
performance. You can certainly measure the Sharpe ratio on a trading strategy, since it generates
returns.
Ernie
 Thursday, May 28, 2015 at 7:57:00 AM EDT


  JPS Rajput said...
 Dear Ernie,
In the book quantitative Trading while writing the code for back-testing you calculate the Z sore
for the training set Data (I guess I have interpreted it right) by means of following code 

set % mean of spread on trainset


spreadMean=mean(spread(trainset));
% standard deviation of spread on trainset
spreadStd=std(spread(trainset));
% z-score of spread
zscore=(spread - spreadMean)./spreadStd;

Now while testing it on the test-set do we need to calculate the Z score of spread of the test-set
separately( using mean and standard deviation of the spread of test-set period) and then try to
see how it performs on the Deviations of the z score calculated from the Trainset?

or 
the z score of the spread of the test-set period is also calculated using the Mean and Stddev of
the Training set period and then performance tested using the Z score deviations which were
calculated by using trainset data.
 Friday, May 29, 2015 at 5:29:00 AM EDT
  Ernie Chan said...
 Hi JPS,
Whether to use the trainset or the testset to determine the mean and std is optional. I would
actually recommend using a moving average to determine mean and a moving std to
determine std, as in Bollinger bands.
Ernie
 Friday, May 29, 2015 at 6:33:00 AM EDT


  JPS Rajput said...
 Hi Ernie,
Thanks for the prompt reply.What I gather from your suggestion is that the Z scores should be
calculated dynamically rather than statically ( with a look back window as per the flavor of the
spread).So what you suggested ,I have tried to jot down logically as follows.Please correct me if I
am wrong.

Decide some look-back period = period( SAY 21 DAYS)

step 1: calculate the moving average of the spread = MA (spread,period)

step 2: Zscore(DYNAMIC) = (CURRENT VALUE OF THE SPREAD)- (CURRENT VALUE OF MA


OF SPREAD)/STDEV(SPREAD,PERIOD)

 Friday, May 29, 2015 at 9:12:00 AM EDT


  Ernie Chan said...
 Hi JPS,
Yes, you implemented my suggestion correctly.
Ernie
 Friday, May 29, 2015 at 9:22:00 AM EDT


  JPS Rajput said...
 Dear Arnie,
Can we safely take the half life of the dynamic ZScore of the spread (calculated based on your
suggestion in the previous blog) as a parameter for the exit strategy.As you had previously
suggested you consider the 3 times the half life a sufficient indicator to exit the spread position.
 Monday, June 1, 2015 at 10:43:00 AM EDT
  Ernie Chan said...
 Hi JPS,
Yes, some small multiple (<10) of this half life can be used to set the max holding period.
Ernie
 Monday, June 1, 2015 at 11:42:00 AM EDT


  JPS Rajput said...
 Dear Ernie,
As per your recent comment " I would actually recommend using a moving average to determine
mean and a moving std to determine std, as in Bollinger bands." 

What I gather is that the central line will be the MA of the Spread with the upper and bottom
envelop being the 2 STD of the MA of the Spread and one trades when the spread is at the upper
or the lower envelop.But this tool suffers from the same old problem of Bollinegr band being
LAGGARD as the actual shape it gonna take will emerge as the time progresses.

And further in this case what is the role of Z score as calculated by the above mentioned formula
step 1: calculate the moving average of the spread = MA (spread,period)

step 2: Zscore(DYNAMIC) = (CURRENT VALUE OF THE SPREAD)- (CURRENT VALUE OF MA


OF SPREAD)/STDEV(SPREAD,PERIOD)
 Tuesday, June 2, 2015 at 2:20:00 PM EDT
  Ernie Chan said...
 Hi JPS,
If you don't want a lagging volatility, you need to use a volatility prediction model such as
GARCH. Similarly, if you don't want to use moving average to predict mean, you need to use a
time series model such as ARIMA.

Ernie
 Tuesday, June 2, 2015 at 3:37:00 PM EDT


  JPS Rajput said...
 Dear Ernie,
Can you suggest any statistical indicator that can be used in conjunction with the Bollinger Band
of the spread ( Consisting of MovA of the spread and the stdev at upper and lower
levels).Basically this additional indicator I wanna use for an early exit if the trade goes against the
punt.
 Wednesday, June 3, 2015 at 4:03:00 AM EDT
  Ernie Chan said...
 Hi JPS,
You can always impose a trailing stop - but I don't recommend it for a mean reverting strategy for
the reason I stated in my article and book.
Ernie
 Wednesday, June 3, 2015 at 7:06:00 AM EDT


  JPS Rajput said...
 Dear Ernie,
While reading your book algorithmic trading (Section on Trading Pairs using Price Spreads,Log
Price Spreads, or Ratios) I got a bit confused.

lets suppose I find that two stocks X and Y are co-integrated and after regressing X on Y one gets
Y coefficient as 0.5467 and Constant 26

If X and Y are the future prices does this mean that for each lot of future of X long one need to
short half a lot for Y ( which means after normalizing it :for 2 lots long of X one short lot of y) .But
what is the significance of constant 26 in this equation .How do one take care of this in trading
terms
 Thursday, June 4, 2015 at 9:53:00 AM EDT


  JPS Rajput said...
 Dear Ernie,
In the book Algorithmic Trading you have mentioned that the values of the eigen vectors give us
the proportion of the shares for each script.

A) Does the Negative sign of the eigen vector indicates that that particular scrip needs to be
shorted while creating one "unit" of the portfolio.For example x-0.577y+9.0z where x y and z are
the scrips found to be coinetegrated and 1,-0.577,9.0 are the corresponding vlaues of eigen
vectors.Does this mean that while creating 1 "unit" one needs to short 0.577 units of y and long 9
unts of z and long 1 unit of x

B) when as per the Z score we (say at Z=+1) short 1 "unit of the portfolio , how does it translates
in terms of "short" and "long" in terms of individual scrips ?I am really stuck at this point as to
what will be the trading action...Please help me clarify this doubt 

B) what if x,y and z are the future and not shares?

C) if we get all the information from the eigen vectors of the Johansen test,is ther any need to
proceed to conduct VECM? 

 Friday, June 5, 2015 at 3:16:00 AM EDT


  Ernie Chan said...
 Hi JPS,
You can ignore the y-intercept in your regression. We are trading the mean
reversion of the residual - adding a constant to it won't affect your trading if you are using
Bollinger bands.
Negative component in an eigenvector means you should short the shares or futures contracts.
E.g -20.4 means short 20.4 shares or futures contracts. For futures, make sure you multiply the
prices with suitable multipliers first, otherwise the result won't make sense.

Ernie
 Friday, June 5, 2015 at 9:14:00 AM EDT


  JPS Rajput said...
 Dear Ernie ,
Many thanks for the clarifications.When you talk about multiplying by suitable multiplier (in case of
futures)you intend to this so that the future lots come in whole numbers( or near whole numbers)?
 Friday, June 5, 2015 at 9:40:00 AM EDT
  Ernie Chan said...
 JPS,
By futures "multiplier", I meant the dollar per points. E.g. 50 for ES.
We don't really care about whole numbers or not in backtest. 
Ernie
 Friday, June 5, 2015 at 11:12:00 AM EDT

IMP:
 The moving Z -Score is exact replica of the spread
deviation in the Bollinger Band of the Spread. It
is a matter of Back-Testing convenience that it is
calculated as a separate entity
 Run the VECM as per the dependent/independent variable
suggestion from the Johannes test and by switching the
variables from independent to dependent. The one with
the Maximum magnitude of the coefficient is the best
model. For example in SRRTEQ and AXIS VECM the Long
term Coefficient is significant in both cases( when either
SRRTEQ is made independent or AXIS is made independent
) but the Long term Coefficient is more ( 3% per day) in
case of AXIS as dependent rather in the case of SRRTEQ
dependent(1.24% per day)
 _____________________________________________
 Dear Ernie,
In then the book Algorithmic Trading ,while calculating the Kalman Filter based dynamic
regression the expression for R(t | t − 1) is cov(β(t) − ˆβ(t | t − 1)). which eventually helps in
calculating the value of K.

1) What is β(t) here...Is it the actual value of β at time t that one gets after regressing the
dependent variable on independent variable.

2) Also what should be the period of regression( I mean how many data points one should
choose to calculate β(t) β hat (t) etc.??
 Monday, June 8, 2015 at 5:12:00 AM EDT


  JPS Rajput said...

 Dear Ernie,
In the calculation of the kalman filter while calculating Q(T)
Q(t)=x(t, :)*R*x(t, :)’ WHAT DOES THE TERM x(t, :)’ DO?

and what is the dimension of Q(t)?


 Monday, June 8, 2015 at 8:54:00 AM EDT

  Ernie Chan said...

 Hi JPS,
Beta is a 2x1 vector which denote both the intercept and the slope of the linear relation between
the two instruments. The slope is often called the hedge ratio. Beta is updated at every time step
using the Kalman filter. The whole point of using Kalman filter is that we do not need to use linear
regression with a fixed lookback to compute the hedge ratio. Instead, it adapts to every new data
point, and uses the entire history.
Ernie
 Monday, June 8, 2015 at 9:12:00 AM EDT

  Ernie Chan said...

 Hi JPS,
Since R is a 2x2 covariance matrix, and Q is just a scalar variance of forecast errors, we need to
multiply R on both sides with a vector to turn a matrix into a scalar.
As a variance of prices, Q has the dimension of price squared.
Ernie
 Monday, June 8, 2015 at 9:16:00 AM EDT


  JPS Rajput said...

 Hi Ernie,
Thanks for the explanation. Is R a 2x2 diagonal matrix with the starting value as Delta (which in
the code we have taken as 0.0001?

So from what you said above I can conclude that the term 
x(t, :)*R*x(t, :)’ in the code mathematically equivalent to Square of Price X Det R ( Determinant of
R)
 Tuesday, June 9, 2015 at 1:07:00 AM EDT


  JPS Rajput said...

 Dear Ernie,
Further to my earlier query I guess X(t) has been made a Tx2 matrix so that x(t, :)*R*x(t, :)’ is
equivalent to a 1x2 matrix multiplied by 2x2 ( R the covariance matrix)and then 2x1 ( transpose of
x(t) ) which results in a scalar.
and further K is also a 2x1 matrix like beta

Am i correct in my interpretations?
 Tuesday, June 9, 2015 at 9:14:00 AM EDT

  Ernie Chan said...

 Hi JPS,
R starts off as a zero matrix, then get updated in the for loop as displayed on page 79. It is
generally not a diagonal matrix.

I am not sure that what you meant by Square of Price X Det(R), since Price is a vector, and the
result Q should be a scalar.

Ernie
 Thursday, June 11, 2015 at 2:49:00 PM EDT

  Ernie Chan said...
 JPS,
Yes, x*R*x' = Q is a scalar.

You can easily verify all these days by checking out the numerical results in Matlab or R.

Hi Ernie,
While reading your implementation of KALMAN filter  you have used the delta as .0001 and Ve as .01

1. Are these values of delta and Ve specific for the pair under study in the example  (you have
himself written " from the HINDSIGHT" : which means that we need to find it for specific pair
under study)?
2. While Establishing a trading system using KALMAN FILTER am I Correct in assuming ( taking
the bollinger band analogy) that the intercept c is the moving average, error term is the
spread and +/- sqrt(Q) are the upper and lower bands respectively.
3. While  Back testing using the KALMAN model,I have found ( in a large number of cases) that
though the long or short exit signal has given indication to exit the trade but the trade has
ended with loss. Is it normal thing to happen in this or I am making some mistake.

Will greatly appreciate if you could clarify my doubts!

Thanks in advance:))

Hi Jitender,
1) Indeed they are optimized for this pair, and may not be optimal for others.
2) Yes, you can interpret the intercept of beta as the moving average of the spread. It is just the intercept
in y=beta(1, t)*x + beta(2, t) + e. Error term e is the deviation of the spread from its moving average, and
sqrt(Q) is the 1 standard deviation of e.
3) Kalman filter strategies depend sensitively on many parameters! So a lot of optimization (hopefully in-
sample only) is needed.

Best,
Ernie  

 JPS Rajput said...

Dear Ernie,

Many thanks for the earlier replies! It has indeed propelled me in to study further the details of the
books

I have few other queries regarding the sections of the book where you have described trading
ETF and Triplets.

1.Does the Formation of a long-only portfolio (logMktVal_long=sum(log(yN),2)) to check that it co-


integrate with SPY is necessary in all cases or it is the compulsion of Long only Portfolio?
2. What if one discovers that Stock1(futures) ,Stock4(futures) and Stock5(futures) Co-integrates
individually with the 

Index and I want to create a long short portfolio among these 4. In this case Can't I straight away
run the Co-integration 

between the series consisting of [ stock1(futures) stock4(futures) stock5 (futures) ] and


[ index].Get the weights from 

the eigen vector and create a Long Short Portfolio?

3. If after getting the weights from the eigen vectors one gets a Spread of the Form of :

stock1(futures) + 0.90* stock4(futures) - 2.89 * stock5(futures) 

Please correct me IF I am wrong ( with respect to the aforementioned portfolio)

LONG PORTFOLIO TRADING DECISION :

Long I unit of stock1(futures) , Long 0.90 unit of stock4(futures) and Short 2.89 units of
stock5(futures) 

SHORT PORTFOLIO TRADING DECISION :

Short 1 unit of stock1(futures) , Short 0.90 unit of stock4(futures) and Long 2.89 units of
stock5(futures)

Monday, June 22, 2015 at 12:53:00 AM EDT

 Ernie Chan said...

Hi JPS,
1) The strategy is based on the mean reversion of the hedged portfolio. If we don't carefully select
the stocks that cointegrate with SPY in the long side, we cannot expect mean reversion.

2) Yes, but no cointegration test allows you to test more than 12 stocks. Furthermore, many of
those stocks will have negative weight. We don't want a long portfolio with short stock
components.

3) That is correct.

Ernie

Monday, June 22, 2015 at 8:24:00 AM EDT


 JPS Rajput said...

Dear Ernie,
Greetings for the Day!
Thanks for the prompt reply.I have got an interesting situation where the components stocks don't
co-integrate individually with the index but as a combination( component stocks and index) are
getting co-integrated.

In your opinion is it prudent to go ahead and create a spread between index and the components
stocks to trade knowing well that they ( component stocks) are not co-integrating with the index
on one-to-one level?

Wednesday, June 24, 2015 at 8:48:00 AM EDT

 Ernie Chan said...

Hi JPS,
Yes, you can do that - but make sure none of the components have a negative capital allocation.
Otherwise, you will be unduly concentrated on those stocks. We want a long-only stock portfolio
to arbitrage against an index ETF/future.

Ernie

Wednesday, June 24, 2015 at 10:21:00 AM EDT

 Larry Buchheit said...

Hi Ernie....I keep current on all your publications/blogs/lectures and your recent podcast. I am
spending considerable time and effort on cointegrating "triplets" using the Johansen Test. One
issue that doesn't seem to get any attention is the normalized eigenvector values that make up
the resulting proportions of the synthetic portfolio elements. Those particular eigenvector values
outputted from the Johansen test are NOT adaptive and represent the whole time period in
question. As we well know the Beta of a normal regression will determine a similar proportion
when only 2 components are being evaluated and of course that Beta changes throughout the
time period in question. Kalman filters can produce an adaptive Beta. How can we approach the
same situation when using the Johansen test to determine an "adaptive" proportion of
components in a triplet?

Thank you
LB

Friday, June 26, 2015 at 3:12:00 PM EDT

 Ernie Chan said...
Hi Larry,
Yes, the Johansen test will give you a stationary portfolio in the historical period, but does not
guarantee stationarity in the future. 

Kalman filter can be applied to any number of times series that will give you an adaptive beta.
Also, you can just run Johansen test on a moving lookback period. Even if it suggests that the
statistical significance is not high enough to determine cointegration, you can still use the
eigenvector as the components of your portfolio.

Ernie

Friday, June 26, 2015 at 7:20:00 PM EDT

 JPS Rajput said...

Dear Arnie,
I am facing a practical problem while applying the adaptive beta( kalman filter) strategy to the
futures.
Lets suppose I have a triplet and the hedge ratios at the start of the trade are

1 0.5 0.71 ( 1 being for the dependent variable and 0.5 and 0.7 being for the independent
variables).But both dependent and independent variable come in different lot sizes (minimum
quantity that one can buy which is also the $/point), for example the dependent its 260 and two
independents is 1400 and 600. 

Can we Simply multiplying these lot sizes to the hedge ratios?Will not that change the ratios as
suggested by the filter?

If we can not the simple multiplications like above what is the way out?

Saturday, July 4, 2015 at 9:10:00 AM EDT

 Ernie Chan said...

Hi JPS,
If you are applying these methods to futures with different multipliers, you need to multiply the
futures' points by their multipliers in order to convert them to dollar values first. For e.g. for ES on
Globex, you need to multiply the points by 50.

Ernie

Saturday, July 4, 2015 at 9:13:00 PM EDT


 JPS Rajput said...

Dear Ernie,
What i gather from what you suggested is that the future price series should first be multiplied by
their respective multipliers before putting them under analysis.
Am I correct in my interpretation?

Saturday, July 4, 2015 at 9:29:00 PM EDT

 Ernie Chan said...

Hi JPS,
Yes, you are correct.
Ernie

Sunday, July 5, 2015 at 6:31:00 AM EDT

 JPS Rajput said...

Dear Ernie,
Greetings for the Day!
As suggested by you in response to my earlier query regarding the implementation of KALAMAN
FILTER strategy to the futures, one needs to multiply by the respective multipliers of the futures
to the price series to arrive at dollar values.

Exchanges ( at least Indian Stock exchange does that) change the multiplier values periodically
as and when the prices of the underlying go very high or low and in case of splits. While in case
of splits of the underlying stock the total dollar value does not change but in other case it gives a
sudden spike in the dollar values of the futures.

1.Does this impact the accuracy of the analysis in terms of hedge ratios that are arrived at and
my give us unrealistic results?

2. Is there any way to get around this problem?

Tuesday, July 7, 2015 at 1:29:00 PM EDT

 Ernie Chan said...

Hi JPS,
Naturally, you need to use the multiplier that was in force at the time a price point was recorded in
your historical time series. So you need a historical time series of the multiplier itself.
Ernie

Tuesday, July 7, 2015 at 1:54:00 PM EDT

 JPS Rajput said...

Dear Ernie,
Thanks for the prompt reply.I do have the historical multiplier series,but my concern is about the
spurts in the dollar values as and when the new multiplier comes in to force.
Does these sudden spikes in dollar values impact the accuracy of the analysis?

Tuesday, July 7, 2015 at 2:02:00 PM EDT

 Ernie Chan said...

Hi JPS,
If you apply the historical multipliers to the historical prices correctly, there should be no jumps in
the adjusted price series that you feed into various algorithms. A jump in such adjusted series
indicates that your historical multipliers were not correct.

Ernie

Tuesday, July 7, 2015 at 2:42:00 PM EDT

 JPS Rajput said...

Dear Ernie,
Greetings for the day!

The code that has been used in most of the strategies in the books for PnL is as follows:

positions=repmat(numUnits, [1 size(y2, 2)]).*[-beta(1, :)' ones(size(beta(1, :)'))].*y2; %


[hedgeRatio -ones(size(hedgeRatio))] is the shares allocation, [hedgeRatio
-ones(size(hedgeRatio))].*y2 is the dollar capital allocation, while positions is the dollar capital in
each ETF.

pnl=sum(lag(positions, 1).*(y2-lag(y2, 1))./lag(y2, 1), 2); % daily P&L of the strategy

Considering a scenario where the price series is the dollar value instead of pure price.
I guess the Pnl is the daily return matrix of the strategy, which is used to calculate APR and
Annualized return. 

This matrix actually does not tell us about the Net Cash Inflow or the Outflow (if one follow the
trade signal of Long and short) which further Mean the sum of the matrix Pnl does not give us the
Net Cash Inflow/Outflow even if the Series under analysis are dollar value series.

A I right in the interpretation of the code?

Friday, July 10, 2015 at 11:24:00 AM EDT

 Ernie Chan said...

Hi JPS,
The pnl in the code above is not the portfolio return. It is the portfolio P&L. In order to get the
return, you have to divide that by the gross market value of the portfolio, given by
sum(abs(lag(positions, 1)), 2).

In our backtest, we are generally not interested in cash flow. I.e. we don't care if the P&L is
realized or unrealized. We compute the total P&L, which is the sum of realized + unrealized P&L.
The same goes for returns computation.

Ernie

Friday, July 10, 2015 at 11:54:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Greeting for the Day!

You have mentioned in the Book Quantitative Trading, that while calculating the Sharpe Ratio in
the Dollar Neutral Strategy there is no need to subtract the risk free return as the portfolio is self
financing. Does the same principle applies to the dollar neutral portfolio using futures? In Indian
exchanges one needs to maintain the margins both for the short and log futures positions and
one does not get any interest on the maintained balance from the exchange.

if the answer to the above question is yes then ,since it is the double cost for maintaining the
portfolio, does one need to subtract double the value of risk free interest rate from the portfolio
return, while calculating the Sharpe Ratio?

Monday, August 3, 2015 at 4:57:00 AM EDT


 Ernie Chan said...

Hi JPS,
There is never any need to subtract risk free rate from the raw returns when computing a futures
strategy's Sharpe ratio in the US. I am not familiar with Indian futures exchanges, but are you
sure that you cannot hold government bonds as collateral, and thus earning interest on those?

Even if you don't collect interest on the collateral, you don't have to pay interest on your nominal
futures positions. So you still don't have to subtract interest rate from raw returns.

Ernie

Monday, August 3, 2015 at 7:13:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Greetings for the Day!

While reading Kalman Filter as Market-Making Model in the book Algorithmic Trading you have
mentioned making Ve as a function of t as well. 

" If we denote the trade size as T and the benchmark trade size as Tmax".....

My question is what is T and Tamx ( the bench mark trade size) especially when one is dealing
with future?

Friday, August 21, 2015 at 5:27:00 AM EDT

 Ernie Chan said...

Hi JPS,
T or Tmax refers to trade size, which in futures markets refer to the number of contracts traded.
Ernie

Friday, August 21, 2015 at 9:12:00 AM EDT

 JPS Rajput said...
Dear Ernie,

Thanks for the reply!

So we are directly incorporating the volume of the contracts traded in the equation, but what
should be the BENCHMARK trade size (Tmax)?

is it the maximum numbers of contracts traded for that script historically?

Friday, August 21, 2015 at 9:32:00 AM EDT

 Ernie Chan said...

Hi JPS,
As I wrote in my book, Tmax "... can be some fraction of the total trading volume of the previous
day, for example, where the exact fraction is to be optimized with some training data."

Ernie

Friday, August 21, 2015 at 9:36:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Greetings For the Day!

I am trying to understand "Kalman Filter as Market-Making Model" as per given in the in the book
Algorithmic Trading .I have few queries , as the model seems to be a bit different from the model
described in the previous example ( using hedge ratio).

1.Does all the attributes while designing this model like P,R,K are just single value variables as
compared to matrices in the kalman filter for pairs and triplets?

2. The value of Q(t)=var(m(t)) .. Does this mean Variance of all the values of m till time t?

3.Though Ve has been made dependent upon time and volume but the variable Vw is not.In the
new changed scenario for time variability of Ve does the role of Vw changes or it still to be a fixed
constant which needs to be fixed for optimum output?

Monday, August 24, 2015 at 8:31:00 AM EDT

 Ernie Chan said...
Hi JPS,
1) Yes.
2) No. This is merely a definition of Q, which is updated at every step.
3) Vw is set to 0 here.

Ernie

Monday, August 24, 2015 at 8:48:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Thanks a lot for the reply!!!

Would Greatly appreciate If you could throw some light as to how to calculate Q(t) in a single
series Kalman filter case.

As here we have only R available and no other independent variable (like x(t) ) where we could
calculate Q(t)= x(t,:)* R *x(t,:)' +Ve

Monday, August 24, 2015 at 9:07:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Thanks a lot for the reply!!!

Would Greatly appreciate If you could throw some light as to how to calculate Q(t) in a single
series kalman filter case,

As here we have only R available and no other variable (like x(t) ) where we could calculate Q(t)=
x(t,:)* R *x(t,:)' +Ve

Monday, August 24, 2015 at 9:13:00 AM EDT

 Ernie Chan said...

Hi JPS,
All the required iterative equations are displayed on Eq. 3.14-3.20. We have just used m(t)
instead of x(t). The KF equations in Box 3.1 is valid irrespective of the dimension of the variables,
which in this case is just 1.
Ernie

Monday, August 24, 2015 at 10:06:00 AM EDT

 JPS Rajput said...

Dear Ernie,

So can we safely say m(t) is the 1 X N (N total number of observations) vector of the mean values
of the price series where mean for a particular time instance 't' can be calculated as (H+L)/2
where H ans L are the low and high price of the observable variable for a particular time instance
t.

Monday, August 24, 2015 at 12:50:00 PM EDT

 Ernie Chan said...

Hi JPS,
m(t) is indeed a 1xN matrix, but it has nothing to do with the high or low at any time. It is a
quantity to be deducted from the Kalman update equations.
Ernie

Monday, August 24, 2015 at 1:16:00 PM EDT

 JPS Rajput said...

Dear Ernie,

Thanks for the clarifications.Just one more doubt, what would be the state co-variance prediction
in this case as in this case we have set Vw=0 so R=P+Vw is not doing anything actually?

Monday, August 24, 2015 at 2:16:00 PM EDT

 Ernie Chan said...

Hi JPS,
What you wrote is incorrect. Please look at Eq. 3.19.
Ernie
Monday, August 24, 2015 at 2:25:00 PM EDT

 JPS Rajput said...

Dear Ernie,
Greetings for the Day and Thanks for such a wonderful help all along really appreciate the help.

My doubt stems from the fact that eq (3.19) is state variance update 
R(t | t) = (1 − K(t))R(t | t – 1)) and is akin to the equation P =R*(1-K).

But what should be the parallel to the R=P+Vw; the state co variance prediction (Equation 3.8)
Since as R=0 initially, R will not increment with each iteration if we have Vw=0.

Tuesday, August 25, 2015 at 7:24:00 AM EDT

 Ernie Chan said...

Hi JPS,
I notice on error in one of my previous responses to you. m(t) is akin to beta(t) in Eq. 3.7, not to
x(t). It is the hidden variable.

Indeed the state variance prediction is just the identity relation here. It does not mean, however,
the R(t) remains constant at every t: it is still updated through the state variance update step
(after an observation).

Ernie

Tuesday, August 25, 2015 at 7:58:00 AM EDT

 JPS Rajput said...

Dear Ernie,
Greetings for the day!
While Discussing the Time Sereis Momentum Strategies in the chapter 6 of the book " Algorithmic
Trading", you have mentioned that if

" If look-back is greater than the holding period, we have to shift forward
by the holding period to generate a new returns pair. If the holding
period is greater than the look-back, we have to shift forward by the lookback
period "
But in this piece of code ( Finding Correlations between Returns of Different Time Frames) we
are doing just the reveres.Is there any specific reason for that?

if (lookback >= holddays)


indepSet=[1:lookback:length(ret_lag)];
else
indepSet=[1:holddays:length(ret_lag)];
end

Monday, August 31, 2015 at 1:51:00 AM EDT

 Ernie Chan said...

Hi JPS,
You are right - there is an error in the book. lookback and holddays should be reversed after [1:.

Thanks for pointing that out!


Ernie

Monday, August 31, 2015 at 7:38:00 AM EDT

 JPS Rajput said...

Dear Ernie,

Greetings for the day!!! 

Thanks for the reply to an earlier query.I have 2 small queries regarding the Time Series
Momentum Strategies Example 6 (chapter 6) of the book " Algorithmic Trading",

1 as you have mentioned that there has been a slight modification in the strategy adopted by
(Moskowitz, Yao, and Pedersen, 2012) .“Instead of making a trading decision every month, we
will make it every day, each day investing only one twenty-fifth of the total capital”. What is meant
by taking the trading decision each day? If we are doing this on daily basis what is the
significance and purpose of the “holding period”( 25 days in this case)? I suppose that once we
take position we hold it for " Holddays" number of days.

2.While calculating the returns of the strategy I have confusion.The return is calculated as follows.

ret=(backshift(1, pos).*(cl-backshift(1, cl))./backshift(1, cl))/holddays


Lets consider for example the holding period is 3 days then the pos Matrix can have the values
( assuming at time =0 it has +1 due to 1 in the long matrix) 3,1 or -1 after the completion of the
loop “for h=0:holddays-1” . But while calculating the return we are multiplying pos matrix with the
return of only previous day? What about the returns of the previous 2 days? 

Tuesday, September 1, 2015 at 7:46:00 AM EDT

 Ernie Chan said...

Hi JPS,
1) On each day, you decide whether to buy or short to do nothing, based on the momentum entry
rule. Once entered, you hold the position for 25 days.

2) Yes, if Holddays=3, pos can be -3 to +3. Hence the unlevered return that we compute using
the formula you wrote must be divided by 3. That return capture all 3 positions, whether they are
entered on the same day or not.

Ernie

You might also like