Finance: Markowitz portfolio variance

Background

I wanted to learn about finance, so I started to take some courses in it. It’s been nearly a year, and I have learned a ton. To help reinforce what I’ve learned (and to share the knowledge), I plan to write about finance every once in a while. For this first article on finance, I wanted to write about the Markowitz portfolio variance.

In finance, one of the most important discoveries was by Harry Markowitz when he figured out how to measure the portfolio variance. It is used in modern portfolio theory to estimate the combination of investments that would reduce idiosyncratic risk, which is inherit in the asset (or a group of assets). Idiosyncratic risk is unrelated to the risk in the market. Rather, it is the risks when assets that you invest in are correlated with each other. The more correlated they are, the more risky they become.

Assets that are part of the same sector or type tend to be correlated with each other. For instance, General Motors is an automobile company, and its stock price will likely be correlated with another automobile company like Ford Motors. If you want to diversify your portfolio, investing in both General Motors and Ford Motors increases your idiosyncratic risk since both investments would be part of the same sector. If one of these firms does poorly, it is likely that the other firm will do poorly.

Markowitz was able to develop an equation that would capture the idiosyncratic risk associated with a combination of assets in an investment. His portfolio management variance calculation uses the standard deviation of one asset (Asset A) and its correlation with another asset (Asset B). In other words, Markowitz’s formula incorporates the correlation between assets. By incorporating the correlation between assets, an investor can estimate the idiosyncratic risk of their investment strategy and avoid stocks in market sectors that would potentially be a greater risk due to their correlation.

Markowitz’s portfolio variance formula for a combination of two assets (i and j) is structured as:

where:

  • sigma_p^2 is the portfolio variance

  • w_i is the weight of Asset i

  • w_j is the weight of Asset j

  • sigma_i^2 is the variance of Asset i

  • sigma_j^2 is the variance of Asset j

  • rho_{i, j} is the correlation between Assets i and j

We can simplify this expression for a two-asset portfolio as:

Motivating Example

Let’s look at an example. Suppose we have two assets (i and j) that we want to diversify our portfolio with. We’re concerned about the idiosyncratic risk between the two. We can use this formula to estimate the idiosyncratic risk. (Note: You can download the Excel exercise from my GitHub repository here.)

Here is the data for the returns for Assets i and j:

We can estimate the average returns for Assets i and j along with their standard deviations.

Then, we can estimate the covariance between the two assets’ returns.

Next, we need to apply weights to the assets. Let’s assume that we want to place more weight to Asset i compared to Asset j. The weight for Asset i will be 0.85; hence, the weight for Asset j is 0.15 (or 1 – 0.85). The sum of the asset weights need to be 1.

Once we have estimated all the parameters, we can now combine them using the Markowitz portfolio variance formula.

The idiosyncratic risk is 0.0043, which is pretty low since the correlation between Asset i and Asset j is very small (rho = -0.000156).

 

Concluding thoughts

There is more to modern portfolio management, but this is just the first part. As we continue in future lessons, we will build upon this knowledge by learning about how we can use the Markowitz portfolio variance to determine the risk and return tradeoffs.

 

Disclosure and Disclaimer

Since this is a work in progress, expect updates in the future.

Meanwhile, this is for educational purposes only

 

References

You can learn more about Harry Markowitz on Wikipedia here.

You can also learn more about portfolio variance on Investopedia here.

You can download the Excel exercise from my GitHub repository here.

Two-Part Model with Bootstrap using R

In this article, I wanted to expand on a previous post that describes using a two-part model to model cost (or total expenditure) as an outcome with data from the Agency for Healthcare Research and Quality (AHRQ) Medical Expenditure Panel Survey (MEPS). In the previous article, I used the twopartm package, which is great at leveraging the two-part model approach. However, it does not appear to handle data from complex survey designs like MEPS.

The best way to handle complex survey design data with weights using the two-part model approach is to perform the estimations for each part separately and then combine them.

With a little help from some AI chatbots, I was able to construct a viable code that not only estimates and combines both parts of the two-part model, but also allows me to bootstrap the results to generate 95% confidence intervals (CI).

The complete article on how to construct a two-part model with bootstrap using R is available on my RPubs site (link)

One-sample z-test of proportions in R

There are situations where you will be asked to compare the performance of your institution with another institution. This is commonly done with projects that I’m on where data collection occurs at a single site, and stakeholders want to compare the single site’s findings with a reference site. More commonly, stakeholders want to compare their performance to a published paper’s findings. In other words, we want to compare an observed finding to a theoretical one.

In the case of proportions, we can compare the proportion of individuals who experienced an event in single site to the proportion from a published study. To do that, we can use the one-sample z-test of proportions.

I wrote a guide on how to perform one-sample z-test of proportions to determine if the proportion of events observed is significantly different from an expected proportion, which is available on my RPubs site (link).

Literary Cafe series: Patterns and costs of GLP1-RA (Part 1) - Getting data from MEPS

In this Literary Cafe series, I attempt to reproduce the findings from Wu and colleagues’ paper, “Patterns and costs associated with glucagon-like peptide-1 receptor agonist use in US adults with type 2 diabetes“ (link).

In this first part (with subsequent parts to follow), I demonstrate how we can use the same publicly available data from the Agency of Healthcare Research and Quality (AHRQ) Medical Expenditure Panel Survey (MEPS) to reproduce the sample used by Wu and colleagues in their study (link).

I published this article in my RPubs page (link).

Literary Cafe series: Policy analysis (Part 2) - Interrupted Times Series Analysis with publicly available data

I’m back with some Literary Cafe series updates.

I have regularly informal discussions with my students about interesting papers in the biomedical sciences. Recently, we discussed a great paper by Jurecka and colleagues on the impact of a state-wide law to change the definition of fentanyl possession on opioid-related overdose death rates.

Jurecka and colleagues used publicly available data to perform their research, and I wanted to show my students how this was done using CDC WONDER data. Hence, I started this Literary Care series to document these exercises for others to learn from.

Last month, I wrote an article on how to get data from the CDC WONDER site, which you can read here. I considered this Part 1 (Getting the data).

This is the second part of a two-part series that illustrates how to use publicly available data to replicate the findings from a published study. In Part 2, I use the data from Part 1 to analyze the impact of the statwide fentanyl possession law on opioid-related overdose death rates using an interrupted time series analysis. I posted this on my RPubs site (link) along with part 1 (link).

Literary Cafe series - Policy Analysis (Part 1): Getting Data From CDC WONDER

This is Part 1 on a series of articles that I plan to write on how to perform analyses using publicly available data inspired by published studies.

Hence, I wrote an article on how to get death data from CDC WONDER, which I posted on my RPubs site here.

I’m not sure how these articles will evolve, so I’ll start with something simple like this first part, which is to gather the data to perform the analysis (Part 2 is available here).

Meanwhile, I think I’ll call these series of articles, “Literary Cafe series.” (Note: I know that this title needs work.)

Is there a Principal-Agent problem between large retail-chain pharmacy corporations and community pharmacists?

Is there a Principal-Agent problem between large retail-chain pharmacy corporations and community pharmacists?

 

Date: 31 October 2025

 

(This is part of a working paper. Updates are expected.)

 

The principal-agent problem is a type of market failure involving a misalignment of incentives between the owners of a company or firm (principals) and the employees that they hire (agents).[1] The conflict arises when the agents (or employees) do not act in accordance with the interest or expectation of the principals (firm). Principals delegate the agents to represent their interest, oftentimes providing them with decision-making capabilities. However, the principals cannot control the agents, nor do they have the same level of information as the agents (asymmetric information). This conflict can lead to non-Pareto optimal conditions, which would result in inefficiency and harm to both the principals and agents.

Misalignment of incentives is a central issue between large retail-chain pharmacy corporations and community pharmacists. Using the principal-agent problem framework, large retail-chain pharmacies (principals) hire community pharmacists (agents) to represent their interest to maximize their shareholder value (e.g., increased profits). However, community pharmacists are not interested in maximizing profits for the large retail-chain pharmacy corporations. Rather, they are interested in providing high-quality care to their patients and community, which is in direct conflict with the expectations of the large retail-chain pharmacy corporations. This misalignment of interests between the large retail-chain pharmacy corporations and community pharmacists has been responsible for unsafe working conditions, increased medication errors, pharmacist burnout and retention issues, and corporate bankruptcy.

This article will attempt to establish the misalignment between the large retail-chain pharmacy corporations and community pharmacists and offer some recommendations to address this principal-agent problem.

 

Misalignment of Incentives

A substantial number of licensed pharmacists work in the community pharmacy setting, which includes independent pharmacies, small and large retail chain pharmacies, supermarkets, mass merchandizers, and health-system retail pharmacies. In a 2024 work survey of pharmacists in the United States (US), 59.1% of pharmacists were working in the community setting, and, among those, 22.4% were working in large chain pharmacies.[2]

Large-chain retail pharmacy corporate leaderships are focused on maximizing shareholder value and downplaying the professional and ethical responsibilities of the pharmacist working in the community setting. Community pharmacists, on the other hand, often are not interested in these corporate incentives (e.g., increased earnings per share) and are focused on upholding their professional and ethical responsibilities to providing the highest quality care to their patients and community. Large retail chain pharmacy corporations expect their pharmacists to not only perform their duties as community pharmacists but also expect them to meet productivity performance measures such as filling and dispensing quotas. According to the California Code, Business and Professions Code,  a “quota” is defined as a fixed number or formula related to prescriptions filled, services rendered to patients, programs offered to patients, and revenue obtained as a means to evaluate or measure the performance of the pharmacy staff.[3] This practice of using quotas to evaluate the productivity performance of community pharmacists has resulted in unsafe working conditions, increased medication errors, and increased burnout and retention issues.[4] According to a 2020 survey conducted among community pharmacist in Ohio, 82% of respondents reported either “agreed” or “strongly agreed” with the statement, “I feel pressure by my employer or supervisor to meet standards or metrics that may interfere with safe patient care.”[5]

The burden of meeting productivity performance-based measures such as prescription quotas contribute to an unsafe work environment where medication errors can occur. Compound this with an increased workload and lack of proper staffing and resources, and the conditions for a serious medication error increase the probability of a serious event. In a 2024 workload report, 91% of pharmacists working at chain pharmacies reported having “high” or “excessively high” workload compared to 55% of pharmacists working at independent pharmacies.[2] Similar findings were reported in 2019, suggesting that this practice and culture has been normalized for many years. Additionally, 54.9% of community pharmacists responded that they “disagreed” or “strongly disagreed” with the statement that “My organization is willing to extend resources to help me perform my job to the best of my ability,” and 56.3% of community pharmacists reported that they “disagreed” or “strongly disagreed” with the statement, “My organization is committed to employee health and well-being.”

Another factor that complicates the principal-agent problem is the involvement of the pharmacy benefits management (PBM) that do not provide pharmacies with enough compensation for filling prescriptions.[6] The reimbursement rate for each prescription fill is often less than the cost of supply (e.g., label and bottle), which means that the community pharmacies are losing revenue with each fill. This has dangerous consequences as the large, chain retail pharmacy corporations will try to maximize profits by imposing unreasonable prescription fill quotas and decreasing staffing levels, thereby creating an unsafe work environment and causing pharmacist burnout.[7,8] Moreover, the lack of proper reimbursements for prescription fills has led to many pharmacies closing their doors. According Guadamuz and colleagues, 29.4% of pharmacies that were opened between 2010-2020 closed their doors in 2021.[9] Further, Rite-Aid, one of the largest retail-chain pharmacies in the US filed for bankruptcy in October 2025, partly due to poor reimbursements from PBMs.[10]

 

Recommendations

Given the market failure associated with this principal-agent problem, governmental action in the form of legal policy may be needed. For instance, California passed a law prohibiting chain community pharmacies from using quotas to measure the performance of pharmacy staff to address the concerns of rising medication errors due to unsafe work environments in 2021.[3,11] Shortly afterwards in October 2022, Walgreens, one of the largest retail-chain pharmacies in the US announced that they would abandon the use of quotas for productivity performance-based evaluations of pharmacy staff.[12] However, these changes have not eliminated the use of these productivity performance-based metrics, and misaligned incentives between large retail-chain pharmacy corporations and community pharmacists have continued to result in unsafe environments, increased medication errors, and increased burnout and retention issues. 

To address unsafe working conditions due to understaffing and resulting in increased medication errors, California Governor Gavin Newsom signed into law the “Stop Dangerous Pharmacies Act” (AB 1286) in 2024.[13] This bill, the first of its kind, requires large retail-chain pharmacies to staff their pharmacies with at least one pharmacy technician or clerk to assist with pharmacy-related services and to report all medication errors. Although current California law requires that pharmacies include a pharmacy staff to assist the pharmacist, this had not been enforced. The new bill will empower pharmacists to make staffing decisions instead of the large retail-chain pharmacy corporations thereby improving working conditions and reducing medication errors.   

In October 2025, California Governor Gavin Newsom signed into law Senate Bill 41 (SB-41) that impose upon pharmacy benefits managements (PBMs) a fiduciary duty to their clients, ban spread pricing (profiting from the difference in costs between health plans and pharmacies), and providing fair reimbursement to pharmacies.[14] This bill has important implications for pharmacies by improving their reimbursement rates for each prescription filled thereby allowing for improved a profit margin. For community pharmacists, this could lead to reduced burden from the large retail-chain pharmacy corporations to increase revenue through unreasonable prescription fill quotas. However, future evaluation will need to assess the effectiveness of this policy on the principal-agent problem between large retail-chain pharmacies and community pharmacists.   

 

Conclusions

In this brief article about the principal-agent problem between large retail-chain pharmacy corporations and pharmacists, I try to establish the framework for potential misaligned incentives leading to negative consequences. Pharmacists (agents) are delegated to represent the interests of the large retail-chain pharmacy corporations (principals), but their incentive to their professional oath and service to community are in direct conflict with the rent-seeking behaviors of large retail-chain pharmacy corporations. This conflict inevitably led to unsafe working conditions, increased medication errors, and increased burnout and retention issues. Recently legislation has been developed to address the issues of staffing, medication errors, and quotas to improve patient and community safety. However, the impact of these legal interventions has yet to be determined.

References

  1. Jensen MC, Meckling WH. Theory of the firm: Managerial behavior, agency costs and ownership structure. Journal of Financial Economics. 1976;3(4):305-360. doi:10.1016/0304-405X(76)90026-X

  2. Mott DA, Bakken BK, Nadi S, et al. Final Report of The 2024 National Pharmacist Workforce Survey. Pharmacy Workforce Center; 2024. https://www.aacp.org/article/national-pharmacist-workforce-studies

  3. California Code, Business and Professions Code - BPC § 4113.7.; 2023. Accessed October 31, 2025. https://codes.findlaw.com/ca/business-and-professions-code/bpc-sect-4113-7/

  4. O’Donnell J, Vogenberg FR. Imperatives for Oversight Of Professional Personnel. P T. 2015;40(11):744-774.

  5. Francis SG. Pharmacists’ Perceptions About the Effect of Work Environment Factors on Patient Safety in Large-Chain Retail Pharmacies. J Pharm Technol. 2022;38(6):376-378. doi:10.1177/87551225221116000

  6. Joyce G. The cost of misaligned incentives in the pharmaceutical supply chain. Health Aff Sch. 2025;3(7):qxaf126. doi:10.1093/haschl/qxaf126

  7. Mott D, Doucette W, Schommer J, Gaither CA. Opinion: Why your chain-store pharmacist is so unhappy. CNN. December 13, 2023. Accessed October 4, 2025. https://www.cnn.com/2023/12/13/opinions/pharmacy-working-conditions-mott-doucette-schommer-gaither

  8. Coz EL. Prescription for disaster: America’s broken pharmacy system in revolt over burnout and errors. USA TODAY. Accessed October 4, 2025. https://www.usatoday.com/story/news/investigations/2023/10/26/pharmacy-chains-dangerous-conditions-medication-errors/71153960007/

  9. Guadamuz JS, Alexander GC, Kanter GP, Qato DM. More US Pharmacies Closed Than Opened In 2018–21; Independent Pharmacies, Those In Black, Latinx Communities Most At Risk. Health Affairs. 2024;43(12):1703-1711. doi:10.1377/hlthaff.2024.00192

  10. Case Summary: Rite Aid Chapter 11. Bondoro. May 10, 2025. Accessed October 31, 2025. https://bondoro.com/rite-aid/

  11. SB 362- CHAPTERED. Accessed October 31, 2025. https://leginfo.legislature.ca.gov/faces/billTextClient.xhtml?bill_id=202120220SB362

  12. Kaplan A. Walgreens will stop judging its pharmacy staff by how fast they work. NBC News. October 28, 2022. Accessed October 31, 2025. https://www.nbcnews.com/health/health-care/walgreens-will-stop-judging-pharmacy-staff-fast-work-rcna54297

  13. Stop Dangerous Pharmacies Act is signed into California Law | Official Website - Assemblymember Matt Haney Representing the 17th California Assembly District. Accessed October 31, 2025. https://a17.asmdc.org/press-releases/20231009-stop-dangerous-pharmacies-act-signed-california-law

  14. California SB41 | 2025-2026 | Regular Session. LegiScan. Accessed October 31, 2025. https://legiscan.com/CA/bill/SB41/2025

R - Tips and Tricks (Guide) - Part 2

I wrote a second R guide to help students navigate and use R and RStudio in their biostatistics course. I focused on creating vectors, matrices, and dataframes.

The guide can be found on my RPubs site.

Ratio of risk ratios in R

I ran into a problem where I had two risk ratios, but I wanted to evaluate the statistical difference between them. I couldn’t find an R package, but I found a paper by Altman and Bland that go over the step-by-step process. I wrote a tutorial on how to perform this method using R, which is available on my RPubs page (link).

Reference:

Altman DG, Bland JM. Interaction revisited: the difference between two estimates. BMJ. 2003 Jan 25;326(7382):219. doi: 10.1136/bmj.326.7382.219. PMID: 12543843; PMCID: PMC1125071.