Bas de Kruijf
Bas de Kruijf

Reputation: 5

Looping with ARIMA to predict volatility

A small question about loops in Stata:

I have a dataset that includes the following variables: implied volatility (of stock options), and the delta of that option (elasticity of the option price on the underlying). Delta is between 20 and 80 strictly, with increments of 5. Implied volatility is usually a couple percent.

I want to get this:

quietly arima impl_volatility if delta == 20, ar(1) ma(1)
predict tildevol20 if delta == 20

looped for each value of delta (20, 25, 30, 35, ..., 80), so that the next in the loop would be:

quietly arima impl_volatility if delta == 25, ar(1) ma(1)
predict tildevol25 if delta == 25

The variable tildevol(delta) should start at tildevol20 and increase with the delta as well up to tildevol80.

I've tried this, and a couple of other iterations, but I can't seem to get it working (deltalvl is the name of the local stored values of delta, 20-80).

levelsof delta, local(deltalvl)
foreach 1 of local deltalvl {
   quietly arima impl_volatility if delta == `deltalvl', ar(1) ma(1)
   predict tildevol`deltalvl' if delta == `deltalvl'
}

It returns nothing, it just runs, then ends, it doesn't give an error.

Stata documentation doesn't seem to have anything on this (or I might just be looking in the wrong place).

Examples of the dataset:

example 1

example 2

So every date has every delta between 20-80 with increments of 5, and every delta has an implied volatility. So 1 date > 13 deltas > each delta 1 volatility.

Upvotes: 0

Views: 349

Answers (1)

Nick Cox
Nick Cox

Reputation: 37183

What makes a little more sense would be something like

foreach 1 of local deltalvl {
   arima impl_volatility if delta == `1', ar(1) ma(1)
   predict tildevol`1' if delta == `1'
}

but it's not easy to predict whether that will work.

quietly when debugging is a bad idea. You may need the information Stata will give.

Upvotes: 1

Related Questions