Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization...
Transcript of Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization...
![Page 1: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/1.jpg)
Kecerdasan Bisnis Terapan
Prescriptive Analytics
Optimization and Simulation
HusniLab Riset JTIF UTM
Sumber awal httpmailtkuedutwmydayteaching1071BI1071BI08_Business_Intelligencepptx
Business Intelligence (BI)
2
Introduction to BI and Data Science
Descriptive Analytics
Predictive Analytics
Prescriptive Analytics
1
3
5
4
Big Data Analytics
2
6 Future Trends
Prescriptive Analytics Optimization and
Simulation
3
Outline
4
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
5
Business Analytics and Prescriptive Analytics
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 2: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/2.jpg)
Business Intelligence (BI)
2
Introduction to BI and Data Science
Descriptive Analytics
Predictive Analytics
Prescriptive Analytics
1
3
5
4
Big Data Analytics
2
6 Future Trends
Prescriptive Analytics Optimization and
Simulation
3
Outline
4
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
5
Business Analytics and Prescriptive Analytics
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 3: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/3.jpg)
Prescriptive Analytics Optimization and
Simulation
3
Outline
4
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
5
Business Analytics and Prescriptive Analytics
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 4: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/4.jpg)
Outline
4
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
5
Business Analytics and Prescriptive Analytics
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 5: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/5.jpg)
5
Business Analytics and Prescriptive Analytics
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 6: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/6.jpg)
Prescriptive Analytics Model Examples
bull Modeling is a key element for prescriptive analytics
bull Employ a mathematical model to be able to recommend a decision for any realistic problem
bull Building a probability-based response maximization model with the budget as a constraint would give us the information we are seeking
6Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 7: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/7.jpg)
Identification of the Problem and Environmental Analysis
bull Environmental scanning and analysis
ndash Monitoring scanning and interpretation of collected information
bull Business intelligencebusiness analytics (BIBA) tools can help identify problems by scanning for them
bull Variable Identification
bull Forecasting (Predictive Analytics)
7Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 8: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/8.jpg)
Categories of Models
8Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 9: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/9.jpg)
Structure of Mathematical Models for Decision Support
9
bull The Components of Decision Support Mathematical Models
bull The Structure of Mathematical Models
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 10: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/10.jpg)
The General Structure of a Quantitative Model
10Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 11: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/11.jpg)
Examples of Components of Models
11Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 12: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/12.jpg)
The Structure of Mathematical Models
12
A very simple financial model is
P = R - C
where P = profit R = revenue and C = cost
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 13: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/13.jpg)
The Structure of Mathematical Models
13
Financial model (present-value cash flow model)
P = F (1 + i)n
where P = present value F = a future single
payment in dollars i = interest rate (percentage)
and n = number of years
P = 100000 (1 + 01)5 = 62092Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 14: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/14.jpg)
Certainty Uncertainty and Risk
14
bull Decision Making under Certainty
bull Decision Making under Uncertainty
bull Decision Making under Risk (Risk Analysis)
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 15: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/15.jpg)
The Zones of Decision Making
15Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 16: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/16.jpg)
Mathematical Programming Optimization
16
bull Mathematical programming
ndash a family of tools designed to help solve managerial problems in which the decision maker must allocate scarce resources among competing activities to optimize a measurable goal
bull Linear programming (LP) is the best-known technique in a family of optimization tools called mathematical programming
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 17: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/17.jpg)
Mathematical Model of a Product-Mix Example
17Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 18: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/18.jpg)
Prescriptive Analytics Operations researchManagement Science
18
bull Multiple Goals
bull Sensitivity Analysis
bull What-If Analysis
bull Goal Seeking
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 19: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/19.jpg)
Decision Analysis with Decision Tables and Decision Trees
19
bull Decision tables
ndash conveniently organize information and knowledge in a systematic tabular manner to prepare it for analysis
bull Decision tree
ndash shows the relationships of the problem graphically and can handle complex situations in a compact form
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 20: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/20.jpg)
Investment Problem Decision Table Model
20Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 21: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/21.jpg)
Multiple Goals
21Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 22: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/22.jpg)
The Process of Simulation
22Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 23: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/23.jpg)
Discrete versus Continuous Probability Distributions
23Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 24: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/24.jpg)
Simulation Types
24
bull Monte Carlo Simulation
bull Discrete Event Simulation
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 25: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/25.jpg)
Visual Interactive Simulation
25
bull Conventional Simulation Inadequacies
bull Visual Interactive Simulation (VIS)
ndashVisual Interactive Modeling (VIM)
bull Visual Interactive Models and DSS
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 26: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/26.jpg)
Simulation Software
26
bull Analytica (Lumina Decision Systems luminacom)
bull Excel add-ins Crystal Ball
bull RISK (Palisade Corp palisade com)
bull Arena
bull Simio (simiocom)
bull ExtendSim (extendsimcom)
bull SAS JMP
Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 27: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/27.jpg)
Monte Carlo Simulation
27Source Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 28: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/28.jpg)
28
Monte Carlo Simulation to Forecast Stock Prices
httpscolabresearchgooglecomdrive1lwXt0TlidwF2jhPPE7tte2TH-JWb9QFk
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 29: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/29.jpg)
Python Pandas for Finance
29Source httpsmapattackwordpresscom20170212using-python-for-stocks-1
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 30: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/30.jpg)
The Quant Finance PyData Stack
30Source httpnbviewerjupyterorgformatslidesgithubquantopianpyfolioblobmasterpyfolioexamplesoverview_slidesipynb5
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 31: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/31.jpg)
31
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 32: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/32.jpg)
32
Python in Google Colabhttpscolabresearchgooglecomdrive1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 33: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/33.jpg)
pip install pandas_datareader
33
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 34: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/34.jpg)
conda install pandas-datareader
34
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 35: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/35.jpg)
35
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 36: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/36.jpg)
36
pip install pandas_datareader
import pandas_datareaderdata as web
import datetime as dt
Read Stock Data from Yahoo Finance
end = dtdatetime(2017 12 31)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Yahoo Finance
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 37: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/37.jpg)
37
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth
endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 38: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/38.jpg)
38
df[Adj Close]plot(legend=True figsize=(12
8) title=AAPLrsquo label=Adj Close)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 39: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/39.jpg)
39
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0)
rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100)
rowspan=2 colspan=9)
topplot(dfindex df[Adj Close]
color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 40: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/40.jpg)
40
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 41: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/41.jpg)
41
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna()
bins=50 color=purple)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 42: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/42.jpg)
42
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 43: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/43.jpg)
43
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean()
5 days
df[MA20] = df[Adj
Close]rolling(20)mean() 20 days
df[MA60] = df[Adj
Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj
Close]MA05 df[MA05]MA20 df[MA20]
MA60 df[MA60])
df2plot(figsize=(12 9) legend=True
title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 44: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/44.jpg)
44
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 45: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/45.jpg)
45
pip install pandas_datareader
import pandas as pd
import pandas_datareaderdata as web
import matplotlibpyplot as plt
import seaborn as sns
import datetime as dt
matplotlib inline
Read Stock Data from Yahoo Finance
end = dtdatetimenow()
start = dtdatetime(endyear-2 endmonth endday)
start = dtdatetime(2016 1 1)
df = webDataReader(AAPL yahoo start end)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
df[Adj Close]plot(legend=True figsize=(12 8) title=AAPL label=Adj Close)
pltfigure(figsize=(129))
top = pltsubplot2grid((129) (0 0) rowspan=10 colspan=9)
bottom = pltsubplot2grid((129) (100) rowspan=2 colspan=9)
topplot(dfindex df[Adj Close] color=blue) dfindex gives the dates
bottombar(dfindex df[Volume])
set the labels
topaxesget_xaxis()set_visible(False)
topset_title(AAPL)
topset_ylabel(Adj Close)
bottomset_ylabel(Volume)
pltfigure(figsize=(129))
snsdistplot(df[Adj Close]dropna() bins=50 color=purple)
simple moving averages
df[MA05] = df[Adj Close]rolling(5)mean() 5 days
df[MA20] = df[Adj Close]rolling(20)mean() 20 days
df[MA60] = df[Adj Close]rolling(60)mean() 60 days
df2 = pdDataFrame(Adj Close df[Adj Close]MA05 df[MA05]MA20 df[MA20] MA60 df[MA60])
df2plot(figsize=(12 9) legend=True title=AAPL)
df2to_csv(AAPL_MAcsv)
fig = pltgcf()
figset_size_inches(12 9)
figsavefig(AAPL_plotpng dpi=300)
pltshow()
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 46: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/46.jpg)
46
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 47: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/47.jpg)
47Source httpswwwquandlcomtoolspython
pip install quandl
import quandl quandlApiConfigapi_key = YOURAPIKEY
df = quandlget(WIKIAAPL start_date=2016-01-
01 end_date=2017-12-31)
dfto_csv(AAPLcsv)
dffrom_csv(AAPLcsv)
dftail()
Finance Data from Quandl
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 48: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/48.jpg)
48httpfinanceyahoocomqs=AAPL
Yahoo Finance Symbols AAPL Apple Inc (AAPL)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 49: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/49.jpg)
Dow Jones Industrial Average (^DJI)
49httpfinanceyahoocomchart^DJI
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 50: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/50.jpg)
TSEC weighted index (^TWII) - Taiwan
50httpfinanceyahoocomchart^TWII
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 51: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/51.jpg)
51httpfinanceyahoocomchart2330TW
Yahoo Finance Charts TSMC (2330TW)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 52: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/52.jpg)
52
import pandas as pd
import pandas_datareaderdata as web
df = webDataReader(AAPL data_source=yahoo
start=112010 end=3212017)
dfto_csv(AAPLcsv)
dftail()
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 53: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/53.jpg)
53
df = webDataReader(GOOG
data_source=yahoo start=111980
end=3212017)
dfhead(10)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 54: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/54.jpg)
54
dftail(10)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 55: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/55.jpg)
55
dfcount()
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 56: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/56.jpg)
56
dfix[2015-12-31]
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 57: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/57.jpg)
57
dfto_csv(2330TWYahooFinanceDatacsv)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 58: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/58.jpg)
58
import fix_yahoo_finance as yf
data = yfdownload(^TWII start=2017-07-01 end=2017-11-15)
datato_csv(TWII_201707_201711csv)
datatail()
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 59: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/59.jpg)
dfloc[startend]
59
df = dfloc[2017-10-012017-11-15]
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 60: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/60.jpg)
60
import matplotlibpyplot as plt
matplotlib inline
import fix_yahoo_finance as yf
df = yfdownload(^TWII start=2000-01-01 end=2017-11-15)dfto_csv(YF_TWII_2000_2017csv)
print(dfhead())
fig = pltfigure(figsize=(169))df[Adj Close]plot()
figshow()
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 61: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/61.jpg)
import matplotlibpyplot as plt
from matplotlibfinance
import candlestick_ohlc
61Source httpsmatplotliborgexamplespylab_examplesfinance_demohtml
candlestick_ohlc
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 62: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/62.jpg)
62Source httpsntguardianwordpresscom20160919introduction-stock-market-data-python-1
import matplotlibpyplot as plt
from matplotlibfinance import candlestick_ohlc
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 63: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/63.jpg)
daily_to_weekly
63
Convert Daily Data to Weekly Data
def daily_to_weekly(df)
dfWeekly = daily_to_weekly(df)dfsort_index(axis=0 level=None ascending=True inplace=True)
Open = dfOpenresample(W-Fri)first() W W-MON W-Fri
High = dfHighresample(W-Fri)max()
Low = dfLowresample(W-Fri)min()
Close = dfCloseresample(W-Fri)last()
Volume = dfVolumeresample(W-Fri)sum()
Adj_Close = df[Adj Close]resample(W-Fri)last()
dfWeekly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfWeekly = dfWeekly[pdnotnull(dfWeekly[Adj Close])]
return dfWeekly
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 64: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/64.jpg)
daily_to_monthly
64
Convert Daily Data to Monthly Data
def daily_to_monthly(df)
dfMonthly = daily_to_monthly(df)
Open = dfOpenresample(M)first()
High = dfHighresample(M)max()
Low = dfLowresample(M)min()
Close = dfCloseresample(M)last()
Volume = dfVolumeresample(M)sum()
Adj_Close = df[Adj Close]resample(M)last()dfMonthly = pdconcat([Open High Low Close Volume Adj_Close] axis=1)
dfMonthly = dfMonthly[pdnotnull(dfMonthly[Adj Close])]
return dfMonthly
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 65: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/65.jpg)
TA-LibTechnical Analysis Library
65httpta-liborg
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 66: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/66.jpg)
Stochastic Oscillator (KD)
66
Stochastic oscillator D
def KDJ(df n m1 m2)
KDJ(df 9 3 3)
KDJ_n = n
KDJ_m1 = m1
KDJ_m2 = m2
df[Low_n] = pdrolling_min(df[Low] KDJ_n)
df[Low_n]fillna(value=pdexpanding_min(df[Low]) inplace=True)
df[High_n] = pdrolling_max(df[High] KDJ_n)
df[High_n]fillna(value=pdexpanding_max(df[High]) inplace=True)
df[RSV] = (df[Close] - df[Low_n]) (df[High_n] - df[Low_n]) 100
df[KDJ_K] = pdewma(df[RSV] KDJ_m1)
df[KDJ_D] = pdewma(df[KDJ_K] KDJ_m2)
df[KDJ_J] = 3 df[KDJ_K] - 2 df[KDJ_D]
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 67: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/67.jpg)
Bollinger Bands
67
Bollinger Bands
def BBANDS20(df n)
MA = pdSeries(pdrolling_mean(df[Close] n))
MSD = pdSeries(pdrolling_std(df[Close] n))
b1 = 4 MSD MA
B1 = pdSeries(b1 name = BollingerB_ + str(n))
df = dfjoin(B1)
b2 = (df[Close] - MA + 2 MSD) (4 MSD)
B2 = pdSeries(b2 name = Bollingerb_ + str(n))
df = dfjoin(B2)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 68: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/68.jpg)
Bollinger Bands
68
BB Bollinger Bands BB_20
def BB_20(df)
df[BB_MA20] = pdstatsmomentsrolling_mean(df[Adj Close] 20)
df[BB_SD20] = pdstatsmomentsrolling_std(df[Adj Close]20)
df[BB_UpperBand] = df[BB_MA20] + (df[BB_SD20]2) Default 2SD
df[BB_LowerBand] = df[BB_MA20] - (df[BB_SD20]2)
df[BB_PB] = (df[Adj Close] - df[BB_LowerBand]) (df[BB_UpperBand] -
df[BB_LowerBand])
df[BB_BW] = (df[BB_UpperBand] - df[BB_LowerBand]) df[BB_MA20]
df[BB_UpperBand_1SD] = df[BB_MA20] + (df[BB_SD20])
df[BB_LowerBand_1SD] = df[BB_MA20] - (df[BB_SD20])
BB_PB Bollinger Band Percent b (PB)
BB_BW Bollinger Band Band Width (BW)
return df
Source httpswwwquantopiancompoststechnical-analysis-indicators-without-talib-code
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 69: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/69.jpg)
AI + VDI POC
69
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 70: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/70.jpg)
AI + VDI POSTensorFlow Models
bull M1 Basic Classification (Image Classification) (65 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_classificationipynb
bull M2 Basic Text Classification (Text Classification) (46 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_text_classificationipynb
bull M3 Basic Regression (Predict House Prices) (43 Seconds)ndash httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorials
kerasbasic_regressionipynb
bull M4 Pix2Pix Eager (Option) (7-8 Hours)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplespix2pixpix2pix_eageripynb
bull M5 NMT with Attention (Option) (20-30 minutes)ndash httpscolabresearchgooglecomgithubtensorflowtensorflowblobmastertensorflow
contribeagerpythonexamplesnmt_with_attentionnmt_with_attentionipynb
70
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 71: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/71.jpg)
Basic Classification Fashion MNIST Image Classification
71
httpscolabresearchgooglecomdrive19PJOJi1vn1kjcutlzNHjRSLbeVl4kd5z
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_classificationipynb
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 72: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/72.jpg)
Text ClassificationIMDB Movie Reviews
72
httpscolabresearchgooglecomdrive1x16h1GhHsLIrLYtPCvCHaoO1W-i_gror
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_text_classificationipynb
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 73: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/73.jpg)
Basic RegressionPredict House Prices
73
httpscolabresearchgooglecomdrive1v4c8ZHTnRtgd2_25K_AURjR6SCVBRdlj
Source httpscolabresearchgooglecomgithubtensorflowdocsblobmastersiteentutorialskerasbasic_regressionipynb
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 74: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/74.jpg)
AI+VDI POC ISAC+TKU Test
bull AI+VDI POC Folder (3+1 ipynb) (v3020181120)ndash httpsdrivegooglecomopenid=1qHOemktbEmUz-ot8eFxIKbGwJvXlrjtc
bull run3modelsipynbndash httpscolabresearchgooglecomdrive1HQ1GrIqQUUPCct7_AVgoMwMrh0UqMm0f
bull AI+VDI POC ISAC+TKU Test Reportndash httpsdocsgooglecomspreadsheetsd1meMwqn15PSuTk6d5TgendDpdDX6L3OfHM4E0
SIkq1Zkeditusp=sharing
74
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 75: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/75.jpg)
Summary
75
bull Prescriptive Analytics
bull Model-Based Decision Making
bull Structure of Mathematical Models for Decision Support
bull Certainty Uncertainty and Risk
bull Mathematical Programming Optimization
bull Simulation
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76
![Page 76: Optimization and Simulation - komputasi.files.wordpress.com · Prescriptive Analytics: Optimization and Simulation 3. Outline 4 • Prescriptive Analytics • Model-Based Decision](https://reader036.fdocuments.in/reader036/viewer/2022062402/5fb658d199c2e1233e78d446/html5/thumbnails/76.jpg)
References
bull Ramesh Sharda Dursun Delen and Efraim Turban (2017) Business Intelligence Analytics and Data Science A Managerial Perspective 4th Edition Pearson
bull Jake VanderPlas (2016) Python Data Science Handbook Essential Tools for Working with Data OReilly Media
76