QuestionQuestion

Teza Programming Assignment - Offsite
Given a list of information about fills for different stocks, calculate the total profit or loss accrued for each symbol.
The attached text file contains the following columns:
- time: Date and time of fill
- symbol: Symbol of product
- price: Price of fill
- buy_sell: Side of fill
- qty: Qty of fill
Write a python script that calculates total PNL per symbol. You may ignore any trading costs (just calculate Gross PNL). The output should be a csv with just two columns: symbol, total_pnl, and one row per symbol.
Important: You may assume/confirm that positions are flat after totaling all buys and sells (both on a per-symbol basis, and subsequently overall). In other words, you only need to worry about realized PNL – there should be no open positions with unrealized pnl left to mark to any particular price.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

# open the data file to read
datafile = open("teza_fills.csv", "r")

# skip first line with headers
datafile.readline()

# read the data in datafile and calculate PNL for each symbol of product
pnl = dict() # a dictionary to store PNLs
for line in datafile:
    # split the line by commas
    tokens = line.strip().split(",")
   
    # obtain details of the entry
    symbol = tokens[1]
    price = float(tokens[2])
    buy_sell = tokens[3]
    qty = int(tokens...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats