In this project, I create a market simulator that accepts trading orders and keeps track of a portfolio's value over time and then assesses the performance of that portfolio. My simulator calculates the total value of the portfolio for each day using adjusted closing prices. The value for each day is cash plus the current value of equities. My code keeps account of how many shares of each stock are in the portfolio on each day and how much cash is available on each day. Negative shares and negative cash are possible. Negative shares mean that the portfolio is in a short position for that stock. Negative cash means that I've borrowed money from the broker.
When a BUY order occurs, I add the appropriate number of shares to the count for that stock and subtract the appropriate cost of the shares from the cash account. The cost is determined using the adjusted close price for that stock on that day. When a SELL order occurs, it works in reverse: I subtract the number of shares from the count and add to the cash account.
The following factors are reported:
Price history plot over the trading period. Sharpe ratio (Assumes 252 trading days in a year. And risk-free rate = 0) of the total portfolio Cumulative return of the total portfolio The standard deviation of daily returns of the total portfolio Average daily return of the total portfolio Ending value of the portfolio
Transaction costs are an important consideration for investing strategy. Transaction costs include things like commissions, slippage, market impact, and tax considerations. For this project, I consider two components of transaction cost: Commissions and market impact.
Commissions: For each trade that I execute, a commission is charged according to the parameter sent. It is treated that as a deduction from my cash balance.
Market impact: For each trade that I execute, I assume that the stock price moves against me according to the impact parameter.

Log in or sign up for Devpost to join the conversation.