ValueError: object arrays are not supported in port.optimization #53
Unanswered
pfeliciano87
asked this question in
Q&A
Replies: 1 comment 5 replies
-
I am using Python 3.7.7. All the dependencies are installed. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear dcajasn, congratulations for coding this module, it is really helpfull and unique.
I installed the 1.0.0 version because when I install the 2.0.0 version I get an error when I "import riskfolio as rp".
The error is related to astropy: "ImportError: DLL load failed: The parrameter is incorrect."
WIth riskfolio 1.0.0 version I don't get this error as this version doesn't need astropy.
I can "import riskfolio as rp". But then I get an error: "ValueError: object arrays are not supported".
Here is the code:
`# Import necessary libraries
import pandas as pd
import riskfolio as rp
import numpy as np
Import data as dataframe
columns_df = ['china_eq','em_eq','euro_eq','world_small_cap','us_eq','china_bd','euro_corp','euro_gov','us_glbl_agg','global_hy','em_debt','cmdties']
df_aa = pd.read_excel('asset_classes_regimes.xlsx',index_col=0)
Filtering the dataframe and creating new dataframe
df_aa_stress2 = df_aa[(df_aa.sectors==1) | (df_aa.forex==1)]
df_aa_normal2 = df_aa[~((df_aa.sectors==1) | (df_aa.forex==1))]
df_rets_normal = pd.DataFrame(df_aa_normal2[df_aa_normal2.columns[0:12]])
df_rets_stress = df_aa_stress2[df_aa_stress2.columns[0:12]]
#Assigning new columns' names
df_rets_normal.columns = columns_df
df_rets_stress.columns = columns_df
Building the portfolio object
port = rp.Portfolio(returns=df_rets_normal)
model='Classic' # Could be Classic (historical), BL (Black Litterman) or FM (Factor Model)
rm = 'MV' # Risk measure used, this time will be variance
obj = 'Sharpe' # Objective function, could be MinRisk, MaxRet, Utility or Sharpe
hist = True # Use historical scenarios for risk measures that depend on scenarios
rf = 0 # Risk free rate
l = 3 # Risk aversion factor, only useful when obj is 'Utility'
w = port.optimization(model=model, rm=rm, obj=obj, rf=rf, l=l, hist=hist)
`
When I do "port.returns" I get a dataframe with the returns.
The error I get in port.optimization is in the image attached.
Thank you very much for your help here.
Beta Was this translation helpful? Give feedback.
All reactions