How to Compute Intraday Standard Deviations for various historical periods
Author: m0rtimersnerd
Creation Date: 11/21/2014 3:30 AM
profile picture

m0rtimersnerd

#1
Newbie here! Just starting to get used to the framework. So far, I'm very impressed.

I'm having difficulty finding an efficient and concise way to compute the following:

A scalar value representing the standard deviation of the price movement around the opening price for any specific day in the past.

I would like to calculate the standard deviations of the price movements around the respective opening prices for each of the last x days and average that number. Five days would mean averaging five scalars, each computed from one day's worth of intraday data.

Sounds like it should be easy using the powerful functions in your toolbox. I'm just not sure how to do it without writing my own FOR loops which seems quite inelegant, given the power of your framework.

If there is sample code out there to do something like this, I've not been able to locate it.

Thanks!



profile picture

Eugene

#2
No, it won't be possible to achieve that in a single line of code without your own for loops. The thing is, Wealth-Lab's internal structures like Bars/DataSeries do not support LINQ unless you come up with custom LINQ extensions (here's a DataSeries.ToList example). And even then it's not the end.

Let's not go off the beaten track:

CODE:
Please log in to see this code.
profile picture

m0rtimersnerd

#3

Thanks for your thoughtful answer and generous sample code.

Maybe I misunderstood the sample code you sent me because I don't think it provides sufficient patterns to attack my problem. I think your sample code takes the average of the first N bars from a historical period. It then takes the standard deviation of the average.

What I wish to do is compute the intraday standard deviation for a set of days from a data set that includes intraday bars from lots and lots of days.

What I am inferring from your answer is that I'm going to have to solve this by brute force in one of two ways:

1) Bust the multi-day time series into multiple single day time series and take the standard deviations of each of those seperately.

2) Cycle through a single set of 1 minute prices (tens of thousands of bars) using nested FOR loops to compute the standard deviation by hand for each day within that period.

Which do you think will be easier?

-Eric
profile picture

m0rtimersnerd

#4
I obviously have some type of mistake in here, but I can't seem to figure out what it is. Any help would be appreciated.


This almost works, but not quite. Even for an extremely volatile 3x leveraged ETF (lots of intraday volatility!), it produced a debug log which looked like this:

It Opened at 5.16 on day 1
It Opened at 5.85 on day 2
It Opened at 5.32 on day 3
It Opened at 4.19 on day 4
It Opened at 3.37 on day 5
The average Intraday Standard Deviation from the opening price was 0.00313748734503212 measured over the last 5 days


The SD value I expected would have been closed to .3 or .4.

I obviously have some type of mistake in here, but I can't seem to figure out what it is. Any help would be appreciated.







CODE:
Please log in to see this code.
profile picture

Eugene

#5
Good attempt. But by removing this:
CODE:
Please log in to see this code.


You're processing only the first 5 bars of the whole intraday chart, thinking that you're looping by day:

CODE:
Please log in to see this code.


Inserting this line in the loop by "i" should help instantly visualize it:
CODE:
Please log in to see this code.


I think this might also help:

Updating a Daily indicator using Intraday values
profile picture

m0rtimersnerd

#6
I'm getting very close to having my development environment setup---but I'm stuck on something small (and hopefully common)...

I'm setting up Visual Studio 2012 to use to debug as per the instructions published on this website.

I've created the following code which compiles successfully:

CODE:
Please log in to see this code.


This builds successfully:

1>------ Rebuild All started: Project: ClassLibrary2, Configuration: Release x86 ------
1> ClassLibrary2 -> C:\Users\eric.EDW\AppData\Roaming\Fidelity Investments\WealthLabPro\1.0.0.0\Data\Strategies\ClassLibrary2.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

and is saving the dll called ClassLibrary2.dll to the strategies directory shown above.



However, WealthPro can't find the .dll, and when I look in this directory, all I see for the WPL published strategies is XML files, not .dll's. Clearly, I'm doing someting wrong, but I'm not sure what it is.

How can I get WPL to see my strategy file?

Thanks!


profile picture

Eugene

#7
As per the strategy debugging tutorial, the correct placement is...

CODE:
Please log in to see this code.


i.e. Program Files/Fidelity Investments/Wealth-Lab Pro 6

P.S. Actually, despite you've used this code as an example, the question is wildly different and not related to the premise of the thread. Next time in such case please consider using a suitable existing or a new thread.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).