策略失效时,坚守还是放弃

投资者经常会碰到其使用的策略和当前市场实际有效的策略不吻合的问题,该放弃还是坚守?

今天忽然想到一个可以类比的问题:两人走散时,一个试图寻找,另一个应该呆在原地等还是互相寻找?似乎可以理解为市场本身总在寻找新的有效策略,投资者要不要一起找。问了下deepseek,答说理论上是互相寻找更好,实际用deepseek生成的代码验证后也是如此,在10*10的网格中两种策略重复1000次的结果如下:
A不动的话平均所需: 238.64 步
A移动的话平均所需: 182.22 步

话虽如此,强逻辑策略投资者自然不肯放弃,比如价值投资者,但似乎这就是大奖章能傲视群雄的基本策略:不断放弃旧的并寻找新的弱逻辑策略

PS:代码如下
import numpy as np
import random
import matplotlib.pyplot as plt

class GridWorld:
def __init__(self, size=10):
    self.size = size  # n x n grid
    self.positions = {}  # tracks positions of A and B

def initialize_positions(self):
    # Randomly place A and B in the grid
    self.positions['A'] = (random.randint(0, self.size-1), random.randint(0, self.size-1))
    self.positions['B'] = (random.randint(0, self.size-1), random.randint(0, self.size-1))
    # Ensure A and B start at different positions
    while self.positions['A'] == self.positions['B']:
        self.positions['B'] = (random.randint(0, self.size-1), random.randint(0, self.size-1))

def move_random(self, agent):
    x, y = self.positions[agent]
    possible_moves = []
    # Possible moves: up, down, left, right (no diagonal)
    if x > 0:
        possible_moves.append((x-1, y))  # up
    if x < self.size - 1:
        possible_moves.append((x+1, y))  # down
    if y > 0:
        possible_moves.append((x, y-1))  # left
    if y < self.size - 1:
        possible_moves.append((x, y+1))  # right
    # Randomly choose a move
    if possible_moves:
        self.positions[agent] = random.choice(possible_moves)

def simulate_strategy_stay(self, max_steps=1000):
    """Simulate Strategy S: A stays, B moves randomly."""
    self.initialize_positions()
    a_pos = self.positions['A']
    steps = 0
    while steps < max_steps:
        if self.positions['B'] == a_pos:
            return steps  # A and B meet
        self.move_random('B')
        steps += 1
    return max_steps  # did not meet within max_steps

def simulate_strategy_move(self, max_steps=1000):
    """Simulate Strategy M: A and B both move randomly (synchronously)."""
    self.initialize_positions()
    steps = 0
    while steps < max_steps:
        # Store old positions to check if they cross paths
        old_a_pos = self.positions['A']
        old_b_pos = self.positions['B']

        # Move A and B
        self.move_random('A')
        self.move_random('B')

        # Check if they meet after moving
        if self.positions['A'] == self.positions['B']:
            return steps + 1  # +1 since they move simultaneously

        # Optional: Check if they swapped positions (crossed paths)
        if (self.positions['A'] == old_b_pos) and (self.positions['B'] == old_a_pos):
            return steps + 1  # they crossed paths and met

        steps += 1
    return max_steps  # did not meet within max_steps

def run_simulation(grid_size=10, num_trials=1000, max_steps=1000):
"""Run simulations for both strategies and compare."""
grid = GridWorld(size=grid_size)
stay_times = []
move_times = []

for _ in range(num_trials):
    stay_times.append(grid.simulate_strategy_stay(max_steps))
    move_times.append(grid.simulate_strategy_move(max_steps))

# Compute statistics
avg_stay = np.mean(stay_times)
avg_move = np.mean(move_times)

print(f"Average meeting time (A stays): {avg_stay:.2f} steps")
print(f"Average meeting time (A moves): {avg_move:.2f} steps")

# Plot results
plt.figure(figsize=(10, 6))
plt.hist(stay_times, bins=50, alpha=0.5, label='A stays, B moves')
plt.hist(move_times, bins=50, alpha=0.5, label='A and B both move')
plt.xlabel('Meeting Time (steps)')
plt.ylabel('Frequency')
plt.title('Comparison of Meeting Times for Two Strategies')
plt.legend()
plt.show()

Run the simulation

run_simulation(grid_size=10, num_trials=1000)
发表时间 2025-06-29 12:47     最后修改时间 2025-06-29 13:02     来自上海

赞同来自: 万里无云11 研究一下可转债 genamax 流沙少帅

1

zengqlleo

赞同来自: qianfa

这是有限空间,无限空间就不是这样了。原地不动找到的概率大
2025-06-30 15:30 来自北京 引用

要回复问题请先登录注册

发起人

bigbear2046
bigbear2046

无非想要明白些道理,遇见些有趣的人或事

问题状态

  • 最新活动: 2025-07-01 18:20
  • 浏览: 3403
  • 关注: 33