Professional Documents
Culture Documents
05 - Optimization
05 - Optimization
05 - Optimization
(Project !)
2 due
Sunday
AssessPortfolio -
list of stocks
(the old project t)
" " # 1 unknown
symbols & number
/ -
list of allocations
( list sums to 1)
→
- cash to invest
on
No further trades
Calculate portfolio value each
day
especially
.
Sharpe .
and method)
( see end of lecture notes 4 for #
pseudocode .
W!fKgft%M?min
Max . .
?→ don't invest?
risk or volatility
2 best risk adjusted
Sharpe Ratio
-
→
Max .
return!
This is a
good job it searches parameter
for an optimizer :
find parameters
to
space trying or maximize some
function
that minimize
Actually just minimizing
,
is
enough !
find the vector X that minimizes
So some IX) y .
y
-
,
given
-
A-ssumescalarx.yforsimplicity.PK
any two values compute f④=y x ,
,
? Examples
Is
-
entire line ab_wefCxS=y it
parabola?yes
If yes everywhere I cubic? no
x
the slope
-
? no
o
¥y
-
optimizer is multiple
If convex ,
to return minima ? no KW
guaranteedcorrect answer
a
"
"
¥
just a function ! Xz
'
sin: in:#em:c:#urate .
predictions optimizer
,
so the
er's:* differences
errors cancel
out weird
opposing
-
)
all errors proportional
1) sum of abs (errors ←
might
:
use
So we
2) sum of squared errors
worse errors
←
count more
3) root mean squared error (disproportionately)
Now project 2 is
easy
to explain .
I write
.
a
Python function : Halloa) SharpeRatio →
allocate
can 't less than 08 or more
a) you
than 1008 to a stock
b) total allocations should be 100%
your( want to invest all your cash)
optimize minimize C) ← our optimizer
Scipy .
.
an a
TD numpy array length number of stocks
. -
→ er
-
a ,
* it •
an optimization method
-
we use SLSQP
row )
(sequential least squares
most scipy
is bounds & constraints and
why? we need ,
both of those
↳ methods dont
optimization support .
Rightpimizermightrenrnbestaocat.ms
of 0.730.2 that's 1508 of
: 0.6 ,
- our cash .
parameter ,
.
e.s
(( Max,) (Mine
)
Max,)
'
Ma mins ,
bounds = min ,
, ,
,
t t
fun = o fun Z 0
If need e or constants
These two options you
the
only zero , adapt fan to work!
'
are .
besides
example constraint? X
,
the E I
←
mydescionresdtra.it
(X ,tXz) Z I ←
mathematically
-
equivalent
-
ntsisffemone
use
→ -
( x tutti
,
20
"
I can
'
ineg
'
and fun =
Cx,txz)t1
type
-
so I set
-_
pou¥q¥¥ X, Xz lxfxd-CX.tw
It
?
If V
?
+ I
Zo ?
µ
,gversiM2-1iV-#
constraint X SAME z 2 4 - 4 X -3 X
fail ✓ V
* or l ✓
paradigm
O -
I I z
-
pass .
o V V V
o o o ,