Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-03-2007, 09:03 AM
JapanFreak JapanFreak is offline
Registered User
 
Join Date: Aug 2007
Posts: 38
JapanFreak is on a distinguished road
Creating Time Series for Portfolio Values

Dear All,

once again I need your help, I have no idea how to tackle the following problem. I am taking records of stock market transactions. As a final result I want to have a query which gives me for every end of the day the total value of my portfolio.
Therefore I have two tables. The first one, called tblTransactions with columns - among others - Date, Ticker, Quantity, Price does contain my transactions. The second one, called tblQuotes with columns Date, Ticker, LastPrice contains prices for each security traded for every day.
The following SQL code gives me the portfolio holdings with the respective LastPrices on an arbitrarily chosen date (03/09/07):

Code:
SELECT T.Ticker, sum(T.Qty) AS TotQty, Q.qCl AS [Last Price], (T.Qty*Q.qCl) AS [SubTotalValue]
FROM tblTransactions AS T INNER JOIN tblQuotes AS Q ON T.Ticker=Q.qTicker
WHERE T.Date<=#3/9/2007# And Q.qDate=#3/9/2007#
GROUP BY T.Ticker, Q.qCl, (T.Qty*Q.qCl)
HAVING sum(T.Qty) >0
ORDER BY T.Ticker;
This works so far. However, now I struggle with the next step. I want to have a query, which for each date (I could use the date column of tblQuotes) adds all SubTotalValues, i.e. gives me the total value of my portfolio for each day.

Could you give me please some hints on how to proceed from here? I would be very pleased if somebody could help me with that question.

Best regards
JapanFreak
Reply With Quote
Sponsored Links
  #2  
Old 09-04-2007, 05:55 AM
Bilbo_Baggins_Esq Bilbo_Baggins_Esq is offline
Registered User
 
Join Date: Jul 2007
Posts: 359
Bilbo_Baggins_Esq will become famous soon enough
If you can post a sample, I'd be happy to look at this.

I'm thinking a couple of crosstabs with another select query to bring holdings and values together might do the trick.
__________________
If you feel that a member has helped you with your question, please remember to add to that member's reputation.

Please be considerate of all users and refrain from sending direct requests for help via Private Message.
If help sessions are conducted via Private Message, not only do you limit your access to other experts, but you also limit other's access to solutions that may help them.
Reply With Quote
  #3  
Old 09-04-2007, 03:38 PM
JapanFreak JapanFreak is offline
Registered User
 
Join Date: Aug 2007
Posts: 38
JapanFreak is on a distinguished road
Bilbo_Baggins_Esq,

I am of course more than happy to upload an example. The attachment contains the two tables tblTransactions and tblQuotes (the latter one is updated via internet using a free tool called Quaccess -> www.quaccess.com), i.e. the structure of the latter table must not be changed. Additionally the file contains one query, which is the one posted before. It shows the portfolio composition on one arbitrarily chosen date based on the transactions recorded in tblTransactions.

The data are of course only some sample data, which make as such no sense at all. However, they show the basic cases, which are possible: Securities may be bought and sold at irregular dates. The composition of the portfolio (i.e. the securities - identified by tickers - within the portfolio) and the number of stocks held of one ticker can differ every date. tblQuotes contains security prices for each trading day (i.e. excluding weekends and non-trading days like some holidays).

What I like to have is a query, which shows me a time series of the total value of my portfolio for any time period I choose.

I hope this explanation helps so far and is sufficient. I am of course happy to answer any further question that might arise.

Thank you very much for your help.

Best regards,
JapanFreak
Attached Files
File Type: zip dbAccessForum.zip (162.1 KB, 18 views)
Reply With Quote
  #4  
Old 09-04-2007, 07:36 PM
Bilbo_Baggins_Esq Bilbo_Baggins_Esq is offline
Registered User
 
Join Date: Jul 2007
Posts: 359
Bilbo_Baggins_Esq will become famous soon enough
Here you go...

I left your original qryPortfolioHoldingsWithQuotes2 alone, but made a new query called "qryPortfolioHoldingsWithQuotes".

From it, I derived the final query "qryPortfolioValue".
There you'll find a portfolio value for every date contained in tblQuotes

The query assumes you will have a valid quote for every stock in your portfolio for every day you wish to have a total. In other words, if there is one day that does not have a quote on a particular stock in the protfolio for that day, it will be excluded from the total portfolio value.
Attached Files
File Type: zip dbAccessForum_Bilbo.zip (12.4 KB, 23 views)
__________________
If you feel that a member has helped you with your question, please remember to add to that member's reputation.

Please be considerate of all users and refrain from sending direct requests for help via Private Message.
If help sessions are conducted via Private Message, not only do you limit your access to other experts, but you also limit other's access to solutions that may help them.
Reply With Quote
  #5  
Old 09-04-2007, 11:53 PM
JapanFreak JapanFreak is offline
Registered User
 
Join Date: Aug 2007
Posts: 38
JapanFreak is on a distinguished road
Problem Solved

Hi,

thank you very much for your help! This is really the best forum of the world.

Best regards,
JapanFreak
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use SELECT CASE statement in UPDATE query in VBA Curious Modules & VBA 9 10-06-2005 02:19 AM
Date & Time difference & calculations Michv Queries 2 08-17-2005 07:42 PM
creating a KPI % calcualtion using null values vs values action Reports 3 02-23-2004 02:14 PM
Summing a list of time values bgcogen Queries 2 04-21-2002 07:29 PM
Incomplete Time series wnoullet Queries 0 10-09-2001 09:28 AM


All times are GMT -8. The time now is 06:38 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World