S05 if and for

.py

School

University of Illinois, Urbana Champaign *

*We aren’t endorsed by this school

Course

558

Subject

Computer Science

Date

Oct 30, 2023

Type

py

Pages

7

Uploaded by LieutenantFog11660

Report
# -*- coding: utf-8 -*- """ S05 control; if, for, while @author: Dr. Taek Pae, CFA """ #%% If statement sp500_rtn = -0.02 if sp500_rtn > 0.01: print('good day') sp500_rtn = 0.02 if sp500_rtn > 0.01: print('good day') p0 = 10.5 p1 = 11 if p1 > p0: rtn = p1 / p0 - 1 print(round(rtn, 2)) if (p1 > p0) == True: rtn = p1 / p0 - 1 print(round(rtn, 2)) if input('Enter True or False :'): print('Yes') # cannot distinguish True or False. no input -> false if bool(input('Enter True or False :')): print('Yes') # cannot distinguish True or False. no input -> false if input('Enter True or False :') == 'True': print('Yes') # does not understand True or False but simply compare the string. if input('Enter 0 or 1 :'): print('Yes') # cannot distinguish True or False, no input -> false if int(input('Enter 0 or 1 :')): print('Yes') # now it can. #%% If else # call option profit p = 120 k = 100 if p > k: profit = p - k else:
profit = 0 profit # put option profit if p < k: profit = k - p else: profit = 0 profit # practice 1 # collect expected returns of stock and bond ETFs from screen using input() # print 'stock' (or 'bond') if expected return of stock is larger (less) than bond. # for example, # Enter expected return of stock ETF: 0.1 # Enter expected return of bond ETF: 0.05 # stock r_s = float(input("Enter expected return of stock ETF: ")) r_b = float(input("Enter expected return of bond ETF: ")) if r_s > r_b: print('stock') else: print('bond') #%% if elif MA30 = -5 MA50 = -1 if (MA30 > 0) and (MA50 > 0): print('buy') elif (MA30 > 0) and (MA50 < 0): print('hold') elif (MA30 < 0) and (MA50 < 0): print('sell') else: # (MA30 < 0) and (MA50 > 0) print('do nothing') # option in the money out of the money option = 'call' price = 20 strike = 10 if option == 'call': if price > strike: print('In the money') else: print('Out of the money') elif option == 'put': if price < strike: print('In the money') else:
print('Out of the money') else: print('check your input') option='put' # and run the above lines again # practice 2 # make a function that returns profit of a call or a put option. # input parameters: option_type ('call' or 'put'), price, strike_price # def option_profit(option_type, price, strike): #%% For loop # for loop with a tuple t = (1, 2.5, 'data') for item in t: print(item) for i in range(len(t)): print(t[i]) # for loop with a set s = {'stock', 'bond', 'money market'} for item in s: print(item) # for loop with dictionary d = {'Name': 'Warren Buffett', 'Country': 'USA', 'Profession': 'Investor', 'Age': 92} for k in d: print(k) #calling values for k in d: print(d[k]) #calling items for k in d.keys(): #more specific print(k) for v in d.values(): print(v) for key, value in d.items(): print(key, value) # future value of an annuity N = 30 PMT = 30000 r = 0.05 # 5%
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: In class, we learned Huffman Code. It is used to encode a set of characters using binary code (0 and…
Q: Using set notation, formalize the language that a turning machine will take.
Q: Which was the better leaving group, bromine or chlorine? Give a reason for your answer. Are the…
Q: Several months ago while shopping, I was interviewed to see whether or not I'd be interested in…
Q: Ages of Proofreaders At a large publishing company, the mean age of proofreaders is 36.2 years and…
Q: H H // H H Chair 1 H Cl chair flip Answer Bank H Br H H H Chair 2 H H H
Q: a. b. C. 12.5 d. 12 14 10 0 Refer to Figure 1. The firm should shut down if the market price is…
Q: Explain why the function is differentiable at the given point. f(x, y) = 3 +exycos(y), (,0) The…
Q: There are two isotopes of an unknown element, X-19 and X-21. The abundance of X-19 is 14.29%. A…
Q: Evaluate the triple integral JJ (x + 3y) E is bounded by the parabolic cylinder y = 9x² and the…
Q: 14. For each of these scenarios, indicate which direction the variable goes: a. If interest rate…
Q: Use a spreadsheet program, such as Microsoft Excel, to graph the data points and determine the…
Q: Perform a wo-tailed test. Then complete the parts below. Carry your intermediate computations to…
Q: What is the maximum mass of Sg that can be produced by combining 78.0 g of each reactant? 8 SO₂ + 16…
Q: Determine whether the Mean Value theorem can be applied to f on the closed interval [a, b]. (Select…
Q: Solve the following system, using Gaussian elimination or Gauss-Jordan elimination 2Y+3Z = 8 2X…
Q: For the matrix A, find (if possible) a nonsingular matrix P such that P-¹AP is diagonal. (If not…
Q: Draw the dipeptide KQ (condensed structure),
Q: can you explain how can i sove this ? 8 - { 7x - [2 + ( x -1 ) ] + 4 } it is a polynomio
Q: Figure 11-1     Rival in Consumption?     Yes No Excludable? Yes  A B No C D           Refer to…
Q: Calculate the flux of the vector field F(x, y, z) = 8yj through a square of side length 5 in the…
Q: If E is the solid described below with density function P(x, Y, 2) = x + y, find the following…