Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab 16 - Optimization - Nonlinear - Part 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

Optimization for Finance

With ROI Package (Part 2: Nonlinear Optimization)


Difficulty: Intermediate

Matt Dancho & David Curry


Business Science Learning Lab
Learning Lab
Structure

● Presentation
(20 min)

● Demo’s
(20 min)

● Pro-Tips
(20 mins)
Reproducible Finance with R
“Without the BSU courses, I couldn’t do what
I’m doing.”
Success Story
Luis Francisco Gomez
Lopez

- Economist & Student


- Started courses 2 months
ago
- Was using Excel
- Completely switched to
- Latest report & homework
assignment
- TOTAL TRANSFORMATION!

#BusinessScienceSuccess
Agenda
2 Parts
Part 1 (Lab 15)

Product Mix Problem

Linear Programming

If you missed this, join


Learning Labs PRO
Part 2 (Today)
Stock Portfolio Optimization

Nonlinear Programming
Lab 15
R’s Optimization Toolchain, Part 1
Learning Labs
Lab 14
PRO Customer Churn Survival
Analysis
Every 2-Weeks Lab 13
Wrangling 4.6M Rows of
1-Hour Course Financial Data w/ data.table

Recordings + Code + Slack Lab 12


How I built anomalize
$19/month
Lab 11
Market Basket Analysis w/
recommenderLab
university.business-science.io
Lab 10
Building API’s with plumber &
postman

Lab 9
Finance in R with tidyquant
R in Industry
The power of R for trading
The power of
R for Trading
R is the best language in the
world for doing rapid
financial analysis

https://www.linkedin.com/pulse/power-r-trading-part-1-ralph-sueppel/
Financial Case Study
Optimize Stock Portfolio
Building a Financial Portfolio

Historical Stock Prices


We analyze the historical stock prices for
5 Stocks:

AAPL, AMZN, FB, GOOG, & NFLX

How do we determine an optimal


portfolio mix?

https://business-science.github.io/tidyquant/
Modern Portfolio Theory

Minimize Variance
Harry Markowitz - Nobel Prize

What is the lowest x


portfolio variance that I
can achieve a given
Q
return objective?
Efficient Frontier - What happens when we minimize risk

Efficient Frontier
What happens when we
adjust the
Portfolio Return Objective?

Quantitative Decision
Making + Optimization
Optimization (Recap)
80/20 Concepts
Terminology

1 2 3
Objectives Constraints Decision Variables

The goal of the model Decision Rules for the Your problem’s Frame of
model Reference
Always Maximize or
Minimize. Restricts the decision The parameters that your
variables to boundaries optimization model
adjusts
Excel

Data

Decision Variables Calculation


(adjusted values)

Constraints

Goal
Types of Optimization Models

Linear Quadratic Nonlinear


● Fastest solutions ● Fast solutions ● Easy to conceptualize
● Easy to conceptualize ● Difficult to Conceptualize ● Super Flexible
● Analysis limited to ● Requires formulation as a ● Cannot use linear solvers
aggregations, constant quadratic function ● Slower solutions
multiplications, etc ● Can get suboptimal results
● Many problems don’t fit (local vs global maxima)
this mold (e.g. take
correlation of something)
Types of Optimization Models

Linear Quadratic Nonlinear


● Fastest solutions ● Fast solutions ● Easy to conceptualize
● Easy to conceptualize ● Difficult to Conceptualize ● Super Flexible
● Analysis limited to ● Requires formulation as a ● Cannot use linear solvers
aggregations, constant quadratic function ● Slower solutions
multiplications, etc ● Can get suboptimal results
● Many problems don’t fit (local vs global maxima)
this mold (e.g. take
correlation of something)

Part 1 Part 2
Process & Tools
What we need to know
Financial Optimization Modeling
Step-By-Step

Start Finish
1 2 3

tidyquant & dplyr ROI purrr & ggplot2


Retrieve & Manipulate Data Nonlinear Optimization Iteration & Visualization
Financial Optimization Modeling
Step-By-Step

Start Finish
1 2 3

tidyquant & dplyr ROI purrr & ggplot2


Retrieve & Manipulate Data Nonlinear Optimization Iteration & Visualization

101 & Lab 13 NEW 101 & 201


ROI Package
80/20 Concepts & Important
Operations
Using ROI
Decision Variables (adjusted variables)
ROI Asset Weights for each stock
[w_aapl, w_amzn, w_fb, w_goog, w_nflx]

Conversion process is a bit trickier


than what we learned in Part 1

Need to think in terms of Matrix


Calculations

Nonlinear programming has 4


Super Powers

● F_objective
○ Minimize portfolio variance calculation
● F_constraint - Functional Constraint
○ Inputs asset weights, outputs port
○ Return objective set to 40% per year
● L_constraint - Linear Constraint
○ Bounding the weights
Nonlinear Super Power #1
Functional Objective

http://roi.r-forge.r-project.org/introduction.html
Nonlinear Super Power #2
Functional Constraints

http://roi.r-forge.r-project.org/introduction.html
Nonlinear Super Power #3
Linear Constraints

http://roi.r-forge.r-project.org/introduction.html
Nonlinear Super Power #4
Put it all together
Can combine linear (matrix) & nonlinear programming (functions)
Demo
Optimizing a Stock Portfolio
AAPL, AMZN, FB, GOOG, NFLX
Optimization
Secret Tactics & Pro Tips
People get frustrated with

Optimization
Because they fail to start simple
Pro Tip
Design in Excel, then Convert to R

When starting out...

Pros: Data
Sometimes Excel is easier to Calculation
conceptualize

Cons:
● Excel cannot scale (try to do
iterative analysis)
● Excel cannot scale (try to add
1 more stock)
● Excel has difficulties with
nonlinear problems
Pro Tip
Design in Excel, then Convert to R

When starting out...

Cons:
Sometimes R is more difficult to
conceptualize

Pros:
● R can scale (try to do iterative
analysis)
● R can scale (try to add 1 more
stock)
● R is really good with
nonlinear problems
Data Science + Decision Science
Learning Plan
Financial Optimization Modeling
Step-By-Step

Start Finish
1 2 3

tidyquant & dplyr ROI purrr & ggplot2


Retrieve & Manipulate Data Nonlinear Optimization Iteration & Visualization

101 & Lab 13 Lab 16 101 & 201


dplyr + tidyquant

Lab 13

101
ROI

Lab 16
ggplot2 & purrr

101 + 201

101 + 201
Business Science University
Our program that will TRANSFORM YOU in weeks, not years.
The program that will deliver YOUR Transformation
-TRACK 3-Course R-Track System
Business Analysis with R Data Science For Business with R R Shiny Web Apps For Business
(DS4B 101-R) (DS4B 201-R) (DS4B 102-R)

Project-Based Courses with Business Application


Data Science Foundations Machine Learning & Business Consulting Web Application Development
7 Weeks 10 Weeks 4 Weeks

Business Science University


R-Track
Key Benefits
Business Analysis with R
- Fundamentals - Weeks 1-5 (25 hours
of Video Lessons) (DS4B 101-R)
- Data Manipulation (dplyr)
- Time series (lubridate) Data Science Foundations
- Text (stringr) 7 Weeks
- Categorical (forcats)
- Visualization (ggplot2)
- Programming & Iteration (purrr)
- 3 Challenges

- Machine Learning - Week 6


(8 hours of Video Lessons)
- Clustering (3 hours)
- Regression (5 hours)
- 2 Challenges
Business Reporting

- Learn Business Reporting - Week 7


- RMarkdown & plotly Functional
Programming &
- 2 Project Reports: Modeling
1. Product Pricing Algo
2. Customer Segmentation

Visualization
Data Cleaning &
Manipulation
Key Benefits
End-to-End Churn Project Data Science For Business
Understanding the Problem & (DS4B 201-R)
Preparing Data - Weeks 1-4
Machine Learning & Business Consulting
- Project Setup & Framework
- Business Understanding / Sizing
10 Weeks
Problem
- Tidy Evaluation - rlang
- EDA - Exploring Data -GGally, skimr
- Data Preparation - recipes
- Correlation Analysis
- 3 Challenges

Machine Learning - Weeks 5, 6, 7


- H2O AutoML - Modeling Churn
- ML Performance
- LIME Feature Explanation Advanced Data
Science
Advanced Functional
Programming &

Return-On-Investment - Weeks 7, 8, 9 Modeling

- Expected Value Framework


- Threshold Optimization
- Sensitivity Analysis
- Recommendation Algorithm Advanced
Advanced Data
Visualization
Wrangling
Key Benefits
Shiny Apps for Business
Learn Shiny & Flexdashboard
(DS4B 102-R)
- Build Applications Web Application Development
- Learn Reactive Programming
- Integrate Machine Learning
4 Weeks

App #1: Predictive Pricing App


- Model Product Portfolio
- XGBoost Pricing Prediction
- Generate new products instantly

App #2: Sales Dashboard with


Demand Forecasting
- Model Demand History
- Segment Forecasts by Product &
Web Apps
Customer
- XGBoost Time Series Forecast
- Generate new forecasts instantly Machine
Learning
Testimonials

“Your program allowed me to cut down to


50% of the time to deliver solutions to my
clients.”
-Rodrigo Prado, Managing Partner Big Data Analytics &
Strategy at Genesis Partners
Achieve
“I can already apply a lot of the early
Results that
gains from the course to current working Matter to
projects.”
-Adam Mitchell, Data Analyst with Eurostar
the
Business
“My work became 10X easier. I can spend
quality time asking questions rather than
wasting time trying to figure out syntax.”
-Mohana Chittor, Data Scientist with Kabbage, Inc
15% OFF PROMO Code: learninglabs

-TRACK BUNDLE
Begin Learning Today
university.business-science.io

You might also like