BookmarkSubscribeRSS Feed
dfgbnm
Fluorite | Level 6

I am studying a high frequency tick by tick data. I want to calculate every 5 minutes volatility.

The volatility equation is as follow:

未命名10.png

P_t^High:the highest price in 5 minutes interval

P_t^Low:the lowest price in 5 minutes interval

P_t^Open:the opening price(first price) in 5 minutes interval

P_t^Close:the closing price(last price) in 5 minutes interval

 

The trading time in this data is from 8:45 to 13:45(5 hours).

The 5 minutes interval is defined as:(84500.000-85000.000), (85000.001-85500.000),

(85500.001-90000.000),......, (134000.001-134500.000)

 

Here is an example:

date              account         price            time
2010/1/4           123           8203         84500.155

2010/1/4           456           8187         84600.116      

2010/1/4           789           8194         84700.117

2010/1/4           452           8201         84800.115

2010/1/4           124           8199         84900.115

2010/1/4           477           8197         85000.145

2010/1/4           412           8199         85100.115

2010/1/4           633           8196         85200.123

2010/1/4           521           8198         85300.112

2010/1/4           213           8197         85400.145

2010/1/4           777           8199         85500.144

2010/1/4           216           8195         85600.566

2010/1/4           974           8197         85700.963

2010/1/4           269           8194         85800.419

2010/1/4           536           8196         85900.324

2010/1/4           236           8194         90000.639

 

The first 5 minutes volatility is from 84500.000 to 85000.000. So it is

1/2(8203-8187)^2-(2ln2-1)(8203-8199)^2.

 

Could you help me how to write the code about volatility equation above?The data format is csv. If you have any problem about my question, please let me know.

If you need the whole data, you can download the data I upload.

 

Many thanks for your help. Thanks for sparing your time. Highly appreciate it.

 

4 REPLIES 4
Reeza
Super User

This was asked recently on here. Or a very similar question at least. Please search through the forum for similar examples. 

Reeza
Super User

This was asked recently on here. Or a very similar question at least. Please search through the forum for similar examples. 

 

Otheriwse this is very likely homework so please show what you’ve tried so far. 

If you need direction check PROC EXPAND to calculate your rolling/moving statistics. 

Proc TIMESERIES may also be useful. 

dfgbnm
Fluorite | Level 6

Thank you for replying. I'm sorry about not familiar with SAS. I don't know how to write the code such as selecting the highest or lowest price every 5 minutes interval. 

If your time is allowed, please give me some help about coding.

 

Thank you very much for your help.

Reeza
Super User

There’s an example for PROC EXPAND here

https://gist.github.com/statgeek/07a3708dee1225ceb9d4aa75daab2c52

 

Given the correct procedures you should should be able to google a lot of resources on the topic with sample code. Post what you’ve tried and we’re happy to help further. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1286 views
  • 1 like
  • 2 in conversation