473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calculating covariance from a set of data

Hi

Firstly I'm quite a newbie in SQL, so apologies for any obvious stupid questions.

My problem is that I have a large set of stock price data for different companies together with the stock market price index, and I wish to calculate the covariance between the stock price and the index.

The data is structured so that for each row I have
PERMNRO - unique id for given company as integer
DATE - in text format yyyymmdd as text (not date, so some conversion needed)
VALUECHANGE - change in company's market price as double
INDEXCHANGE - change in the corresponding index as double

There is data for each banking day for 600 companies for ten years, so the database is quite large.

My output table would ideally be
PERMNRO
YEAR
COVARIANCE FOR LAST 3 YEARS
having an entry for the 31st of 12 december each year for each company.

I'm SLOWLY constructing the appropriate SQL stament in Access SQL view. I realize I need nested select statements, but just can not get the syntax correct.

Hopefully this description is clear and some of the experts could help me out. Although I have some background in programming, this whole stock price covariance thing is too complicated for me. Normally all the strategy research things I'm involved with here at the University are solved with Excel or VBA macros in extreme cases...

Best regards and greetings from Finland,

Olli Salo
Oct 26 '06 #1
3 8492
NeoPa
32,556 Expert Mod 16PB
I have a little routine for converting your dates to DateTime format

Expand|Select|Wrap|Line Numbers
  1. 'YMDToDate takes varDate in YYYYMM or YYYYMMDD format and returns it as a date.
  2. '28/01/2004 Return Null if not valid format.
  3. Public Function YMDToDate(varDate As Variant) As Variant
  4.     Dim strDMY As String
  5.  
  6.     strDMY = Mid(varDate, 5, 2) & "/" & Left(varDate, 4)
  7.     If Len(varDate) = 8 Then strDMY = Mid(varDate, 7, 2) & "/" & strDMY
  8.     YMDToDate = Null
  9.     If IsDate(strDMY) Then YMDToDate = CDate(strDMY)
  10. End Function
  11.  
I don't know how to calculate covariance mind.
Can you express what you would like the base data to be like - I may be able to provide SQL to get the data needed.
Oct 26 '06 #2
Tanis
143 100+
Covariance in financial terms is different from statistical covariance. Just be aware.
Oct 26 '06 #3
Hi

I mean the normal mathematical covariance, as defined for example by Wikipedia (http://en.wikipedia.org/wiki/Covariance).

In essence can be calculated with sum operator.

BR

Olli Salo
Oct 26 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kalyan | last post by:
Hi All, I have the table as follows column1 ...
1
by: Tony Johansson | last post by:
Hello!! When you have result covariance is it then necessary that you have inheritance. I mean can you have result covariance without having inheritance. //Tony
0
by: Aryeh Holzer | last post by:
Let me start with a quote from the C# Programmers Reference (where I learned the cool word "covariance"): "When a delegate method has a return type that is more derived than the delegate...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
1
by: Arkadiusz Stasiak | last post by:
I am looking for functions/library to calculate covariance matrix, eigenvectors, eigenvalues in Visual C++, as299@kent.ac.uk. Thanks
0
by: rach | last post by:
I am testing the covariance return in C++. First the following code worked. class A { public: class X {}; virtual X* f() {return new X;} }; class B : public A {
2
by: mufenhsieh | last post by:
I am testing covariance return in C++. First the following code worked. class A { public: class X {}; virtual X* f() {return new X;} };
1
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Jon Skeet wrote in the .NET general newsgroup 11/17/2005: "The difference between Invoke and DynamicInvoke is that the parameters to Invoke depend on the delegate itself - the method has the same...
2
by: Anders Borum | last post by:
Hello! I was wondering if anybody in this newsgroup are following the status of covariance in C#? As far as I'm concerned, generics covariance is not supported with C# 3.0 - unfortunately, as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.