Question

In: Computer Science

Need to replace the 0's in Bid/Ask column with "Bid" and the 1's with "Ask" using...

Need to replace the 0's in Bid/Ask column with "Bid" and the 1's with "Ask" using Python.

For line in lines:

line = line.replace(",0,","Bid") etc did not work

Time,Bid\Ask,Price,Volume

05:08.627012,0,1.16198,10000000.0
05:08.627012,1,1.16232,10000000.0

05:08.627012,0,1.16198,10000000.0
05:12.721536,0,1.16209,1000000.0
05:08.627012,1,1.16232,10000000.0

05:08.627012,0,1.16198,10000000.0
05:12.721536,0,1.16209,1000000.0
05:12.729989,1,1.16218,1000000.0
05:08.627012,1,1.16232,10000000.0

05:08.627012,0,1.16198,10000000.0
05:12.735727,0,1.16208,1000000.0
05:12.729989,1,1.16218,1000000.0
05:08.627012,1,1.16232,10000000.0

Solutions

Expert Solution

PROGRAM :

# lines from the question
lines = ["05:08.627012,0,1.16198,10000000.0" ,
        "05:08.627012,1,1.16232,10000000.0" ,
        "05:08.627012,0,1.16198,10000000.0" ,
        "05:12.721536,0,1.16209,1000000.0" ,
        "05:08.627012,1,1.16232,10000000.0" ,
        "05:08.627012,0,1.16198,10000000.0" ,
        "05:12.721536,0,1.16209,1000000.0" ,
        "05:12.729989,1,1.16218,1000000.0" ,
        "05:08.627012,1,1.16232,10000000.0" ,
        "05:08.627012,0,1.16198,10000000.0" ,
        "05:12.735727,0,1.16208,1000000.0" ,
        "05:12.729989,1,1.16218,1000000.0" ,
        "05:08.627012,1,1.16232,10000000.0"]
# bid_ask(x) function which returns "Bid" if value is 0 or else "Ask"
def bid_ask(x):
        if x=='0':
                return "Bid"
        elif x=='1':
                return "Ask"
# new_lines to store the replaced list
new_lines = []
# iterating the lines list
for line in lines :
        # splitting using comma operator and store it as a list
        split_list = line.split(',')
        # replacing the Bid/Ask column with the respective values by calling bid_ask function
        split_list[1] = bid_ask(split_list[1])
        # joining back the list items which we split in the previous steps in the same format using comma operator
        temp_string = ','.join(split_list)
        # appending the strings to a new list
        new_lines.append(temp_string)
print("The original list is :")
print(lines)
print("\nThe modified list is :")
print(new_lines)

OUTPUT:


Related Solutions

Homework 1 on Triangular Arbitrage with Bid-Ask Spread S (€ / £) = S ($ /...
Homework 1 on Triangular Arbitrage with Bid-Ask Spread S (€ / £) = S ($ / £) / S ( $ / €) Suppose Citibank’s quote: $1.5445 – 1.5460 / € Barclay’s quote: $1.9443 – 1.9453 / £ Dresdner’s quote: €1.2789 – 1.2799 / £ Cross-rate between Citibank and Barclay should be € 1.2589 / ₤, compared to the actual Dresdner quote of €1.2789 / ₤. Is triangular arbitrage possible if an investor starts with € 1 million and follows...
Variable $ ¥ R (Bid deposit) 2% 6% R (ask borrowing) 3% 7% S ($ask/¥Bid) $1.3450/¥...
Variable $ ¥ R (Bid deposit) 2% 6% R (ask borrowing) 3% 7% S ($ask/¥Bid) $1.3450/¥ $1.3450/¥ S ($bid/¥ask) $1.4150/¥ $1.4150/¥ F ($ask/¥Bid) $1.3200/¥ $1.3200/¥ F ($bid/¥ask) $1.3500/¥ $1.3500/¥ 1. Suppose an American with $5 million dollars invests for one year a. In which country do you advise them to invest? (Show work) b. Calculate their profit 2. Suppose a chinese client has 5million yuan to invest for one year a. In which country do you advise them to invest?...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
Assume the following information: USD/AUD, bid/ask: 0.7 / 0.75 USD/MXP, bid/ask: 0.074 / 0.076 MXP/AUD, bid/ask:...
Assume the following information: USD/AUD, bid/ask: 0.7 / 0.75 USD/MXP, bid/ask: 0.074 / 0.076 MXP/AUD, bid/ask: 8.13 / 8.32 Assume you have 1 million USD to conduct one cycle of triangular arbitrage. What will be your profit from implementing this strategy? Remember to pay careful attention whether you're trading at the bid or the ask with the bank.
​Bid/Ask on Aussie Dollar Forward. Use the following spot and forward​ bid-ask rates for the U.S.​...
​Bid/Ask on Aussie Dollar Forward. Use the following spot and forward​ bid-ask rates for the U.S.​ dollar/Australian dollar ​(US$=A$1.00​) exchange rate from December​ 10, 2010, to answer the following​ questions: a. What is the midrate for each​ maturity? b. What is the annual forward premium for all​ maturities? c. Which maturities have the smallest and largest forward​ premiums?  ​(Click on the    icon to import the table into a​ spreadsheet.) Period Bid Rate Ask Rate spot 0.98490 0.98512 1 month...
1) At Bank X, the bid rate of a NZD is USD 0.630 and the ask...
1) At Bank X, the bid rate of a NZD is USD 0.630 and the ask rate is USD 0.635. However, at Bank Y, the bid rate of the NZD is USD 0.628 and the ask rate is USD 0.631. What would be your profit if you use USD 1,000,000 and try to execute locational arbitrage? A) + USD 11,146.50 B) + USD 1,587.30 C) - USD 1,584.79 D) - USD 11,023.62 2) At Bank X, the bid rate of...
Spot rates are $.1325/MXN bid and $.1345/MXN ask and C$.874/$ bid and C$.876/ask. What are the...
Spot rates are $.1325/MXN bid and $.1345/MXN ask and C$.874/$ bid and C$.876/ask. What are the MXN/C$ big and MXN/C$ ask to 4 decimal places?
Suppose the current spot rates are $.135/MXN bid and $.140/MXN ask, combined with current spot rates of €.775/$ bid and €.785/$ ask.
Suppose the current spot rates are $.135/MXN bid and $.140/MXN ask, combined with current spot rates of €.775/$ bid and €.785/$ ask. What are the MXN/€ bid and MXN/€ ask prices? (to 4 decimal places)MXN/€ bid:       MXN/€ ask
Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&... Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&-2&0)],Vector_4=[Column(1&-2&-2)]. Show tha
Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&... Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&-2&0)],Vector_4=[Column(1&-2&-2)]. Show that S={Vector_1,Vector_2,Vector_3,Vector_4} is linearly dependent. Show that Vector_3 can be written as a linear combination of Vector_1,Vector_2 and Vector_4. Show that T={Vector_1,Vector_2,Vector_4} is linearly independent. Show that the set of all linear combinations of vectors from S is the same as the set of all linear combinations of vectors from T.
Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&... Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&-2&0)],Vector_4=[Column(1&-2&-2)]. Show tha
Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&... Let Vector_1=[Column (1 &-2&1)],Vector_2=[Column(2&-1&1)],Vector_3=[Column(-2&-2&0)],Vector_4=[Column(1&-2&-2)]. Show that S={Vector_1,Vector_2,Vector_3,Vector_4} is linearly dependent. Show that Vector_3 can be written as a linear combination of Vector_1,Vector_2 and Vector_4. Show that T={Vector_1,Vector_2,Vector_4} is linearly independent. Show that the set of all linear combinations of vectors from S is the same as the set of all linear combinations of vectors from T.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT