r VBA How To

Transcription

r VBA How To
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
How To Use SQL Scripts for VBA Apps
In this document we show the scripts required to set up a database, continuing with the example of a Portfolio Reporting VBA tool consisting of a
SQL/Access database linked with Excel. The Portfolio Reporting VBA tool was first outlined in a document on writing use cases.
The key advantage of using scripts is that they are re-useable, and provide a powerful means of backing up the database architecture.
The following SQL scripts will set up the database in a SQL server environment. For Access, we will need to make changes to the code, as shown below.
CREATE TABLE IF NOT EXISTS Risk_Return (
Date_ DATE NOT NULL,
Daily_Return FLOAT NULL,
PRIMARY KEY (Date_)
)
CREATE TABLE IF NOT EXISTS Portfolio_Return (
Date_ DATE NOT NULL,
PortfolioValue FLOAT NULL,
PRIMARY KEY (Date_),
INDEX FK_Portfolio_Return_DATE
CONSTRAINT FK_Portfolio_Return_DATE
FOREIGN KEY (Date_)
REFERENCES Risk_Return (Date_)
1
Nyasha Madavo, VBA Developer.net
Portfolio Reporting VBA App: Creating a Database using SQL Scripts
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
ON DELETE NO ACTION,
)
CREATE TABLE IF NOT EXISTS Asset_Return (
Date_ DATE NOT NULL,
AssetID VARCHAR (30) NOT NULL,
AssetHoldings FLOAT NULL,
PRIMARY KEY (Date_, AssetID)
CONSTRAINT FK_Asset_Return_DATE
FOREIGN KEY (Date_)
REFERENCES Risk_Return (Date_)
ON DELETE NO ACTION,
)
SQL Scripts for Access Database
CREATE TABLE Risk_Return (
Date_ DATE
NOT NULL CONSTRAINT PK_DateID PRIMARY KEY,
Daily_Return FLOAT NULL)
CREATE TABLE Portfolio_Return (
2
Nyasha Madavo, VBA Developer.net
Portfolio Reporting VBA App: Creating a Database using SQL Scripts
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
Date_
DATE
NOT NULL CONSTRAINT PK_DateID PRIMARY KEY
REFERENCES Risk_Return (Date_),
PortfolioValue FLOAT)
CREATE TABLE Asset_Return (
Date_
DATE NOT NULL CONSTRAINT PK_DateIDAssetID
REFERENCES Risk_Return (Date_),
AssetID VARCHAR (30) NOT NULL ,
AssetHoldings FLOAT NULL,
PRIMARY KEY (Date_, AssetID)
)
Next Steps
Having created the tables, we then set up stored procedures for calculating the risk-return measures of the Portfolio.
How VBA Developer.net Can Save You Time and money
You can get complete Excel apps from VBA Developer.net containing the code in this document, customisation, VBA development of any
Excel, Access and Outlook apps, as well as C# and C++ add-ins and technical documentation.
Visit VBA Developer.net
Examples of VBA documents from VBA Developer.net
How to build a Black Scholes VBA Option Pricer
3
Nyasha Madavo, VBA Developer.net
Portfolio Reporting VBA App: Creating a Database using SQL Scripts
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
How to build a Black Scholes C# Option Pricer
How to build a Black Scholes VBA Option Pricer for FX Options
How to build a Black Scholes VBA Option Pricer for Equity Options
How to build a Black Scholes VBA Option Pricer using Monte Carlo Simulation
How to build a Black Scholes VBA Option Pricer for Binary Options
How to build a Black Scholes VBA Option Pricer for Equity Barrier Options
How to build a Black Scholes VBA Option Pricer for Exotic Asian Options
How to build a Black Scholes VBA Option Pricer for Exotic Lookback Options
How to build an Equity Option Pricer using the Binomial Tree in Excel VBA
How to code a Choleskey Decomposition in VBA (Numerical Methods for Excel)
3 ways to sort in VBA
How to Code a Multivariate Value at Risk (VaR) VBA Monte Carlo Simulation
How To Code the Newton-Raphson Method in Excel VBA
How to Model Volatility Smiles, Volatility Term Structure and the Volatility Surface in Excel VBA
How To Write Use Cases for a Portfolio Reporting VBA Tool
4
Nyasha Madavo, VBA Developer.net
Portfolio Reporting VBA App: Creating a Database using SQL Scripts
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
How To Write a User Interface Model For a Portfolio Reporting VBA Tool
How To Create a Semantic Object Model For a Portfolio Reporting VBA Tool
How To Normalise a Database For VBA Apps
How To Create a Database using SQL Scripts for a Portfolio Reporting VBA App
How to Write Stored Procedures in SQL/Access/VBA for a Portfolio Reporting VBA App
How to Use Cursors in SQL for a Portfolio Reporting VBA Tool
How to Move Data from Access to Excel with SQL for a Portfolio Reporting VBA App
Portfolio Reporting VBA Tool: Inserting Data into SQL/Access Databases from Excel
Portfolio Reporting VBA Tool: Connecting Excel with SQL & Access Databases
How To Design Classes For an Option Pricer in VBA: UML Concepts
How To Design Classes for Object Orientated VBA Programming
5
Nyasha Madavo, VBA Developer.net
Portfolio Reporting VBA App: Creating a Database using SQL Scripts