コード例 #1
0
ファイル: train.py プロジェクト: Repsay/BinanceAPI
def get_first_generation(layers) -> list[Trader]:
    global IDX
    base_trader = Trader(IDX, MUTATION_RATE, SYMBOL, layers)
    print(IDX, end='\r')
    traders = [base_trader]


    for i in range(IDX+1, IDX+POPULATION_SIZE):
        print(i, end='\r')
        if base_trader.brain.model_loaded:
            traders.append(base_trader.clone_mutate(i))
        else:
            traders.append(Trader(i, MUTATION_RATE, SYMBOL, layers))


    # for trader in traders:
    #     trader.tempStore()

    IDX += POPULATION_SIZE

    return traders
コード例 #2
0
ファイル: train.py プロジェクト: Repsay/BinanceAPI
    new = False
    allTraders: list[Trader] = []
    if first:
        base_trader = Trader(idx, MUTATION_RATE, SYMBOL, HIDDEN_LAYERS[0])

    for i in range(len(HIDDEN_LAYERS)):
        layer = HIDDEN_LAYERS[i]
        traders: list[Trader] = []
        for j in range(POPULATION_SIZE):
            print(f'Generating trader {idx}')
            if first:
                if idx == 0:
                    traders.append(base_trader)
                else:
                    if base_trader.brain.model_loaded:
                        traders.append(base_trader.clone_mutate(idx))
                    else:
                        traders.append(Trader(idx, MUTATION_RATE, SYMBOL, layer))
            else:
                traders.append(pickOne(previousTraders).clone_mutate(idx))
            
            idx += 1
            

        CLS()
        line = ''
        for trader in allTraders:
            line = f"{line}trader {trader.idx} - fitness: {trader.fitness:.4f}, prob: {trader.prob:.4f}, trades: {trader.tradesCounter}, ptrades: {trader.tradesProfit}, profit: {trader.profit:.4f}, counter: {trader.counter}\n"
        print(line)
        print(f"Start generation {generationCount} - {i+1}/{len(HIDDEN_LAYERS)}")