Answer to Question #301809 in Python for cronus

Question #301809

# You work at a low latency trading firm and are asked to deliver the order book data provided in order_book_data.txt to a superior

# The problem is that the data isn't formatted correctly. Please complete the following steps to apropriately format the data

1. Open order_book_data.tx

3. Get rid empty lines

4. Get rid of spaces

5. Notice that there are two currencies in the order book; USD and YEN. Please convert both the Bid and Ask price to USD

6. Create a header line ['Symbol,Date,Bid,Ask']

7. Save the header line and properly formatted lines to a comma seperated value file called mktDataFormat.csv


1
Expert's answer
2022-02-24T04:20:02-0500
import csv
import rhinoscriptsyntax as rs

def CSVlist():
    #prompt the user for a file to import
    filter = "CSV file (*.csv)|*.csv|*.txt|All Files (*.*)|*.*||"
    filename = rs.OpenFileName("Open Point File", filter)
    if not filename: return

    with open(filename) as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            x = float(row[0])
            y = float(row[1])
            z = float(row[2])
            print x, y, z
            rs.AddPoint(x,y,z)

if( __name__ == "__main__" ):
    CSVlist()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS