2173 Salk Avenue, Suite 250 Carlsbad, CA

support@assignmentprep.info

Write a function called is_special_word that takes a string as input and returns a bool indicating whether this string is a “special word.”

September 30, 2021
Christopher R. Teeple

Problem Set 1
This problem set has two primary parts. In each part you are asked to write one or more functions that I will test with different inputs (simliar to what we did in the Labs). Don’t jump around. Do part 1A, then 1B, etc. I really want you to push yourself to do this on your own. I’m here to help if needed, but only after you’ve spent some time on your own. Start early and then when you’ve reached the point where you can’t get anything else done, take a break for a few hours or a day. Then come back and work on it some more.
When you are done with a part, run the tests to make sure everything is working. There are three or four tests for each part for a total of 25 tests. When you pass all the tests, hit the Submit button
Part 1: Base Python
Here we will use Base Python to write a couple functions for us. NumPy is not needed. iPython is installed just to make things easier for you to test.
1A: Special Words
Write a function called is_special_word that takes a string as input and returns a bool indicating whether this string is a “special word.” For our purposes, a special word is one where at least one of the characters is a string representation of a number.
Inputs
the_string the string to be checked for being a special word.
Example:
Input: the_string = “The”
Output: False
Input: the_string = “f7s”
Output: True
1B: Counting Words
Write a function called word_count that takes a string as input and returns a dictionary with unique word count of special words in the string. Special words are those described above. Each word in the string is separated by a space.
Inputs
the_string the string to count special words within.
Example:
Input: the_string = “The rain in Spain stays mainly in the plain.”
Output: {}
Input: the_string = “T7 t7 hi 9 there t7”
Output: {‘T7’: 1, ‘t7’: 2, ‘9’: 1}
1C: Weird Multiplication
I’ve invented a new way to do multiplication for whole numbers. For this, you take the number in the one’s place and multiply it by all the numbers not in the one’s place. However, if the number in the one’s place is a zero, you don’t do the multiplication and instead drop the zero (see the example below). You continue with this process until the number is a single digit (between 1 and 9). Write a function called weird_multiplication that implements this.
Inputs
the_number the number for which we want to perform this weird multiplication.
Example:
Input: the_number = 345
Output: 7
Explanation: 34 * 5 = 170. The one’s place is a zero, so we drop the zero to get 17. Finally, 1 * 7 = 7.
Part 2: Binomial Model for Option Pricing
The binomial model for options pricing is based on the idea that an investment can either go up or down in any given time interval. To simplify things, let’s imagine we are talking about a stock with a current_price before the start market opens today and that will either go up by price_percent_change or down by price_percent_change at the end of the day. The probability that the price goes up is prob_up.
2A: Binomial Stock Prices
Write a function binomial_stock_prices that simulates stock prices using a binomal pricing model as described above. The number of days and number of times to simulate should be included as inputs. The output should be a 2-d array with num_simulations rows and num_days columns where each item in the matrix is the price of the stock on the simulation-day.
Inputs
current_price the price of the stock today (at day zero).
num_simulations the number of different stock prices to simulate.
num_days the number of days to simulate for each simulation.
price_percent_change the percent amount of price increases or decreases from one day to the next. For example, a 5% change would be price_percent_change = 0.05.
prob_up the probability that the price increases with default of 0.5
random_seed the random seed to use for NumPy’s random number generation with default 13579
Example:
Input: binomial_stock_prices(current_price = 90, num_simulations = 5, num_days = 3, price_percent_change = 0.03, prob_up = 0.5, random_seed = 13579)
Output: array([[92.7 , 95.481 , 98.34543], [87.3 , 89.919 , 87.22143], [87.3 , 84.681 , 82.14057], [92.7 , 95.481 , 92.61657], [87.3 , 84.681 , 82.14057]])
2B: European Call Option
A European call option gives the owner the right, but not the obligation, to buy a stock for a strike_price at an ending time num_days from now. You will only exercise a European call option if the ending_price (i.e, the price num_days from now) is greater than the strike_price. Exercise the option means you agree to buy the stock for the strike_price. At that point you would then sell the stock in the open market and get ending_price – strike_price in profit. If the ending_price is below the strike_price then you don’t buy the stock and you make no profit.
Write a function european_call_option returns the average profit for a given set of inputs.
Inputs
current_price the price of the stock today (at day zero).
strike_price the price at which you can buy the stock after num_days.
num_simulations the number of different stock prices to simulate.
num_days the number of days to simulate for each simulation.
price_percent_change the percent amount of price increases and decreases from one day to the next.
prob_up the probability that the price increases with default of 0.5
random_seed the random seed to use for NumPy’s random number generation with default 13579
Example:
Input: european_call_option(current_price = 90, strike_price = 85, num_simulations = 5, num_days = 3, price_percent_change = 0.03, prob_up = 0.5, random_seed = 13579)
Output: 4.636685999999997
2C: Lookback Call Option
A lookback call option gives the owner the right, but not the obligation, to buy a stock for a strike_price at an ending time num_days from now and sell the stock at max_price, the maximum price observed from now until num_days from now . You will only exercise a lookback call option if the max_price is greater than the strike_price. Exercise the option means you agree to buy the stock for the strike_price. At that point you would then sell the stock for max_price and get max_price – strike_price in profit. If the max_price is below the strike_price then you don’t buy the stock and you make no profit.
Write a function lookback_call_option returns the average profit for a given set of inputs.
Inputs
current_price the price of the stock today (at day zero).
strike_price the price at which you can buy the stock after num_days.
num_simulations the number of different stock prices to simulate.
num_days the number of days to simulate for each simulation.
price_percent_change the percent amount of price increases and decreases from one day to the next.
prob_up the probability that the price increases with default of 0.5
random_seed the random seed to use for NumPy’s random number generation with default 13579
Example:
Input: lookback_call_option(current_price = 90, strike_price = 85, num_simulations = 5, num_days = 3, price_percent_change = 0.03, prob_up = 0.5, random_seed = 13579)
Output: 6.669085999999996
2D: Volatility Option
This option gives you the right, but not the obligation to buy the stock for ending_price * volatility_ratio in num_days if the volatility_ratio is greater than a volatility_ratio_threshold. The volatility_ratio is the standard deviation of simulated_stock_prices across all days, divided by the average of simulated_stock_prices.
Write a function volatility_option returns the average profit for a given set of inputs.
Inputs
current_price the price of the stock today (at day zero).
volatility_ratio_threshold the required ratio of standard deviation of stock price to average stock price to activate the option.
num_simulations the number of different stock prices to simulate.
num_days the number of days to simulate for each simulation.
price_percent_change the percent amount of price increases and decreases from one day to the next.
prob_up the probability that the price increases with default of 0.5
random_seed the random seed to use for NumPy’s random number generation with default 13579
Example:
Input: volatility_option(current_price = 90, volatility_ratio_threshold = 0.02, num_simulations = 5, num_days = 3, price_percent_change = 0.03, prob_up = 0.5, random_seed = 13579)
Output: 51.23362477025618
2E: Dual Stock Gamble
In a dual stock gamble, we simulate two different stocks. The payout at the end can be either positive or negative. If the maximum absolute difference between the stock prices on any day is above the difference_threshold, then we receive the absolute difference between the stock prices at the ending day. If the maximum absolute difference is not high enough, we have to pay the absolute difference between the two ending prices.
Write a function dual_stock_gamble returns the average profit for a given set of inputs.
NOTE: To implement the two different stocks, use random_seed as an input for one of them and random_seed + 1 as an input for the other. If you do this any other way you will not get the results I get.
Inputs
current_price the price of the stock today (at day zero).
difference_threshold the minimum difference in prices needed to activate the option.
num_simulations the number of different stock prices to simulate.
num_days the number of days to simulate for each simulation.
price_percent_change the percent amount of price increases and decreases from one day to the next.
prob_up the probability that the price increases with default of 0.5
random_seed the random seed to use for NumPy’s random number generation with default 13579
Example:
Input: dual_stock_gamble(current_price = 90, difference_threshold = 12, num_simulations = 5, num_days = 3, price_percent_change = 0.03, prob_up = 0.5, random_seed = 13579)
Output: 4.257143999999999

Struggling With a Similar Paper? Get Reliable Help Now.

Delivered on time. Plagiarism-free. Good Grades.

What is this?

It’s a homework service designed by a team of 23 writers based in Carlsbad, CA with one specific goal – to help students just like you complete their assignments on time and get good grades!

Why do you do it?

Because getting a degree is hard these days! With many students being forced to juggle between demanding careers, family life and a rigorous academic schedule. Having a helping hand from time to time goes a long way in making sure you get to the finish line with your sanity intact!

How does it work?

You have an assignment you need help with. Instead of struggling on this alone, you give us your assignment instructions, we select a team of 2 writers to work on your paper, after it’s done we send it to you via email.

What kind of writer will work on my paper?

Our support team will assign your paper to a team of 2 writers with a background in your degree – For example, if you have a nursing paper we will select a team with a nursing background. The main writer will handle the research and writing part while the second writer will proof the paper for grammar, formatting & referencing mistakes if any.

Our team is comprised of native English speakers working exclusively from the United States. 

Will the paper be original?

Yes! It will be just as if you wrote the paper yourself! Completely original, written from your scratch following your specific instructions.

Is it free?

No, it’s a paid service. You pay for someone to work on your assignment for you.

Is it legit? Can I trust you?

Completely legit, backed by an iron-clad money back guarantee. We’ve been doing this since 2007 – helping students like you get through college.

Will you deliver it on time?

Absolutely! We understand you have a really tight deadline and you need this delivered a few hours before your deadline so you can look at it before turning it in.

Can you get me a good grade? It’s my final project and I need a good grade.

Yes! We only pick projects where we are sure we’ll deliver good grades.

What do you need to get started on my paper?

* The full assignment instructions as they appear on your school account.

* If a Grading Rubric is present, make sure to attach it.

* Include any special announcements or emails you might have gotten from your Professor pertaining to this assignment.

* Any templates or additional files required to complete the assignment.

How do I place an order?

You can do so through our custom order page here or you can talk to our live chat team and they’ll guide you on how to do this.

How will I receive my paper?

We will send it to your email. Please make sure to provide us with your best email – we’ll be using this to communicate to you throughout the whole process.

Getting Your Paper Today is as Simple as ABC

No more missed deadlines! No more late points deductions!

}

You give us your assignments instructions via email or through our order page.

Our support team selects a qualified writing team of 2 writers for you.

l

In under 5 minutes after you place your order, research & writing begins.

Complete paper is delivered to your email before your deadline is up.

Want A Good Grade?

Get a professional writer who has worked on a similar assignment to do this paper for you