Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use python language!!! There are two investment machines. If you put $X in one machine, there is 60% of chance it will return $2X

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

please use python language!!!

There are two "investment machines". If you put $X in one machine, there is 60% of chance it will return $2"X (and 40% returning $0); if you put $X in the other machine, there is 40% of chance it will return $2"X (and 60% returning $0). You just don't know which machine is which! You have a total of $100 to start with, and you can only invest a maximum of 30 times. The minimum amount to invest is $0 with $1 minimum incremental. Part 1 of this assignment: Use Python to implement the following "vanilla" investment strategy: Put $1 in each investment machine for 10 times to see which one returns more money (thus, you have invested a total of 20 times). Break tie whatever way you prefer. 1. 2. For the remaining money, always invest half (of the current remaining total money) in the more profitable machine discovered each time, for the last 10 times of investment. Simulate this strategy for 1000 times. Print out the average amount of return, the standard deviation, and the Sharpe Ratio you end up with using this strategy. The standard deviation measures how "spread out" a set of numbers is. (see sample code below to learn how to calculate "std" with the python numpy module). The Sharpe Ratio is a way to evaluate the performance of an investment by adjusting for its risk. The ultimate goal of the investment is to maximize the Sharpe Ratio, defined as follows: (average gain) / (standard deviation + 1), where average gain-average return - risk free amount (in this case: the risk free amount $100). That is, we seek for a higher return, with relatively low volatility. To avoid the rare situation where the standard deviation is 0, we add 1 in the demometer. Useful background info: In artificial intelligence (Al), the first step in the "vanilla" approach above is often called "exploration" which uses trial-and-error to see which option is best. The second step is often called "exploitation" which exploits the newly learned best option to make a maximum "profit". Exploration and exploitation can be interleaved and integrated in sophisticated and intelligent ways to achieve an optimal outcome In real-world, things are often much more complicated. For example, there are usually more investments to choose from, each with an unknown distribution of returns which may vary over time, and so on. This type of problems in this assignment do have widespread important applications. The "investments" can be the restaurants you are exploring and enjoying in a new city, different subjects you try to choose in universities, or different jobs/career you want to work for in your life. The assignment may also be helpful to improve your rational decision-making under uncertainty The Python code for the two investment machines will be provided to you as an independent python file called investment_machine.py in which a python class 'InvestmentMachine' was defined with a function called 'invest". Do not modify investment_machine.py, just put it with your own python file in the same directory The following sample Python program invests $3 in each machine for 15 times, and print out the final total. It may help you start with your assignment. Save the following codes in any_name.py, in the same directory as investment_machine.py. Load and run any_name.py in PyCharm. You would get a total return value of around $100. (Here Sharpe Ratio is not calculated, but it would be around 0) #import Investment Machine class from investment_machine import InvestmentMachine #initialize investment machine instance my_investment machines InvestmentMachine) total_reward_machine 10 total_reward machine 2 0 #invest to machine 1 with $3 for 15 times for times_machine 1 in range(15): # v1 += v2 is shorthand for v1 = v1 + v2 total reward-machine-1 +.my-investment, machines.invest(13) # The first argument is for machine 1 or machine 2, randomly assigned to have 40% and 60% return # The second argument is for the amount of money put in. #invest to machine 2 with $3 for 15 times for times_machine 2 in range(15): total reward machine-2+=my-investment-machinesinvest(23) print( The total return of my investment strategy is S", total_reward_machine_1 +total_reward_machine_2) For the 1000 simulations, you need to save the total amount of money in a list of size 1000, then computer the average amount of money, the standard deviation, and the Sharpe Ratio. To simplify your coding, you can use the existing function "std" to calculate the standard deviation. See below. # #############sample standard deviation calculation#### #import numpy module import numpy as np #generate a list of 10 random numbers value_list np.random.rand(10) print("values in the list are ", value_list) sdnp.std(value_list) print("Standard deviation is ", sd) ## ## ## You must define and use the following functions in your final submission: Define and use the main function Define and use a function for repeated investment of a fixed amount in one machine. The function should take three arguments: the machine number, the money you invest each time, and total times you invest with the fixed amount. You will see the benefit of defining such a function, which is an abstraction for repeated calculations. Define and use a function for repeated investment of a fixed percentage of the current total money you have in one machine. The function should take three arguments: the machine number, the percentage you invest each time, and total times you invest with the fixed percentage. You can define any other functions if needed. a. b. c. d. There are two "investment machines". If you put $X in one machine, there is 60% of chance it will return $2"X (and 40% returning $0); if you put $X in the other machine, there is 40% of chance it will return $2"X (and 60% returning $0). You just don't know which machine is which! You have a total of $100 to start with, and you can only invest a maximum of 30 times. The minimum amount to invest is $0 with $1 minimum incremental. Part 1 of this assignment: Use Python to implement the following "vanilla" investment strategy: Put $1 in each investment machine for 10 times to see which one returns more money (thus, you have invested a total of 20 times). Break tie whatever way you prefer. 1. 2. For the remaining money, always invest half (of the current remaining total money) in the more profitable machine discovered each time, for the last 10 times of investment. Simulate this strategy for 1000 times. Print out the average amount of return, the standard deviation, and the Sharpe Ratio you end up with using this strategy. The standard deviation measures how "spread out" a set of numbers is. (see sample code below to learn how to calculate "std" with the python numpy module). The Sharpe Ratio is a way to evaluate the performance of an investment by adjusting for its risk. The ultimate goal of the investment is to maximize the Sharpe Ratio, defined as follows: (average gain) / (standard deviation + 1), where average gain-average return - risk free amount (in this case: the risk free amount $100). That is, we seek for a higher return, with relatively low volatility. To avoid the rare situation where the standard deviation is 0, we add 1 in the demometer. Useful background info: In artificial intelligence (Al), the first step in the "vanilla" approach above is often called "exploration" which uses trial-and-error to see which option is best. The second step is often called "exploitation" which exploits the newly learned best option to make a maximum "profit". Exploration and exploitation can be interleaved and integrated in sophisticated and intelligent ways to achieve an optimal outcome In real-world, things are often much more complicated. For example, there are usually more investments to choose from, each with an unknown distribution of returns which may vary over time, and so on. This type of problems in this assignment do have widespread important applications. The "investments" can be the restaurants you are exploring and enjoying in a new city, different subjects you try to choose in universities, or different jobs/career you want to work for in your life. The assignment may also be helpful to improve your rational decision-making under uncertainty The Python code for the two investment machines will be provided to you as an independent python file called investment_machine.py in which a python class 'InvestmentMachine' was defined with a function called 'invest". Do not modify investment_machine.py, just put it with your own python file in the same directory The following sample Python program invests $3 in each machine for 15 times, and print out the final total. It may help you start with your assignment. Save the following codes in any_name.py, in the same directory as investment_machine.py. Load and run any_name.py in PyCharm. You would get a total return value of around $100. (Here Sharpe Ratio is not calculated, but it would be around 0) #import Investment Machine class from investment_machine import InvestmentMachine #initialize investment machine instance my_investment machines InvestmentMachine) total_reward_machine 10 total_reward machine 2 0 #invest to machine 1 with $3 for 15 times for times_machine 1 in range(15): # v1 += v2 is shorthand for v1 = v1 + v2 total reward-machine-1 +.my-investment, machines.invest(13) # The first argument is for machine 1 or machine 2, randomly assigned to have 40% and 60% return # The second argument is for the amount of money put in. #invest to machine 2 with $3 for 15 times for times_machine 2 in range(15): total reward machine-2+=my-investment-machinesinvest(23) print( The total return of my investment strategy is S", total_reward_machine_1 +total_reward_machine_2) For the 1000 simulations, you need to save the total amount of money in a list of size 1000, then computer the average amount of money, the standard deviation, and the Sharpe Ratio. To simplify your coding, you can use the existing function "std" to calculate the standard deviation. See below. # #############sample standard deviation calculation#### #import numpy module import numpy as np #generate a list of 10 random numbers value_list np.random.rand(10) print("values in the list are ", value_list) sdnp.std(value_list) print("Standard deviation is ", sd) ## ## ## You must define and use the following functions in your final submission: Define and use the main function Define and use a function for repeated investment of a fixed amount in one machine. The function should take three arguments: the machine number, the money you invest each time, and total times you invest with the fixed amount. You will see the benefit of defining such a function, which is an abstraction for repeated calculations. Define and use a function for repeated investment of a fixed percentage of the current total money you have in one machine. The function should take three arguments: the machine number, the percentage you invest each time, and total times you invest with the fixed percentage. You can define any other functions if needed. a. b. c. d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions