I have a access database named portfolio, storing the portfolio and benchmark…
Jump to turn (11)
- 1I have a access database named portfolio, storing the portfolio and benchmark in
- 2There’s still some problems. the calculation of Q is baed on industry level. but
- 3obviously, when you calculate benchmarkt return by industry, you also need to ca
- 4what if dbname=portfolio.accdb and path = C:\Users\LIQI\Documents\
- 5import pandas as pd import matplotlib.pyplot as plt connstr = r"DRIVER={Microsof
- 6error code. unexpected indent
- 7you forgot to import these two function: import matplotlib.pyplot as plt import
- 8I try to write a sql,but got invalid syntax. any suggestion? portfolioquery = f"
- 9Execution failed on sql 'SELECT FROM Mockportfolio WHERE ID = '300Active' AND tr
- 10I think the problem is data type of the column of tradedate. How to check the da
- 11The data type of 'TRADEDATE' column is DATETIME. So how can I change this query?
- User
I have a access database named portfolio, storing the portfolio and benchmark information. the portfolio table contains 6 columns, “portfolio ID”, “tradedate”, “ticker”, “weight”, “price change” and “industry”. the benchmark table also has 6 columns: “bench ID”, “tradedate”, “ticker”, “weight”, “price change”, “industry”. please use python define a function brinson (portfolioID , bench ID, begindate, enddate), setup connection to the database, calculate and return the total daily excess return and each effect, and plot a chart in the end as well. Be careful, First, I need to run the brinson attribution grouping by industry. I recommand you using 4 additional serials, you can call it Q1 Q2 Q3 and Q4. Q1= sigma benchmark weight * benchmark return in each industry. Q2= sigma portfolio weight * benchmark return in each industry. Q3= sigma benchmark weight * portfolio return in each industry. Q4= sigma portfolio weight * portfolio return in each industry. As you can see, excess return=Q4 - Q1, allocation effect = Q2-Q1, Selection effect =Q3-Q1, and interaction effect= Q4 - Q3 - Q2 + Q1. Second, When running multi-period attribution. the excess rtn should be compounded correctly. For example when calculation the total effect of day1 to day2. you have the Q1 for day1 and Q1 for day2, then total Q1=Q1 day1 + (1+Q1 day1)*Q1 day2. then used the conpound Q values, you will get the right compund excess return and attribution result.