Bardo.API (Bardo v0.1.0)

View Source

A simplified API layer for Bardo, providing beginner-friendly functions for common tasks while abstracting away implementation complexity.

This module serves as the main entry point for new users to interact with Bardo without needing to understand the underlying architecture.

Summary

Functions

Create a flatland environment for agent navigation.

Create and configure an agent for algorithmic trading.

Create and setup a simple XOR neural network.

Deploy an agent for live trading.

Get performance metrics for an agent.

Initialize a new Bardo environment with sensible defaults.

Load a pre-trained trading agent from a file.

Run a standalone training session for a trading agent.

Save a trained agent to a file.

Stop a deployed trading agent.

Test the agent on the XOR problem.

Train a flatland agent to navigate and avoid obstacles.

Train an agent on the XOR problem.

Functions

create_flatland(opts \\ [])

Create a flatland environment for agent navigation.

Options

  • :id - the ID for the agent (default: random UUID)
  • :hidden_neurons - number of hidden neurons (default: 5)
  • :world_size - size of the flatland world (default: {10, 10})

Examples

iex> Bardo.API.create_flatland()
{:ok, agent_id}

create_trading_agent(opts \\ [])

Create and configure an agent for algorithmic trading.

Options

  • :id - the ID for the agent (default: random UUID)
  • :instrument - trading instrument (default: "EUR_USD")
  • :timeframe - trading timeframe (default: "M15")
  • :hidden_neurons - number of hidden neurons (default: 10)

Examples

iex> Bardo.API.create_trading_agent(instrument: "BTC_USD")
{:ok, agent_id}

create_xor(opts \\ [])

Create and setup a simple XOR neural network.

Options

  • :id - the ID for the agent (default: random UUID)
  • :hidden_neurons - number of hidden neurons (default: 2)
  • :bias - whether to use bias neurons (default: true)
  • :activation - activation function to use (default: :tanh)

Examples

iex> Bardo.API.create_xor()
{:ok, agent_id}

deploy_trading_agent(agent_id, opts \\ [])

Deploy an agent for live trading.

Options

  • :broker - the broker to use (default: :oanda)
  • :config - broker-specific configuration

Examples

iex> config = %{api_key: "your_api_key", account_id: "your_account_id"}
iex> Bardo.API.deploy_trading_agent(agent_id, broker: :oanda, config: config)
{:ok, deployment_id}

get_agent_metrics(agent_id)

Get performance metrics for an agent.

Examples

iex> Bardo.API.get_agent_metrics(agent_id)
{:ok, %{
  sharpe_ratio: 1.2,
  max_drawdown: 0.15,
  total_return: 0.25,
  win_rate: 0.55
}}

init()

Initialize a new Bardo environment with sensible defaults.

Examples

iex> Bardo.API.init()
:ok

load_trading_agent(file_path)

Load a pre-trained trading agent from a file.

Examples

iex> Bardo.API.load_trading_agent("/path/to/agent.json")
{:ok, agent_id}

run_standalone_training(opts \\ [])

Run a standalone training session for a trading agent.

Options

  • :instrument - trading instrument (default: "EUR_USD")
  • :timeframe - trading timeframe (default: "M15")
  • :start_date - historical data start date (default: one year ago)
  • :end_date - historical data end date (default: current date)
  • :generations - number of generations to train (default: 100)
  • :population_size - size of the population (default: 50)

Examples

iex> Bardo.API.run_standalone_training(instrument: "BTC_USD")
{:ok, %{agent_id: agent_id, fitness: 0.85}}

save_agent(agent_id, file_path)

Save a trained agent to a file.

Examples

iex> Bardo.API.save_agent(agent_id, "/path/to/save/agent.json")
:ok

stop_trading_agent(deployment_id)

Stop a deployed trading agent.

Examples

iex> Bardo.API.stop_trading_agent(deployment_id)
:ok

test_xor(agent_id)

Test the agent on the XOR problem.

Examples

iex> {:ok, agent_id} = Bardo.API.create_xor()
iex> Bardo.API.train_xor(agent_id)
iex> Bardo.API.test_xor(agent_id)
{:ok, %{
  inputs: [[0, 0], [0, 1], [1, 0], [1, 1]],
  outputs: [[0.02], [0.98], [0.97], [0.03]],
  expected: [[0], [1], [1], [0]]
}}

train_flatland(agent_id, opts \\ [])

Train a flatland agent to navigate and avoid obstacles.

Options

  • :generations - number of generations to train (default: 500)
  • :population_size - size of the population (default: 50)
  • :fitness_target - target fitness to reach (default: 800)
  • :simulation_steps - steps per evaluation (default: 100)

Examples

iex> {:ok, agent_id} = Bardo.API.create_flatland()
iex> Bardo.API.train_flatland(agent_id)
{:ok, %{best_fitness: 825, generations: 320}}

train_xor(agent_id, opts \\ [])

Train an agent on the XOR problem.

Options

  • :generations - number of generations to train (default: 100)
  • :population_size - size of the population (default: 20)
  • :fitness_target - target fitness to reach (default: 3.9)

Examples

iex> {:ok, agent_id} = Bardo.API.create_xor()
iex> Bardo.API.train_xor(agent_id)
{:ok, %{best_fitness: 3.95, generations: 42}}