Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500
Robust Arbitrage Model
Notation:
K = number of scenarios
0, 1, 2, . . . , n: indices for assets (cash is 0)
r = riskfree interest rate
oj = todays price for asset j,
kj = expected value for kj , the price for asset j in scenario k 1 (0 j K
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
NonRobust ArbitrageDetection Problem
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <windows.h>
int does_it_exist(char *filename);
int readfile(char *filename, double *pv, int *ps, int
*pc);
int writefile(do
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
How to solve simple QPs
The problem we discussed in class had the following general structure:
Minimize
i
2
i x2 + 2
i
i<j
ij xi xj
i
i xi , (*)
Subject to the constraints:
i
xi = 1, and
li xi ui , for all i.
The method we discussed in class consisted of
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500
Arbitrage through Linear Programming
We are given:
Two securities: 1 and 2, and three scenarios: 1, 2, 3. Prices:
today Scen. 1 Scen. 2 Scen. 3
1
10
7
19
9
2
8
6
8
8
Is arbitrage possible?
We take a position today, we close it tomorrow
What i
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
More on UserForms
There are many capabilities that can be added to UserForms lots of material on the web.
Here we will single out a few useful features.
Text Boxes. A text box is a window into which the user can type anything.
In the Toolbox this shows up
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500
ValueatRisk of Portfolios under the Robust Arbitrage
Model
In past lectures we have seen the following model
K = number of scenarios
0, 1, 2, . . . , n: indices for assets (cash is 0)
r = riskfree interest rate
0j = todays price for asset
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500
Quick Review of the Principal Components Method
Suppose Q is the covariance matrix for the returns of n assets. Then Q is symmetric
(qij = qji for all indices i, j) and positivesemidenite (v T Qv 0 for any vector v Rn
this is denoted Q 0). We
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
Multithreading under Windows a primer
Multithreading always involves the manipulation of memory objects (or, more
appropriately, kernel objects) such as threads and mutexes. Here are some salient
facts about how to use these objects with MSVC+, in a conso
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500: A second algorithm for meanvariance QPs
The problem we are interested in is as follows:
.
Minimize F (x) =
i
2
ii x2 + 2
i
i<j
ij xi xj
i
i xi ,
Subject to the constraints:
j
xj = 1, and
lj xj uj , for all j.
Step 1. Achieve feasibility
This
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
Trade Execution and Dynamic Programming
Suppose we want to sell a large number N of shares of some stock.
Assume the current price of the stock is P0 is it reasonable to
expect that we will receive, from our trade, a cash flow of P0N?
The answer, in gener
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
HOW TO DESIGN, BUILD AND TEST A DLL
Step 0.
First, write a standard program that includes all the functionality that want
to export, and also includes a way to test the functionality, by example by reading data
from a file and making calls to the function
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
IEOR 4500  Realistic Portfolio Constraints
1. Long/short portfolios. Here we consider portfolios where the assets can take long or short
positions. In addition, when we construct the portfolio we already have a vector of positions, xstart
which could inc
IEOR 4500 Introduction to Portfolio Optimization
References: The classical reference is Portfolio Selection: Efficient Diversification of Investments, by Harry Markowitz. A more modern reference is: Modern Portfolio Theory and Investment Analysis, by Elto
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
912) chmc M00160) ,4:an >
p
a . .qu (MM) , M302. .
~ 3 l m Wm:
11 .  M ; ' 4.2
A ' ) . 7.2 1" ' = n ' a. ' ~ 21:? I "112" *'
'zl,whm
LI mnnr Inn' 51'
.190 mm; 
,1
r W
4o . w u may 1mm" 1w M MN. mamwmw
I .V
Applications Programming for Financial Engineering
IEOR 4500

Fall 2014
Formulas for probability theory SF2940 (23
pages)
These pages (+ Appendix 2 of Gut)
are permitted as assistance at the exam.
6 september 2011
Selected formulae of probability
Bivariate probability
Conditional expectation w.r.t a Sigma field
Transforms
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
Assignment 1, due September 23
For this assignment you need to first install the Yahoo finance package and then use the Python script I provided to download the Russell 1000 closing prices for a sixmonth period (any six month period).
Then, for each a
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
FOXA
FOX
DDD
MMM
AAN
ABT
ABBV
ACHC
ACN
ACE
ATVI
AYI
ADBE
ADT
AAP
ACM
AES
AET
AMG
AFL
AGCO
A
AGIO
GAS
AL
APD
ARG
AKAM
AKRX
ALK
ALB
AA
ALR
ARE
ALXN
ALGN
ALKS
Y
ATI
ALLE
AGN
ADS
LNT
AWH
ALSN
MDRX
ALL
ALLY
ALNY
ALTR
MO
AMZN
AMCX
DOX
UHAL
AEE
AAL
ACC
AGNC
AEP
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
A case with Type A arbitrage
Data:
2 securities + cash, 2 scenarios (plus today's)
interest = 10%
for each security, today's price followed by each
scenario price
sec 1:
sec 2:
5
2
48
2.5 5.5
LP file:
Minimize x0 + 5x1 + 2x2
Subject to:
scenA: 1.1x0 + 4x1
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
Addresses, arrays, pointers, et al
In this brief writeup we review basic memory concepts as they
occur in the C language you should look at the KernighanRitchie
book.
We may think of memory as a onedimensional collection of bits
(each bit has a zero or
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
C+ style Output and Memory Allocation
/*
This program reads a file that has the following
structure:
N
nnn xxxx
nnn xxxx
.
nnn xxxx
END
where each "nnn" is a nonnegative integer and xxxx is
a floatingpoint
number, and "N" is the number of nnn entries
The
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
Illustration of the Impact of Effective Memory Use
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
cfw_
int i, j, rows, columns, h, runs;
double *v, *w;
if(argc < 2)cfw_
printf("need a 'c' or 'r' argument\n"); goto BACK;
rows = 50
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
IEOR 4500
Arbitrage through Linear Programming
We are given:
Two securities: 1 and 2, and three scenarios: 1, 2, 3. Prices:
today Scen. 1 Scen. 2 Scen. 3
1
10
7
19
9
2
8
6
8
8
Is arbitrage possible?
We take a position today, we close it tomorrow
What i
Applications Programming for Financial Engineering
IEOR 4500

Fall 2012
UserForms
UserForms are a tool for providing graphical interaction to an Excel spreadsheet. See, for
additional materials, http:/www.fontstuff.com/vba/vbatut09b.htm. In this document we
will go over some of the basic steps and ideas.
Here is a picture of