Project 1: Martingale (Report)
Instructions for Project 1: Martingale
Revision History
This assignment is subject to change up until 3 weeks before the due date. We do not anticipate changes; any changes will be logged in this section.
1. Published - Start of Term
2. [082524] - Added recommendation to set a starting seed.
3. [082624] - Added clarification that .txt and .html files are optional
4. [082724] - Revised "all work should be your own" to "all work must be your own" to align that statement with course and Institute policy.
1. Overview
In this course, you are building a simplified AI-based trading system. This system is constructed over the course of 8 projects, where each project you complete is a step towards building an intricate system that synthesizes your knowledge of machine learning with practical algorithmic trading strategies. For detailed context and an overview of how each piece fits into the broader system, please refer to the
Machine Learning for Trading Project page
(gatech.instructure.com/courses/411…) .
In this project, you will write software that will perform probabilistic experiments involving an American Roulette wheel .(en.wikipedia.org/wiki/Roulet…) . The project will help provide you with some initial feel for risk, probability, and “betting.” Purchasing a stock is, after all, a bet that the stock will increase (or, in some cases, decrease) in value. You will submit the code for the project to Gradescope SUBMISSION. You will also submit to Canvas a report that discusses your experimental findings.
1.1 Learning Objectives
The specific learning objectives for this assignment are focused on the following areas:
· Mathematical Tools: Developing an understanding of common probabilistic and statistical tools associated with machine learning, including expectations, standard deviations, sampling, minimum values, maximum values, and convergence.
· Research: Experience researching additional material (conceptual and programming) to ensure the successful completion of the assignment.
· Programming Academic Writing: Each assignment will build upon one another. The techniques around experimentation, graphs, interpretation (and so on) will play important roles in this and future projects.
· Course Conduct: Developing and testing code locally in the local Conda ml4t environment,
submitting it for pre-validation in the Gradescope TESTING environment, and submitting it for grading in the Gradescope SUBMISSION environment.
2. About the Project
In this project, you will build a Simple Gambling Simulator. Specifically, you will revise the code in the martingale.py file to simulate 1000 successive bets on the outcomes (i.e., spins) of the American roulette wheel using the betting scheme outlined in the pseudo-code below. Each series of 1000 successive bets is called an “episode.” You should test for the results of the betting events by making successive calls to the get_spin_result(win_prob) function. Note that you will have to update the win_prob parameter according to the correct probability of winning. You can figure that out by thinking about how roulette works (see Wikipedia link below).
In this project, you will evaluate Professor Balch’s actual betting strategy at roulette when he goes to Las Vegas.
Here is the pseudocode of the strategy:
episode_winnings = 0<br>whileepisodewinnings<80:
won = False
bet_amount = 1<br>whilenotwon<br>wagerbetamountonblack<br>won=resultofroulettewheelspin<br>ifwon==True:<br>episodewinnings=episodewinnings+betamount<br>else:<br>episodewinnings=episodewinnings−betamount<br>betamount=betamount∗2<br>Additionaldetailsregardinghowroulettebettingworks:Bettingonblack(orred)isconsideredan“evenmoney”bet.ThatmeansthatifyoubetNchipsandwin,youkeepyourNchips,andyouwinanotherNchips.IfyoubetNchipsandyoulose,thenthoseNchipsarelost.TheoddsofwinningorlosingdependonbettingatanAmericanwheeloraEuropeanwheel.Forthisproject,wewillbeassuminganAmericanwheel.Youcanlearnmoreaboutrouletteandbettinghere:https://en.wikipedia.org/wiki/Roulette.<br>3.YourImplementation<br>Youwilldevelopanimplementationleveragingthepseudocodeabovethatconductsseveralexperiments.Conductthefollowingexperiments,thenwriteyourreport.Beforethedeadline,makesuretopre−validateyoursubmissionusingGradescopeTESTING.OnceyouaresatisfiedwiththeresultslocallyandinGradescopeTESTING,submitthecodetoGradescopeSUBMISSION.OnlycodesubmittedtoGradescopeSUBMISSIONwillbegraded.IfyousubmityourcodetoGradescopeTESTINGandhavenotalsosubmittedyourcodetoGradescopeSUBMISSION,youwillreceiveazero(0).<br>3.1GettingStarted<br>Youwillbegivenastarterframeworktomakeiteasiertogetstartedontheprojectandfocusontheconceptsinvolved.ThisframeworkassumesyouhavealreadysetuptheML4TDevelopment<br>Environment(https://gatech.instructure.com/courses/411838/pages/ml4t−development−environment−setup).TheframeworkforProject1canbeobtainedfromtheMartingale2024Fall.zip<br>(https://gatech.instructure.com/courses/411838/files/53096803?wrap=1)<br>(https://gatech.instructure.com/courses/411838/files/53096803/download?downloadfrd=1)fileonCanvasorDropbox(https://www.dropbox.com/scl/fi/2qisdfrikezwsm7yaws6w/martingale2024Fall.zip?<br>rlkey=xl4zcpde5o2bkqmpz60e1qyc8st=g31fzvvbdl=1).Extractitscontentsintothebasedirectory(e.g.,ML4T2023Fall,although“ML4T2021Summer”isshownintheimagebelow).Thiswilladdanew”martingale”foldertothedirectorystructure.<br>Withinthemartingalefolderisasinglefile:martingale.py<br>Youwillmodifythemartingale.pyfile代写Project1:MartingalePythontoimplementthenecessaryfunctionalityforthisassignment.Theexistingcodeinthemartingale.pyfilemaycontainideasforfunctionsandmethodsthatcouldbeusedinyourimplementations.Thisfilemustremainandrunfromwithinthemartingaledirectoryusingthefollowingcommand:<br>PYTHONPATH=../:.pythonmartingale.py<br>3.2Experiment1–Explorethestrategyandcreatesomecharts<br>Inthisexperiment,youwilldevelopcodethatperformsexperimentsusingProfessorBalch’soriginalbettingstrategy.Youwillrunsomeexperimentstodeterminehowwellthebettingstrategyworks.TheapproachwearegoingtotakeiscalledMonteCarlosimulation.Theideaistorunasimulatorrepeatedlywithrandomizedinputsandassesstheresultsinaggregate.Yourimplementationwillproducethefollowingcharts(i.e.,figures):<br>⋅Figure1:Runyoursimplesimulator10episodesandtrackthewinnings,startingfrom0eachtime.Plotall10episodesononechartusingMatplotlibfunctions.Thehorizontal(X)axismustrangefrom0to300,thevertical(Y)axismustrangefrom–256to+100.Wewillnotbesurprisedifsomeoftheplotlinesarenotvisiblebecausetheyexceedtheverticalorhorizontalscales.<br>⋅Figure2:Runyoursimplesimulator1000episodes.(Rememberthat1000successivebetsareoneepisode.)PlotthemeanvalueofwinningsforeachspinroundusingthesameaxisboundsasFigure1.Forexample,youshouldtakethemeanofthefirstspinofall1000episodes.Addanadditionallineaboveandbelowthemean,atmeanplusstandarddeviation,andmeanminusstandarddeviationofthewinningsateachpoint.<br>⋅Figure3:UsethesamedatayouusedforFigure2butplotthemedianinsteadofthemean.Addanadditionallineaboveandbelowthemediantorepresentthemedianplusstandarddeviationandmedianminusstandarddeviationofthewinningsateachpoint.<br>Foralltheabovefiguresandexperiments,ifthetargetof80 winnings is reached, stop betting, and allow the 80value(orwhatevervaluegreaterthan80 you have obtained) to persist from spin to spin (e.g., fill the data forward with a value of 80orthevaluegreaterthan80 you have obtained).
The charts created by the experiments must be included in your report, along with your supporting analysis and discussion. All charts must be properly titled, have appropriate axis labels, use consistent axis ranges, and have legends.
3.3 Experiment 2 – A more realistic gambling simulator
You may have noticed that the original strategy performed in experiment 1 works well, maybe better than you expected. One reason for this is that we were allowing the gambler to use an unlimited bankroll. In this experiment, we retain the upper limit of 80inwinningretainedbutmakethingsmorerealisticbygivingthegamblera256 bankroll. This will require a modification to the original strategy since if he or she runs out of money: bzzt, that’s it. Repeat the experiments, as above, with this new condition. Note that once the player has lost all their money (i.e., episode_winnings reach -256), stop betting and fill that number (-256) forward. An important corner case to handle is the situation where the next bet should be N,butyouonlyhaveM (where M
· Figure 4: Run your realistic simulator 1000 episodes and track the winnings, starting from 0 each
time. Plot the mean value of winnings for each spin using the same axis bounds as Figure 1.Add an additional line above and below the mean at mean plus standard deviation and mean minus standard deviation of the winnings at each point.
· Figure 5: Use the same data you used for Figure 4 but plot the median instead of the mean. Add an additional line above and below the median to represent the median plus standard deviation and median minus standard deviation of the winnings at each point.
The charts created by the experiments will be included in your report, along with your supporting analysis and discussion. All charts must be properly titled, have appropriate axis labels, use consistent axis ranges, and have legends. You should use Python’s Matplotlib library.
3.4 Technical Requirements
The following technical requirements apply to this assignment:
1. The martingale.py file must implement this API specification
(gatech.instructure.com/courses/411…) .
2. All winnings must be tracked by storing them in a NumPy array. You might call that array winnings
where winnings[0] should be set to 0 (just before the first spin). The entry in winnings[1] should reflect the total winnings after the first spin and so on.
3. Use the population standard deviation. The standard deviation is plotted as two lines, the upper standard deviation (e.g., mean +stdev) and the lower standard deviation (e.g., mean –stdev).
4. You may set a specific random seed for this assignment. If a specific random seedisused, it can
only be called once, and it must use your GT ID as the numeric value. To promote the reproducibility of results on different machines, we strongly recommend setting a starting seed,
5. The implementation may optionally write text, statistics, and/or tables to a single file named
p1_results.txt or p1_results.html. These files can be created by each student so that they do not need to write output to the terminal (or screen). The use of such files is entirely optional (i.e., left to each student). If used, this file (or both files) should be created in the same folder as the .py file being run.
6. You must implement the author() and study_group() APIs.
WX:codehelp