Spaces:
Sleeping
Sleeping
Robert Castagna
commited on
Commit
•
641a9e4
1
Parent(s):
4ad15ae
meeting updates
Browse files- fin_data.db +0 -0
- pages/2_Portfolio_Builder.py +20 -13
fin_data.db
CHANGED
Binary files a/fin_data.db and b/fin_data.db differ
|
|
pages/2_Portfolio_Builder.py
CHANGED
@@ -69,18 +69,14 @@ obb.account.login(pat=os.environ['open_bb_pat'])
|
|
69 |
|
70 |
if 'tickers' not in st.session_state:
|
71 |
tickers = [
|
72 |
-
"
|
73 |
-
"XLK", "XLV", "XLY", "XLP", "XLB",
|
74 |
-
"XOP", "IYR", "XHB", "ITB", "VNQ",
|
75 |
-
"GDXJ", "IYE", "OIH", "XME", "XRT",
|
76 |
-
"SMH", "IBB", "KBE", "KRE", "XTL",
|
77 |
]
|
78 |
st.session_state['tickers'] = tickers
|
79 |
|
80 |
if not platform.processor(): # take inputs from the user for hosted application
|
81 |
tickers = st.session_state['tickers']
|
82 |
|
83 |
-
elif re.search('AuthenticAMD', platform.processor()): # use live ibkr portfolio if ran from local machine
|
84 |
try:
|
85 |
# Initialize IB connection here
|
86 |
open_nested_event_loop()
|
@@ -132,8 +128,8 @@ with st.form(key="selecting columns"):
|
|
132 |
# Step 2: Set portfolio optimization model
|
133 |
port.assets_stats(model='hist') # Using historical data for estimation
|
134 |
# Step 3: Configure the optimization model and calculate the efficient frontier
|
135 |
-
ef = port.efficient_frontier(model='Classic', rm='
|
136 |
-
w1 = port.optimization(model='Classic', rm='
|
137 |
|
138 |
mu = port.mu # Expected returns
|
139 |
cov = port.cov # Covariance matrix
|
@@ -148,7 +144,7 @@ with st.form(key="selecting columns"):
|
|
148 |
# Ensure you're using the adjusted close prices for accurate return calculation
|
149 |
benchmark_returns = spy_prices['close'].pct_change().dropna()
|
150 |
|
151 |
-
port.rf = 0.
|
152 |
portfolio_return = np.dot(w1, mu)
|
153 |
|
154 |
# market return
|
@@ -225,12 +221,13 @@ with st.form(key="selecting columns"):
|
|
225 |
|
226 |
st.pyplot(fig1)
|
227 |
|
228 |
-
port = rp.HCPortfolio(returns=returns)
|
229 |
w = port.optimization(
|
230 |
model="HRP",
|
231 |
codependence="pearson",
|
232 |
-
|
233 |
-
|
|
|
234 |
linkage="single",
|
235 |
max_k=10,
|
236 |
leaf_order=True,
|
@@ -273,7 +270,7 @@ with st.form(key="selecting columns"):
|
|
273 |
# Ensure you're using the adjusted close prices for accurate return calculation
|
274 |
benchmark_returns = spy_prices['close'].pct_change().dropna()
|
275 |
|
276 |
-
port.rf = 0.
|
277 |
portfolio_return = np.dot(w, mu)
|
278 |
|
279 |
# market return
|
@@ -308,3 +305,13 @@ with st.form(key="selecting columns"):
|
|
308 |
w=w,
|
309 |
)
|
310 |
st.write('Sharpe Ratio: ', np.round(sharpe_ratio, 3))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
if 'tickers' not in st.session_state:
|
71 |
tickers = [
|
72 |
+
"SPY", "QQQ","BND","GLD","VTI"
|
|
|
|
|
|
|
|
|
73 |
]
|
74 |
st.session_state['tickers'] = tickers
|
75 |
|
76 |
if not platform.processor(): # take inputs from the user for hosted application
|
77 |
tickers = st.session_state['tickers']
|
78 |
|
79 |
+
elif not re.search('AuthenticAMD', platform.processor()): # use live ibkr portfolio if ran from local machine
|
80 |
try:
|
81 |
# Initialize IB connection here
|
82 |
open_nested_event_loop()
|
|
|
128 |
# Step 2: Set portfolio optimization model
|
129 |
port.assets_stats(model='hist') # Using historical data for estimation
|
130 |
# Step 3: Configure the optimization model and calculate the efficient frontier
|
131 |
+
ef = port.efficient_frontier(model='Classic', rm='MV', points=50, rf=0.0406, hist=True)
|
132 |
+
w1 = port.optimization(model='Classic', rm='MV', obj='Sharpe', rf=0.0, hist=True)
|
133 |
|
134 |
mu = port.mu # Expected returns
|
135 |
cov = port.cov # Covariance matrix
|
|
|
144 |
# Ensure you're using the adjusted close prices for accurate return calculation
|
145 |
benchmark_returns = spy_prices['close'].pct_change().dropna()
|
146 |
|
147 |
+
port.rf = 0.000406 # Risk-free rate
|
148 |
portfolio_return = np.dot(w1, mu)
|
149 |
|
150 |
# market return
|
|
|
221 |
|
222 |
st.pyplot(fig1)
|
223 |
|
224 |
+
port = rp.HCPortfolio(returns=returns)#, w_max=0.3, w_min=0.05)
|
225 |
w = port.optimization(
|
226 |
model="HRP",
|
227 |
codependence="pearson",
|
228 |
+
obj='Sharpe',
|
229 |
+
rm='vol', # minimum variance
|
230 |
+
rf=0.000406,
|
231 |
linkage="single",
|
232 |
max_k=10,
|
233 |
leaf_order=True,
|
|
|
270 |
# Ensure you're using the adjusted close prices for accurate return calculation
|
271 |
benchmark_returns = spy_prices['close'].pct_change().dropna()
|
272 |
|
273 |
+
port.rf = 0.000406 # Risk-free rate
|
274 |
portfolio_return = np.dot(w, mu)
|
275 |
|
276 |
# market return
|
|
|
305 |
w=w,
|
306 |
)
|
307 |
st.write('Sharpe Ratio: ', np.round(sharpe_ratio, 3))
|
308 |
+
|
309 |
+
# -------------------------- (Report) -------------------------------- #
|
310 |
+
# fig_report = rp.jupyter_report(returns,
|
311 |
+
# w=w1,
|
312 |
+
# rm='MV',
|
313 |
+
# rf=0.0406,
|
314 |
+
# nrow=25
|
315 |
+
# )
|
316 |
+
|
317 |
+
# st.pyplot(fig_report)
|