Quant Finance with R Part 3: Portfolio Optimization

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 73

  • @nachiketrko
    @nachiketrko 4 ปีที่แล้ว +12

    If you are using the code from the previous tutorial, be careful as you need to consider the portfolio prices and not the returns. I was using portfolio returns which gave me the error of "ROI". Using portfolio prices fixed it.

  • @eljuan9754
    @eljuan9754 3 ปีที่แล้ว +3

    library(forecast)
    library(PortfolioAnalytics)
    then,
    porf

  • @kirankumarkv858
    @kirankumarkv858 4 ปีที่แล้ว +12

    Excellent. ROI package needs to be downloaded with ROI.plugin.quadprog & ROI.plugin.glkp for the optimize.portfolio to work

    • @elnokeadorml
      @elnokeadorml 3 ปีที่แล้ว

      thanks

    • @БаярсайханХУЛАН
      @БаярсайханХУЛАН 3 ปีที่แล้ว

      what should I do? It doesn't work either.
      Error in optimize.portfolio(portfolioReturns, portf, optimize_method = "ROI", :
      ROI only solves mean, var/StdDev, HHI, or sample ETL/ES/CVaR type business objectives, choose a different optimize_method.
      Having this result, even if I had those ROI packages.

    • @fu955
      @fu955 2 ปีที่แล้ว

      @@БаярсайханХУЛАН same problem

    • @nikoskouretsis1772
      @nikoskouretsis1772 ปีที่แล้ว

      @@БаярсайханХУЛАН same problem. Has anyone found the solution?

  • @vineetsansi
    @vineetsansi 2 ปีที่แล้ว +4

    Try below code to avoid errors:
    library(tidyverse)
    library(lubridate)
    library(quantmod)
    library(PerformanceAnalytics)
    library(PortfolioAnalytics)
    tickers

  • @alanhill5337
    @alanhill5337 3 ปีที่แล้ว +2

    great tutorials, thank you. Part 2 worked well. but I have the same issue with "portfolio.spec" as others with Part 3. and i thought "R" was the answer for CAPM solutions. There are "R" online references to "portfolio.spec" (undated) but seems it may have been superseded and/or deleted with no reference to any replacement. that's a shame.

  • @easydrafting
    @easydrafting 3 ปีที่แล้ว +2

    Getting this Error ---------Error in gmv_opt(R = R, constraints = constraints, moments = moments, :
    "package:ROI" %in% search() || requireNamespace("ROI", quietly = TRUE) is not TRUE-----------------I have installed ROI package as well...But it didn't work... can someone help.

  • @Kig_Ama
    @Kig_Ama 4 ปีที่แล้ว

    ty, this is a great series, u provide here. i d like to make a recomnendation: is it possible u make video how to simulate the hurdle rate for a stock by using the monte carlo simulation in combination with the capm?

  • @OutperformMP
    @OutperformMP 3 ปีที่แล้ว

    How do you do this when rf is not 0? I can change it on the efficient fronter plot, but I would like to do it on the optimize.portfolio function too

    • @insteadtechsolutions4276
      @insteadtechsolutions4276 ปีที่แล้ว

      when rf is not 0, the the capital market line(tangential line) is not tangential. portfolio returns are lower than the risk free return

  • @ThePengmun
    @ThePengmun 4 ปีที่แล้ว +2

    Hi , I have a question. I am receiving this error : > optPort

    • @sherryparikh8310
      @sherryparikh8310 4 ปีที่แล้ว

      Hey!
      I am getting a similar error. Did you find a solution?

    • @fu955
      @fu955 2 ปีที่แล้ว

      @@sherryparikh8310 me to ,Error in optimize.portfolio(portfolioreturns, portf, optimize_method = "ROI", :
      ROI only solves mean, var/StdDev, HHI, or sample ETL/ES/CVaR type business objectives, choose a different optimize_method. anyone found a solution ?

  • @tronization
    @tronization 5 ปีที่แล้ว

    Thanks for this tutorial. Good stuff and keep it coming

  • @biancadegroot7213
    @biancadegroot7213 4 ปีที่แล้ว

    Thanks! You deserve way more subscribers! :)

  • @hadifattah622
    @hadifattah622 ปีที่แล้ว

    I keep getting an error saying "object = 'daily' not found", this is related to the line with periodicity. Does anyone know how I can fix this?

  • @lorenzofeijoo4284
    @lorenzofeijoo4284 4 ปีที่แล้ว +1

    > optport = optimize.portfolio(portfolioReturns, portf, optimize_method = 'ROI')
    Error in gmv_opt(R = R, constraints = constraints, moments = moments, :
    "package:ROI" %in% search() || requireNamespace("ROI", quietly = TRUE) is not TRUE
    >
    i keep getting this error, I have install packages ROI, ROI.plugin.quadprog and glkp

  • @marioemanuele9512
    @marioemanuele9512 7 หลายเดือนก่อน

    Why some stocks are above the security market line ?

  • @yanzhongxu8580
    @yanzhongxu8580 5 ปีที่แล้ว +1

    After I increases the portofolio holding to 25, the optimization did not return correct results. What are the reasons?

  • @numberpercents4495
    @numberpercents4495 4 ปีที่แล้ว +4

    portf

    • @raghadajouz6827
      @raghadajouz6827 4 ปีที่แล้ว

      same as me?
      have you fine the solution?

    • @filippoquattrini1855
      @filippoquattrini1855 4 ปีที่แล้ว

      also me

    • @raghadajouz6827
      @raghadajouz6827 4 ปีที่แล้ว +14

      ​@@filippoquattrini1855 it works ok now try to install
      library(quantmod)
      library(PerformanceAnalytics)
      library(forecast)
      library(PortfolioAnalytics)

    • @filippoquattrini1855
      @filippoquattrini1855 4 ปีที่แล้ว

      @@raghadajouz6827 thanks a lot

    • @jac6003
      @jac6003 4 ปีที่แล้ว

      this chunk work for me: portf

  • @jamesbevan1
    @jamesbevan1 3 ปีที่แล้ว

    I tried to run the optimize.portfolio function and didn't get the weights like you did. I got "PortfolioAnalytics Portfolio Specification" and a bunch of descriptives etc

  • @fu955
    @fu955 2 ปีที่แล้ว

    to access fportfolio i need to install Rcurl and this just will not install for some reason

  • @takao95
    @takao95 5 ปีที่แล้ว +3

    I can't use the optimize method ROI because when I try it tell me " Error: "package:ROI" %in% search() || requireNamespace("ROI", quietly = TRUE) is not TRUE". What I can do? Help please

    • @dakuta
      @dakuta 5 ปีที่แล้ว +2

      check if you have ROI, ROI.plugin.quadprog, and ROI.plugin.glpk libraries installed

    • @lorenzofeijoo4284
      @lorenzofeijoo4284 4 ปีที่แล้ว

      @@dakuta I DID what you said and still doesnt work

  • @thatPSNguy99
    @thatPSNguy99 4 ปีที่แล้ว

    It seems like portfolio.spec and add.constraint are no longer in the Performance Analytics package. I see them on the old R documentation, but not the new R documentation. I also don't see anything coming when using "?..." for the functions in the Rstudio terminal. Are these operations still possible with the same package?

    • @maartenlabrie6628
      @maartenlabrie6628 3 ปีที่แล้ว +1

      try PortfolioAnalytics instead of PerformanceAnalytics

  • @DuGaita
    @DuGaita 4 ปีที่แล้ว

    Great! Is there any way i can get the weights of the tangency porfolio ploted in the efficient frontier?

  • @aydanp7020
    @aydanp7020 2 ปีที่แล้ว

    I can't do extract efficient portfolio I tried doing exactly the same way as in the video.

  • @fu955
    @fu955 2 ปีที่แล้ว

    Error in optimize.portfolio(portfolioreturns, portf, optimize_method = "ROI", :
    ROI only solves mean, var/StdDev, HHI, or sample ETL/ES/CVaR type business objectives, choose a different optimize_method.

  • @mukailarafiu2718
    @mukailarafiu2718 4 ปีที่แล้ว

    Great Tutorial! but i had a problem with "ROI", the packages do not pick this optimization method, so i used "SANN" , yet still iit can not figure out the chart weight, so that is where i got locked up, any help please?

    • @jamesbevan1
      @jamesbevan1 3 ปีที่แล้ว +2

      You need to install the packages: "ROI" and "ROI.plugin.quadprog"

  • @jac6003
    @jac6003 4 ปีที่แล้ว

    You're great! thanks a lot!

  • @griselwurscht
    @griselwurscht 4 ปีที่แล้ว

    Hey when I run optimazion.portfolio(data_xts, portfolio=portf_minvar, optimize_method="ROI") it only returns NAs. I suggest that the source of this problem lays within add.constraint(portfolio=portf_minvar, type="box", min=0, max=1). Unfortunately I don't know how to fix this problem. Can anyone help me with this?

  • @svuraki4ofara344
    @svuraki4ofara344 4 ปีที่แล้ว

    How can we estimate Bayes-Stein shrinkage portfolio ? or Bayesian portfolio based on belief in an asset-pricing model ?

  • @haozhehuang6932
    @haozhehuang6932 5 ปีที่แล้ว +2

    Error in gmv_opt(R = R, constraints = constraints, moments = moments, :
    paste0("package:", plugin) %in% search() || requireNamespace(plugin, .... is not TRUE
    I have experienced, can someone help?

    • @Federico-pn9hp
      @Federico-pn9hp 4 ปีที่แล้ว

      did you solve this one ?

    • @maumrrobot
      @maumrrobot 4 ปีที่แล้ว

      Check if you have ROI, ROI.plugin.quadprog, and ROI.plugin.glpk libraries installed

    • @stijnvanleeuwen3647
      @stijnvanleeuwen3647 4 ปีที่แล้ว

      @@maumrrobot How do you do that?

    • @maumrrobot
      @maumrrobot 4 ปีที่แล้ว

      Stijn van Leeuwen just install those libraries and then run them. The error will disappear.

    • @rajiyengar5525
      @rajiyengar5525 4 ปีที่แล้ว

      > install.packages("ROI", "ROI.plugin.quadprog", "ROI.plugin.glpk")
      Warning in install.packages :
      'lib = "ROI.plugin.quadprog"' is not writable

  • @benhoward7116
    @benhoward7116 3 ปีที่แล้ว

    The current version of the package "Portfolio Analytics" v 2.0.4 does not include functions like portfolio.spec or optimize.portfolio. Anybody know where it went? I can't find it although I read the change logs.

    • @maartenlabrie6628
      @maartenlabrie6628 3 ปีที่แล้ว +1

      try PortfolioAnalytics instead of PerformanceAnalytics

  • @t567robert2
    @t567robert2 5 ปีที่แล้ว

    below is an error I keep getting. I'm not sure exactly how to fix this. is this perhaps because I ended up importing also the Portfolio Analytics library? Thank you in advance.
    > optPort

    • @codebliss181
      @codebliss181  5 ปีที่แล้ว +2

      ROI is a type solver that is available as an external package. With some downloads, it's already bundled in. Install the following packages using the install.packages("") command:
      ROI
      ROI.plugin.quadprog
      ROI.plugin.glpk
      Then load them like this:
      library(ROI)
      library(ROI.plugin.quadprog)
      library(ROI.plugin.glpk)
      You should be good after that...by the way if you want to do your own quadratic programming to get to your desired optimization then you should install.packages("quadprog"). There are other solvers available as well that you can use in the optimization.
      Here's a list from the PortfolioAnalytics doc: c("DEoptim", "random",
      "ROI", "ROI_old", "pso", "GenSA")
      You'll probably have to install the external libraries for some of these also. Hope this helps!

    • @877050831
      @877050831 4 ปีที่แล้ว

      @@codebliss181 Still it gives this error
      Error in ROI::L_constraint(L = Amat, dir = dir.vec, rhs = rhs.vec) : all(c(dim_L[1], n_dir) == n_L_constraints) is not TRUE

  • @mousaajouz6935
    @mousaajouz6935 4 ปีที่แล้ว

    I keep have this error, anyone can help?
    Error in optimize.portfolio(portfolioReturns, portf, optimize_method = "ROI") :
    ROI only solves mean, var/StdDev, HHI, or sample ETL/ES/CVaR type business objectives, choose a different optimize_method.

    • @magnuslyng9580
      @magnuslyng9580 4 ปีที่แล้ว

      Hey im stuck here as well.. Did you find a solution?

  • @rjmorpheus
    @rjmorpheus 5 ปีที่แล้ว +1

    YAAAAH!!

  • @tomaspicca6559
    @tomaspicca6559 4 ปีที่แล้ว

    I dont know what I am doing wrong, but when I try to do the optimize.portfolio, the result in Weights is NA, can anybody tell me what I am doing wrong?

    • @Patrick-rj8gh
      @Patrick-rj8gh 4 ปีที่แล้ว

      check the portfolio returns. make sure there's only 7 columns corresponding to the closing data for each day

  • @Vaggos16
    @Vaggos16 4 ปีที่แล้ว

    hey I have a question.How can I extact the portofolios that lie on the efficient frontier only.Because I have 1000 possible portofolios and I want only the optimal (those where lie on the efficient frontier) how can I extract them.thank you

  • @Marco.21
    @Marco.21 5 ปีที่แล้ว

    Hi! nice video but i have a problem, when i try to run this
    "optPort

    • @eduardomartincacereslopez6532
      @eduardomartincacereslopez6532 5 ปีที่แล้ว +4

      Hi, I tried the solution in the link below and it worked (install: ROI, ROI.plugin.quadprog, and ROI.plugin.glpk).
      stackoverflow.com/questions/45201485/error-when-trying-to-optimize-with-portfolio-analytics

    • @lvincent.4983
      @lvincent.4983 2 ปีที่แล้ว

      @@eduardomartincacereslopez6532 thanks that helps🙏

  • @t567robert2
    @t567robert2 5 ปีที่แล้ว

    For some reason for me it keeps telling me that the function “portfolio.spec” cannot be found... any suggestions on how to fix this?

    • @t567robert2
      @t567robert2 5 ปีที่แล้ว +2

      Jsuk, I had to download the library portfolio analytics, now it’s working

    • @cooltraderf
      @cooltraderf 5 ปีที่แล้ว

      @@t567robert2 Did you mean the PerformanceAnalytics library? I tied downloading that and I still get an error with portfolio.spec

    • @henriquefaria6940
      @henriquefaria6940 5 ปีที่แล้ว

      I already have the PerformanceAnalytics package installed and I do not find a portfolio.spec function, could anyone help me?

    • @dimuthu999
      @dimuthu999 5 ปีที่แล้ว +5

      You need to install the PortfolioAnalytics package: install.packages("PortfolioAnalytics")

  • @nkunam
    @nkunam 5 ปีที่แล้ว

    can someone please help

  • @coreyhillman7506
    @coreyhillman7506 2 ปีที่แล้ว

    Hi trying to follow along, the syntax for even downloading port info isn't working. is anyone else having this problem? is it because it is out of date or am I doing something wrong?