Investment/betting simulation I am creating an investment/betting simulation; since is the first I create , I am sure it can be done better, both from a coding and a simulation point of view.

I would like to ask you what you think and if you can share your experience.

There are 5 main variables that the user has to input:


z --> it is my average winning percentage. As discuss later, a random number between 0 and 100 will be generate. If the generated number (x) is greater than (z), then the trade is loss; if x &lt; z, is a win.
invest --> how much money invested per trade, es. 10$. In case of a win, the return is always the 70%. i.e. bet 10$, win 7$ (plus the bet)
days --> how many days I trade. there is fixed amount of trade per day, which is between 9 and 33
simulazioni --> the number of simulations
varianza --> is the shifting probability. If varianza is 5% and my percentage (z) is 50%, my actual variance could be either 45% or 55%. This is calculated randomly for each trade.


As you can see from the code at the bottom, the simulation is based on "for loops". The main one is the simulations, second one are the days and the last one calculates if the trading is positive or negative.

There are also dictionaries that I use to collect data from daily profit and total profit (i.e. "datatot"; these dictionaries are used to plot data later on (this bit is not included in the code).

import random
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np

data=[]
data2=[]
datatot = []
portafoliotot = 0
portafolio = 0
pos= 0 
neg= 0

#input variables
z= input("Percentuale: ")
invest = input("Investimento:")
days = input ("Giorni:")
simulazioni = input("Simulazioni:")
varianza = input("Varianza:")

for simulazione in range(0,int(simulazioni)):

    for giorno in range(0,int(days)):

        portafoliotot = 0 #simulation portfolio
        portafolio = 0 #daily portfolio
        pos = 0 #n of positive trades
        neg = 0 #n of negative trades


        for trade in range(0,int(random.randint(9,33))):

            x=random.randint(0,100) #random number to see if the trade is pos or neg

            calcvarianza = 2 * np.random.rand() - 1 # calculation of (varianza). if positive, is going to be added to (z), otherwise subtracted. this is done for each trade.

            if calcvarianza &gt; 0:
                varianza = - int(varianza)

            if x&lt;(int(z)+int(varianza)): #checking if the trade is pos or neg

                portafolio += (int(invest)/100)*70
                pos +=1 
            else:
                portafolio += -int(invest)
                neg +=1


        portafoliotot += portafolio
        data.append(portafoliotot)
        data2.append(portafoliotot)

    datatot.append(sum(data2))
    data2 = []
Idiomatic Python suggestions:


Use argparse rather than input to set the configuration. It is easy to use, and very powerful.


General suggestions:


data and data2 are literally considered the world's worst variable names. Naming is well known to be a hard problem, but it's also a great skill to learn. Naming a thing well gives much needed information to anyone reading the script, including yourself.
Comments like "checking if the trade is pos or neg" are code smells which point to an opportunity to extract a class or function.
Your program contains many magic values, like 33. Use constants or set them as defaults for arguments to make it clear what these numbers mean.
Your program neither prints nor returns anything. In other words it can be replaced by the single line pass.
This may sound chauvinist, but use English names for things in your program. The world's developers have avoided localising programming languages for a long time, and in a programming job you are very likely going to be expected to write everything except user interfaces in English. As long as practically every function, class, package and module in the world is named in English, you are going to improve maintainability by using a single language in your programs. Disclaimer: I'm not a native English speaker.