SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Stock Portfolio Optimization Report
Albert Chu
Introduction:
Financial and data analyst firms need a way to assess people’s money to decide which options
has the least most potential return. Thus the main goal for mathematicians is to find a way to do
so by using different numerical analysis methods to assess which portfolios is most suitable for
them. The two explanations of how to optimize portfolios is to maximize return and to minimize
the risk, This experiment is given data from previous examples of previous trends and mishaps of
the stock market, given the company name, number of sales/trades, and the value of stock during
trade. The method of analysis that I chose to use is the Gauss-Hermite Quadrature to create a
minimizing loss in a risky environment.
Method:
How can we make purchasing stock a less of a risk and more rewarding? We can use data sets
that are which contain numerous factors and trends that computers can analyze and find similar
patterns that may happen in the future. A code of Gaussian Quadrature can be implemented if we
have the nodes/weight given the figure of the stock chart, which can then be used to accurately
spot out noticeable trends and make purchasing a stock optimally pleasing. We will be using this
general formula:
The reason we are using Gauss-Hermite Quadrature is because in order to find expected loss and
probability of losing, we use the PDF of the loss and integrate it.
f(x) will be a complicated function that will be integrated to but in this situation, is assumed by a
random stock function found,and in this case, a form of logarithmic function, making it a little
different then the actual stock market.. This is the PDF (probability density function) of a normal
distribution function with random variable x to calculate the expected profit/gain of the stock
portfolio which is derived to be:
To use this formula we first need to find the variables and define them.
Minimize the variance σ2=xtVx (where t is time)
Maximize the expected return r = atx
Sample set derived from R: σ2 (x)=σ2x+σrx+V+error
Let's say we are given data sets named as Train_file and Test_file. These datasets were taken off
off the Kaggle website. The data given are the sale price of stocks at the closing time of the stock
market. The sales are then recorded for each specific company and the trends are put into the
formula. The code that I used to run reads in the dataset in the file, runs the Gauss-Hermite
Quadrature, giving us values which are the probability of gains. The other value that it gives is
the expected return, or the amount of profit gained from the transaction. The expected value of
the exact value is very pretty close to the predicted model.
And the Formula for the Probability of gain is:
Formula for Expected Gain is:
As stated earlier, the
Results:
A tabular result from the the output file shows:
Id Sales Id Sales
1 4770.5 11 7041.0
2 7864.5 12 8110.5
3 8955.0 13 7322.0
4 6893.0 14 9156.0
5 6697.0 15 6017.0
6 5829.0 16 4847.0
7 8004.0 17 6042.0
8 8078.0 18 9735.0
9 5365.0 19 11966.0
10 6007.0 20 10178.0 etc.
Gauss-Hermite Quadrature
With xi zeroes
Probability of Gain Expected gain
2 .5 .081
3 .5168 .125
4 .5 .0912
5 .5199 .132
Exact probability of gain was .51
As you can see, the reason stock markets are so hard to cheat is because of the random behaviors
that occur, mostly due to the impact of other companies. The probability of gaining is only ~51%
or ever so slightly more than that, and the compliment of the probability is almost the same
which is to say the probability of loss. The majority of the other results show around 50%, with a
few outliers. These outliers could have different reasons for such high probability of gain, such
as start-ups just getting a public offering, or for many other reasons. There are just very slight
ways to lower risk, but no method to totally remove the risk aspect.
Code:
import pandas as pd
Import numpy as np
Train_file = 'C:/Users/ACHU/input/train.csv'
Test_file = 'C:/Users/ACHU/input/test.csv'
Output_file ='stock.csv'
train = pd.read_csv( train_file )
test = pd.read_csv( test_file )
train = train.loc[train.Change > 0] #days that stock up in price
columns = ['Company', 'DayOfWeek', 'Sales']
medians = train.groupby( columns )['Sales'].median()
medians = medians.reset_index()
test2 = pd.merge( test, medians, on = columns, how = 'left' )
assert( len( test2 ) == len( test ))
test2.loc[ test2.Open == gaussian_MC, 'Sales' ] = 0
assert( test2.Sales.isnull().sum() == 0 )
test2[[ 'Company', 'Sales' ]].to_csv( output_file, index = False )
function gaussian_MC(M=200,integral, columns)
ex = np . zeros (M)
k = x # no. of experiments
N = 10∗∗np . arange (1 , k+1)
v = [ ] ; e = [ ]
for n in N:
for m in xrange (M) :
x = np . p i ∗np . rando m . rand ( n )
c t v = np . exp(−np . cos ( x ) ) − 1. + np . cos ( x ) − 0.5∗np . cos ( x ) ∗np . cos ( x )
ex [m] = 1.25 + sum( c t v ) / n # quadrature
ev = sum( ex ) /M
vex = np . dot ( ex , ex ) /M
vex −= ev∗∗2 31 v += [ vex ] ; e += [ ev ]
print n , vex , ev

Weitere ähnliche Inhalte

Andere mochten auch

Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
idescitation
 
Estimating Beta For A Portfolio Of Stocks
Estimating Beta For A Portfolio Of StocksEstimating Beta For A Portfolio Of Stocks
Estimating Beta For A Portfolio Of Stocks
Geoffery Mullings
 
Portfolio Management Project
Portfolio Management ProjectPortfolio Management Project
Portfolio Management Project
Ran Zhang
 
Portfolio management
Portfolio managementPortfolio management
Portfolio management
Xiaohua Liu
 
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
Hok Lie
 
Financial Economics Essay Maxwell Mayhew 2015
Financial Economics Essay Maxwell Mayhew 2015Financial Economics Essay Maxwell Mayhew 2015
Financial Economics Essay Maxwell Mayhew 2015
Max Mayhew
 
Group_5_stream_80.docx (1)
Group_5_stream_80.docx (1)Group_5_stream_80.docx (1)
Group_5_stream_80.docx (1)
Arthur Qiu
 
Polyu Reference letter
Polyu Reference letterPolyu Reference letter
Polyu Reference letter
Kelvin Lam
 
Nduati Michelle Wanjiku Undergraduate Project
Nduati Michelle Wanjiku Undergraduate ProjectNduati Michelle Wanjiku Undergraduate Project
Nduati Michelle Wanjiku Undergraduate Project
Michelle Nduati
 
Portfolio Optimization Project Report
Portfolio Optimization Project ReportPortfolio Optimization Project Report
Portfolio Optimization Project Report
John Cui
 
ma574-final-paper
ma574-final-paperma574-final-paper
ma574-final-paper
Xuan Ning
 
CAPM Fama French
CAPM Fama FrenchCAPM Fama French
CAPM Fama French
AhmedSaba
 
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
Mengxi Jiang
 

Andere mochten auch (20)

Case 2
Case 2Case 2
Case 2
 
Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
Improving Returns from the Markowitz Model using GA- AnEmpirical Validation o...
 
Estimating Beta For A Portfolio Of Stocks
Estimating Beta For A Portfolio Of StocksEstimating Beta For A Portfolio Of Stocks
Estimating Beta For A Portfolio Of Stocks
 
Portfolio Management Project
Portfolio Management ProjectPortfolio Management Project
Portfolio Management Project
 
Portfolio management
Portfolio managementPortfolio management
Portfolio management
 
Project on KSE 25 companies
Project on KSE 25 companiesProject on KSE 25 companies
Project on KSE 25 companies
 
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
Resolving Multi Objective Stock Portfolio Optimization Problem Using Genetic ...
 
Financial Economics Essay Maxwell Mayhew 2015
Financial Economics Essay Maxwell Mayhew 2015Financial Economics Essay Maxwell Mayhew 2015
Financial Economics Essay Maxwell Mayhew 2015
 
Saha, Final Project
Saha, Final ProjectSaha, Final Project
Saha, Final Project
 
Group_5_stream_80.docx (1)
Group_5_stream_80.docx (1)Group_5_stream_80.docx (1)
Group_5_stream_80.docx (1)
 
Is capm a good predictor of stock return in the nigerian banking stocks
Is capm a good predictor of stock return in the nigerian banking stocksIs capm a good predictor of stock return in the nigerian banking stocks
Is capm a good predictor of stock return in the nigerian banking stocks
 
Portfolio Analysis
Portfolio AnalysisPortfolio Analysis
Portfolio Analysis
 
Project Report
Project ReportProject Report
Project Report
 
Project final
Project finalProject final
Project final
 
Polyu Reference letter
Polyu Reference letterPolyu Reference letter
Polyu Reference letter
 
Nduati Michelle Wanjiku Undergraduate Project
Nduati Michelle Wanjiku Undergraduate ProjectNduati Michelle Wanjiku Undergraduate Project
Nduati Michelle Wanjiku Undergraduate Project
 
Portfolio Optimization Project Report
Portfolio Optimization Project ReportPortfolio Optimization Project Report
Portfolio Optimization Project Report
 
ma574-final-paper
ma574-final-paperma574-final-paper
ma574-final-paper
 
CAPM Fama French
CAPM Fama FrenchCAPM Fama French
CAPM Fama French
 
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
Application of Graphic LASSO in Portfolio Optimization_Yixuan Chen & Mengxi J...
 

Ähnlich wie PorfolioReport

Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
Amit Sharma
 
Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
Amit Sharma
 
CostPerform’s multidimensional costing function leads to improved profitability
CostPerform’s multidimensional costing function leads to improved profitabilityCostPerform’s multidimensional costing function leads to improved profitability
CostPerform’s multidimensional costing function leads to improved profitability
Brian Plowman
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
melbruce90096
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
armanuelraj
 

Ähnlich wie PorfolioReport (20)

ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066
 
Data Mining _ Weka
Data Mining _ WekaData Mining _ Weka
Data Mining _ Weka
 
Logistic_regression_ML.pdf
Logistic_regression_ML.pdfLogistic_regression_ML.pdf
Logistic_regression_ML.pdf
 
Empowerment Technology Lesson 4
Empowerment Technology Lesson 4Empowerment Technology Lesson 4
Empowerment Technology Lesson 4
 
Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with R
 
Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
 
Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
 
FDMEE script examples
FDMEE script examplesFDMEE script examples
FDMEE script examples
 
FDMEE script examples
FDMEE script examplesFDMEE script examples
FDMEE script examples
 
Telecom Churn Analysis
Telecom Churn AnalysisTelecom Churn Analysis
Telecom Churn Analysis
 
CostPerform’s multidimensional costing function leads to improved profitability
CostPerform’s multidimensional costing function leads to improved profitabilityCostPerform’s multidimensional costing function leads to improved profitability
CostPerform’s multidimensional costing function leads to improved profitability
 
An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)
 
DataTables
DataTablesDataTables
DataTables
 
somhelpdoc
somhelpdocsomhelpdoc
somhelpdoc
 
BIG MART SALES.pptx
BIG MART SALES.pptxBIG MART SALES.pptx
BIG MART SALES.pptx
 
BIG MART SALES PRIDICTION PROJECT.pptx
BIG MART SALES PRIDICTION PROJECT.pptxBIG MART SALES PRIDICTION PROJECT.pptx
BIG MART SALES PRIDICTION PROJECT.pptx
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
 
Quantitative finance 101
Quantitative finance 101Quantitative finance 101
Quantitative finance 101
 

PorfolioReport

  • 1. Stock Portfolio Optimization Report Albert Chu Introduction: Financial and data analyst firms need a way to assess people’s money to decide which options has the least most potential return. Thus the main goal for mathematicians is to find a way to do so by using different numerical analysis methods to assess which portfolios is most suitable for them. The two explanations of how to optimize portfolios is to maximize return and to minimize the risk, This experiment is given data from previous examples of previous trends and mishaps of the stock market, given the company name, number of sales/trades, and the value of stock during trade. The method of analysis that I chose to use is the Gauss-Hermite Quadrature to create a minimizing loss in a risky environment. Method: How can we make purchasing stock a less of a risk and more rewarding? We can use data sets that are which contain numerous factors and trends that computers can analyze and find similar patterns that may happen in the future. A code of Gaussian Quadrature can be implemented if we have the nodes/weight given the figure of the stock chart, which can then be used to accurately spot out noticeable trends and make purchasing a stock optimally pleasing. We will be using this general formula: The reason we are using Gauss-Hermite Quadrature is because in order to find expected loss and probability of losing, we use the PDF of the loss and integrate it. f(x) will be a complicated function that will be integrated to but in this situation, is assumed by a random stock function found,and in this case, a form of logarithmic function, making it a little
  • 2. different then the actual stock market.. This is the PDF (probability density function) of a normal distribution function with random variable x to calculate the expected profit/gain of the stock portfolio which is derived to be: To use this formula we first need to find the variables and define them. Minimize the variance σ2=xtVx (where t is time) Maximize the expected return r = atx Sample set derived from R: σ2 (x)=σ2x+σrx+V+error Let's say we are given data sets named as Train_file and Test_file. These datasets were taken off off the Kaggle website. The data given are the sale price of stocks at the closing time of the stock market. The sales are then recorded for each specific company and the trends are put into the formula. The code that I used to run reads in the dataset in the file, runs the Gauss-Hermite Quadrature, giving us values which are the probability of gains. The other value that it gives is the expected return, or the amount of profit gained from the transaction. The expected value of the exact value is very pretty close to the predicted model. And the Formula for the Probability of gain is: Formula for Expected Gain is: As stated earlier, the Results: A tabular result from the the output file shows: Id Sales Id Sales
  • 3. 1 4770.5 11 7041.0 2 7864.5 12 8110.5 3 8955.0 13 7322.0 4 6893.0 14 9156.0 5 6697.0 15 6017.0 6 5829.0 16 4847.0 7 8004.0 17 6042.0 8 8078.0 18 9735.0 9 5365.0 19 11966.0 10 6007.0 20 10178.0 etc. Gauss-Hermite Quadrature With xi zeroes Probability of Gain Expected gain 2 .5 .081 3 .5168 .125 4 .5 .0912 5 .5199 .132 Exact probability of gain was .51 As you can see, the reason stock markets are so hard to cheat is because of the random behaviors that occur, mostly due to the impact of other companies. The probability of gaining is only ~51% or ever so slightly more than that, and the compliment of the probability is almost the same which is to say the probability of loss. The majority of the other results show around 50%, with a few outliers. These outliers could have different reasons for such high probability of gain, such as start-ups just getting a public offering, or for many other reasons. There are just very slight
  • 4. ways to lower risk, but no method to totally remove the risk aspect. Code: import pandas as pd Import numpy as np Train_file = 'C:/Users/ACHU/input/train.csv' Test_file = 'C:/Users/ACHU/input/test.csv' Output_file ='stock.csv' train = pd.read_csv( train_file ) test = pd.read_csv( test_file ) train = train.loc[train.Change > 0] #days that stock up in price columns = ['Company', 'DayOfWeek', 'Sales'] medians = train.groupby( columns )['Sales'].median() medians = medians.reset_index() test2 = pd.merge( test, medians, on = columns, how = 'left' ) assert( len( test2 ) == len( test )) test2.loc[ test2.Open == gaussian_MC, 'Sales' ] = 0 assert( test2.Sales.isnull().sum() == 0 ) test2[[ 'Company', 'Sales' ]].to_csv( output_file, index = False ) function gaussian_MC(M=200,integral, columns) ex = np . zeros (M) k = x # no. of experiments N = 10∗∗np . arange (1 , k+1) v = [ ] ; e = [ ] for n in N: for m in xrange (M) : x = np . p i ∗np . rando m . rand ( n ) c t v = np . exp(−np . cos ( x ) ) − 1. + np . cos ( x ) − 0.5∗np . cos ( x ) ∗np . cos ( x ) ex [m] = 1.25 + sum( c t v ) / n # quadrature ev = sum( ex ) /M vex = np . dot ( ex , ex ) /M vex −= ev∗∗2 31 v += [ vex ] ; e += [ ev ] print n , vex , ev