System trading validates strategies based on historical stock price data.
For example, the following verification results are the verification results of a certain order.
However, it is only an evaluation in one scenario.
Therefore, I used Python to evaluate the results of multiple simulations of the winning rate, profit rate, profit / loss rate, and amount of funds of the completed strategy.
#Introducing the library
import pandas as pd
import matplotlib.pyplot as plt
import random
#Function for evaluation
#asset initial capital
#What percentage of bet capital to invest
#probability Win rate
#win average profit margin
#loss average loss rate
#transaction number of transactions
def sim(asset, bet, probability, win, loss, transaction):
result = []
for i in range(transaction):
#Win if the random number is less than the winning percentage
if random.random() < probability:
#Assets increase by the average profit margin multiplied by the invested assets.
#This time it is compound interest, but if you change this area, you can make it simple interest.
asset = asset + (asset * bet * win)
#If you lose, the average loss rate multiplied by the invested assets will decrease.
else:
asset = asset - (asset * bet * loss)
#Store transaction results in a list.
result.append(asset)
return result
#Function for evaluation 2
def mon(asset, bet, probability, win, loss, transaction=100, test=1):
df = pd.DataFrame()
#Call the evaluation function for the number of trials and store it in the data frame.
for i in range(test):
df[i] = sim(asset, bet, probability, win, loss, transaction)
#graph display
#Settings for auxiliary lines
xmin = -3
xmax = transaction
#Bluff size setting
plt.figure(figsize=(25, 15), dpi=50)
plt.plot(df)
#Auxiliary line setting
plt.hlines([asset], xmin, xmax, "blue")
plt.show()
#Display of statistical elements
print(df.iloc[transaction - 1].describe())
#Amount of funds 300, risk 20%, Win rate 61.54% average profit margin 5.83% average loss rate 4.63% Let's verify with 250 trades and 300 trials.
mon(300, 0.2, 0.6154, 0.0583, 0.0463, 250, 300)
If you look at this, you can see that there are cases where profits do not rise up to about 50 transactions.
In another strategy,
was.
This is more stable and the assets will increase.
This time, we are extracting values such as winning percentage and average profit margin from the completed strategy, so I don't know if it is statistically valid.
What do you think, guys?
Recommended Posts