代做Data Science for Finance Problem Set 1帮做Python编程
- 首页 >> C/C++编程Data Science for Finance
Problem Set 1
Exercise 1:
Consider three variables A, B and C. Each variable has a specific value assigned.
Write a code so that B takes the value of A, C takes the value of B and A takes
the value of C
Example:
A=1, B=2, C=3.
Your Code …
A=3, B=1, C=2
Exercise 2:
a) Create two variables, one containing a stock ticker and another
containing the current stock price. Display them using print. (You can
find the stock information using Yahoo finance website)
b) Now transfer the variable values into a list and display the list.
c) Take the variables and now store the values in a dictionary, using keys
‘ticker’ and ‘price’. Display dictionary values.
Exercise 3:
Create a python script. that allows users to input two names and compute the
similarity score between two names.
a) Use the syntax var = input(“please enter a name: ”) to
ask the user to two names and assign them to two variables.
b) Transform. the names to lowercase.
c) Convert both names into two sets
d) Generate the intersection and union of these two sets
e) Compute the similarity score using the following formula:
Where S is the similarity score, |A n B| is the size of the intersection of
these two sets, |A n B| is the size of the union of these two sets.
Exercise 4:
A derivative asset (https://en.wikipedia.org/wiki/Derivative_(finance)) has the following valuation rule:
a)
• If the stock priceS is greater than 50 dollars, then the intrinsic value of the asset is S-50.
• If the stock price is less than or equal to 50 dollars, then the intrinsic value of the asset is 0.
Without using if statement which we will learn in the next lecture, write a program that inputs the stock price and returns the intrinsic value accordingly.
b)
• If the stock priceS is greater than 50 dollars and less than 100 dollars, then the intrinsic value of the asset is S-50.
• If the stock price is greater than or equal to 100 dollars, then the intrinsic value of the asset is 0.
• If the stock price is less than or equal to 50 dollars, then the intrinsic value of the asset is 0.
Without using if statement which we will learn in the next lecture, write a program that inputs the stock price and returns the intrinsic value accordingly.
Exercise 5:
Write a program that computes the net present value (NPV) of a project, given a
discount rate, an initial investment and a stream of future cash flows.
Where I is the initial investment, CFi is the cash flow received in year i, r is the
annualized discount rate, N is the total number of yearly cash flows.
Example:
. r = 0.07
. I = 100000
. CF = (10000,25000,30000,50000) You can use tuple for CF.
. Output in the window:
Should we invest in the project?