Example #1
0
def simulate_one(param):
    data_start_date = param['data_start_date']
    simulate_start_date = param['simulate_start_date']
    simulate_end_date = param['simulate_end_date']
    strategy_name = param['strategy_name']
    strategy_ctx = param['strategy_ctx']
    ts_code = param['ts_code']

    result = simulate(
        ts_code,
        stock,
        data_start_date=data_start_date,
        simulate_start_date=simulate_start_date,
        simulate_end_date=simulate_end_date,
        strategy_name=strategy_name,
        strategy_ctx=strategy_ctx,
    )
    account = result['account'].tail(1)
    last_day_data = result['daily_data'].tail(1)
    last_position = result['position'].tail(1)
    account_report = result['account_report']
    account = pd.concat([account, account_report], axis=1)
    account['ts_code'] = ts_code
    last_day_data['ts_code'] = ts_code
    last_position['ts_code'] = ts_code
    account = account.loc[:, ~account.columns.duplicated()]
    return {
        'account': account,
        'daily_data': last_day_data,
        'position': last_position
    }
Example #2
0
def run_aggressive_sim():

    df1 = pd.read_csv('./data/train_2019.csv')
    df1 = df1[df1['ID'] == 1]

    df2 = pd.read_csv('./data/train_2020.csv')
    df2 = df2[df2['ID'] == 1]

    df = pd.concat([df1, df2])

    lats = df['Latitude']
    longs = df['Longitude']
    coords = [(lats.iloc[i], longs.iloc[i]) for i in range(len(longs))]
    n_sim = 10

    aggressive_parameters = {
        'p_survival': 0.6,
        'p_queen_survival': 0.15,
        'new_queens': 30,
        'dispersal_range': 10e3
    }

    for i in range(n_sim):
        logger.info(f'Starting aggressive simulation: {i}')
        results = simulate(
            coords,
            2019,
            5,
            hive_parameters=aggressive_parameters,
            shape_file='./data/states_reduced/states_reduced.shp')

        results.to_csv(f'./data/results/results_aggr_sim_{i}.csv')
Example #3
0
def run_conservative_sim():

    df = pd.read_csv('./data/train_2019.csv')
    df = df[df['ID'] == 1]

    lats = df['Latitude']
    longs = df['Longitude']
    coords = [(lats.iloc[i], longs.iloc[i]) for i in range(len(longs))]
    n_sim = 10

    conservative_parameters = {
        'p_survival': 0.4,
        'p_queen_survival': 0.1,
        'new_queens': 30,
        'dispersal_range': 5e3
    }

    for i in range(n_sim):
        logger.info(f'Starting conservative simulation: {i}')
        results = simulate(
            coords,
            2019,
            5,
            hive_parameters=conservative_parameters,
            shape_file='./data/states_reduced/states_reduced.shp')
        results.to_csv(f'./data/results/results_cons_sim_{i}.csv')
def main(args):

    print("reading in instance")
    project_instance = build_instance(args)

    snapshot_list = []
    if args.compare:
        print("Start simulation of both schedulers")
        snapshots_simple, score_simple, snapshots, score = compare(
            project_instance)
        print("Lower score means better capacity distribution")
        print(f"standard scores {score_simple} > {score} our score ")
        snapshot_list.append(snapshots_simple)
        snapshot_list.append(snapshots)
    else:
        print("Start simulation capacity scheduler")
        snapshots = simulate(project_instance, CapacityScheduler())
        score = squared_deviation_from_optimal_capacity(project_instance)
        snapshot_list.append(snapshots)
        print("Score: ", score)

    if args.visualize:
        print("Start visualizing")
        visualize(project_instance, snapshot_list)

    if args.output:
        print("Writing output")
        write_output(project_instance)
Example #5
0
def run(
    keyword,
    data_start_date: str,
    simulate_start_date: str,
    strategy_conf: dict = {},
    simulate_end_date: str = '',
):
    strategy_name = strategy_conf['name']
    strategy_ctx = strategy_conf['ctx']
    strategy_savename = strategy_conf[
        'savename'] if 'savename' in strategy_conf else strategy_name

    result = simulate(keyword,
                      stock,
                      data_start_date=data_start_date,
                      simulate_start_date=simulate_start_date,
                      strategy_name=strategy_name,
                      strategy_ctx=strategy_ctx,
                      init_amount=1000000,
                      excel_path=join(
                          outpath, 'test_simulate_' + strategy_savename + '_' +
                          keyword + '.xlsx'),
                      with_chart=True)
    result['chart']['k'].render(
        join(outpath, 'test_simulate_' + strategy_savename + '_k.html'))
    result['chart']['account'].render(
        join(outpath, 'test_simulate_' + strategy_savename + '_account.html'))
    def test_sim_no_geo(self):
        """Setup a random simulation"""
        stl_lat = 47.6062
        stl_long = -122.3321
        n_starting_hives = 10
        coords = []
        for i in range(n_starting_hives):
            coords.append(
                (stl_lat + np.random.random(), stl_long + np.random.random()))

        df = simulate(coords, 2020, 10)
        print(df.head())
        print(df.tail())
    def test_sim_geo(self):
        """Setup a random simulation with a geometry file"""
        stl_lat = 47.6062
        stl_long = -122.3321
        n_starting_hives = 10
        coords = []
        for i in range(n_starting_hives):
            coords.append(
                (stl_lat + np.random.random(), stl_long + np.random.random()))

        df = simulate(coords,
                      2020,
                      10,
                      shape_file='../data/states_reduced/states_reduced.shp')

        print(df.head())
        print(df.tail())
Example #8
0
import pickle

from src.system import System
from src.simulate import simulate
from src.animate import animate
from src.plot_spin_current import plot_spin_current
from src.total_transfer_depthresolved import total_transfer_depthresolved

from src.systems.system_a import make_system_a
from src.systems.system_b.system_b import make_system_b
from src.systems.system_c import make_system_c
from src.systems.system_d import make_system_d
from src.systems.system_e import make_system_e

h_target = 0.25  # (nm), 0.25
dt = 0.5  # (fs)
substeps = 100
electrons_per_packet = 0.00002  # (nm^-2), 0.0001 for spin current plots

system: System = make_system_e(h_target, dt, substeps, electrons_per_packet)

state_list = simulate(system, 300.0)

pickle.dump(system,     open("system.p", 'wb'))
pickle.dump(state_list, open("state_list.p", 'wb'))

animate(system, state_list, 10.0, 0.0, 40.0)

#plot_spin_current(system, state_list, 16.0, False)
#total_transfer_depthresolved(system, state_list, 15.0, 30.0, 0.01)