JapanFreak
Registered User.
- Local time
- Today, 14:00
- Joined
- Aug 25, 2007
- Messages
- 45
Dear All,
sorry, I need your help again please… The question below builds on a problem earlier today (http://www.access-programmers.co.uk/forums/showthread.php?t=209691). Again I have attached a small sample database which helps to make my problem clearer.
I have a database with a table called tblTrades in which I collect data on stock market transactions:
Note:
If iQuantity > 0 it is a Buy, if iQuantity < 0 it is a Sell.
The combination of the following two queries allows me to retrieve the book value of my stock portfolio at a specific date (e.g. 01/04/2011):
Note:
If sum(T.iQuantity) > 0 the trade is still open, i.e. the stock is part of the portfolio
If sum(T.iQuantity) = 0 the trade has been closed, i.e. the stock is no longer part of the portfolio
Now I am looking for a way to formulate a query which gives me a time series of the book values of my portfolio over time.
Actually, some time ago user Bilbo helped me with a related problem (http://www.access-programmers.co.uk/forums/showthread.php?t=134869) but I struggle to adjust his suggestion to my current problem.
Is there anybody who can help me here?
Thanks for your help –
JapanFreak
sorry, I need your help again please… The question below builds on a problem earlier today (http://www.access-programmers.co.uk/forums/showthread.php?t=209691). Again I have attached a small sample database which helps to make my problem clearer.
I have a database with a table called tblTrades in which I collect data on stock market transactions:
Code:
[COLOR=black][FONT=Arial][FONT=Arial]TradeID – dtDate – sTicker – iQuantity – dPrice[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]1 – 01/03/2011 – A – 10 – 50.00[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]2 – 01/03/2011 – B – 10 – 25.00[/FONT][/FONT][/COLOR]
[FONT=Arial][COLOR=black][FONT=Arial]…[/FONT][/COLOR][/FONT]
Note:
If iQuantity > 0 it is a Buy, if iQuantity < 0 it is a Sell.
The combination of the following two queries allows me to retrieve the book value of my stock portfolio at a specific date (e.g. 01/04/2011):
Code:
[B][COLOR=black][FONT=Arial][FONT=Arial]qryPortfolioBV[/FONT][/FONT][/COLOR][/B]
[COLOR=black][FONT=Arial][FONT=Arial]SELECT Sum(T.iQuantity*T.dPrice) AS dBV[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]FROM qryPortfolioHoldingsDate AS Q LEFT JOIN tblTrades AS T ON Q.sTicker=T.sTicker[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]WHERE T.dtDate<=#1/4/2011#;[/FONT][/FONT][/COLOR]
[B][COLOR=black][FONT=Arial][FONT=Arial]qryPortfolioHoldingsDate[/FONT][/FONT][/COLOR][/B]
[COLOR=black][FONT=Arial][FONT=Arial]SELECT T.sTicker, sum(T.iQuantity) AS iPosition[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]FROM tblTrades AS T[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]WHERE dtDate<=#1/4/2011#[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]GROUP BY T.sTicker[/FONT][/FONT][/COLOR]
[COLOR=black][FONT=Arial][FONT=Arial]HAVING sum(T.iQuantity)>0;[/FONT][/FONT][/COLOR]
Note:
If sum(T.iQuantity) > 0 the trade is still open, i.e. the stock is part of the portfolio
If sum(T.iQuantity) = 0 the trade has been closed, i.e. the stock is no longer part of the portfolio
Now I am looking for a way to formulate a query which gives me a time series of the book values of my portfolio over time.
Actually, some time ago user Bilbo helped me with a related problem (http://www.access-programmers.co.uk/forums/showthread.php?t=134869) but I struggle to adjust his suggestion to my current problem.
Is there anybody who can help me here?
Thanks for your help –
JapanFreak