Code Monkey home page Code Monkey logo

Comments (3)

enzbus avatar enzbus commented on September 27, 2024

Hi, those scores should be factor exposures, so you can use for example the FactorMaxLimit (or the others) constraint. You pass the loadings as a pandas Series indexed by assets' names, if they are constant in time, or a dataframe indexed by time and with assets as columns if they change in time. If they change in time they must have an observation for every point in time of the backtest. (So you'll probably have to do pandas forward fills.)

from cvxportfolio.

gladiator1410 avatar gladiator1410 commented on September 27, 2024

Thank you. I have created series with a simple array of factors and supplied to FactorMaxLimit.
I am not really sure these factors considered anywhere and adjusted the "weights" of these stocks based on relative factor values.

Is this code valid? If yes, how can I verify that MultiPeriodOptimization is using my factor values while optimizing the portfolio.

Appreciate your help and any additional direction.

# simple array
esg_leaders_data = np.array(
    [41, 22, 33, 43, 52, 46, 56, 31, 28, 52, 46, 52, 49, 54])  # Max  60

# providing esg scores as an index
ser = pd.Series(esg_leaders_data,
                index=['AAPL', 'BA', 'CAT', 'CVX', 'DIS', 'GS', 'JNJ', 'JPM', 'MCD', 'NKE', 'PG', 'TRV', 'V', 'WBA'])
#print(ser)
gamma_risk = 2
gamma_trade = 0.5
simulator = cvx.StockMarketSimulator(universe, trading_frequency=trading_frequency)
policy = cvx.MultiPeriodOptimization(cvx.ReturnsForecast()
                                     - gamma_risk * cvx.FactorModelCovariance(num_factors=10)
                                     - gamma_trade * cvx.StocksTransactionCost(),
                                     [cvx.LongOnly(), cvx.FactorMaxLimit(ser,60)],
                                     planning_horizon=6)

from cvxportfolio.

enzbus avatar enzbus commented on September 27, 2024

Yes, this code seems valid and is what I meant in my previous answer. I'll try to run it. This will guarantee that at each step the portfolio weights will satisfy w.T @ e <= 60 where e are the esg scores. If you also have long only and leverage 1 it means that the average esg score of the portfolio is less than 60. You can also have it equal to or greater than (with the others factor limit constraints). If the portfolio is long short it's the same, if the leverage is greater than one you'll need to change the limit accordingly. This is one way to use esg information, you can also use it to limit the universe (exclude stocks that don't meet your esg limits) or as a feature in a returns forecast model (see the user_provided_forecasts.py example on how to change the default returns forecaster). There are many ways...

from cvxportfolio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.