- Parent Category: Programming Assignments' Solutions
We Helped With This MATLAB Programming Assignment: Have A Similar One?
|More Info||Matlab Solve|
You will create a function that sends emails to hypothetical clients, giving the suggestion that a stock price will go up or down. The process works in the following way:
1. Given a set of emails addresses, the code splits them in two groups of equal size, say group A and group B. Emails in group A receive an email saying that the stock will go up, emails in group B receive an email saying that the stock will go down. The code then checks what happened to the stock price in reality (for simplicity, this will be randomly generated):
· if the stock went up, then the code focuses only on emails in group A (those that were told that stock will go up), split these emails in two groups (again, A and B) which respectively receive an email saying the stock will go up or down.
· if the stock went down, then it focus only on emails in group B (those that were told that stock will go down), split these emails in two groups (again, A and B) which respectively receive an email saying the stock will go up or down.
· Check the realization of the stock price, etc. etc.
Keeps iterating on this process until there is just a set of emails who always received a suggestion that was correct, given prices realised on the markets. Those clients will think you are a finance guru, since you gave them the right predictions all the times.
(This is just for teaching purposes, I remind you that financial fraud is a crime and leads to jail ).
Call the function financeguru. It splits your email addresses into two groups (|groupA| and groupB) and sends a message to each group. Group A gets the message 'The stock will go up today.'. Group B gets the message 'The stock will go down today.'.
The code then assesses what actually happened to the stock. To do this, we generate a random number with the command randn. If this number is positive, we interpret this as an increase in the stock price, hence the code takes the group A, splits it into two groups (let's call them again groupA and groupB), and sends the messages (stock up and stock down) to these subgroups. If instead, the randomly generated number is negative, this is interpreted as a decrease in the stock price, and hence the code takes the group B, splits it into two groups (let's call them again A and B), and sends the messages again to these subgroups (stock up and stock down).
Then the code generates another random number, based on this it focuses only on the group who received the correct prediction, splits it into two subgroups, etc. etc.
We keep iterating this process for a number of times specified in the input iterations.
OUTPUTS: no OUTPUTS
iterations number of times the emails are sent before stoppingmyaddress the gmail address from which emails are sentmypassword password for the gmail addressemailaddresses a cell containing the email addresses to which we will send the emailsmessages a cell containing the two messages for each group
To test your function, it is a good idea to write a script which defines the values for the inputs, and then calls the function financeguru. You should send emails using the following address that I created for this purpose:
email: ... PWD: financeguru
Receive emails at your personal account, or create one for this purpose. More suggestions below.
NOTE 1. The price change for the stock is a random draw for the standard normal distribution, for illustration purposes, but it can be modified to collect the closing price of any stock from Yahoo Finance, for example. I am not asking to do this, but think about it for your projects.
NOTE 2. This is a suggestion that will massively help in testing your code and will avoid spamming other people. However, it is a suggestion. Do it as you like, as long as the code does what it is supposed to do. Write the code such that it sends emails one by one with a for loop. Hence, the code will pick an email address from the cell containing all of them, and will send one email at the time. To each email you send, attach a number that uniquely identifies the email (for example call it email_id or client_number). This email identifier can be included in the subject of the email, which should read: 'Dear client n. [email_id], follow this financial advice!'. As an example, if you use the letter i as the counter for the for loop, you can set the email_id to be equal to i, and use concatenation of strings and the command num2str to generate the email subject as suggested. If you code it this way, you can use only one receiving email address (for example, your personal email address) repeated many times in the list of email addresses, since when you will receive them, each email will be numbered and therefore identifiable. In that way, you will be able to check if the code is actually doing what it is supposed to do without the need to check many different email accounts. For this purpose, when calling the function, set emailaddresses to be equal to something like this:
and then you will receive all the emails at your address ..., and each email will have a number identifying it.
How to send emails with Matlab : check the help for the command sendmail at http://uk.mathworks.com/help/matlab/ref/sendmail.html. Notice that you need to set some parameters related to the email account you use for sending emails. I have done this for you in the template solution, so DO NOT MODIFY THAT PART!!! It is well indicated in the template solution.
The syntax for sendmail is the following (check the help for details):
sendmail('...', 'This is the subject of the email', 'This is the main body of the email');
If you have any problems in sending emails using the account I created, try to deactivate your antivirus and your firewall. If this does not work, check your code, and then let me know on Surreylearn ( and post your code!)